From 6b78d9b24337d1533070531faaaaf038b9af383d Mon Sep 17 00:00:00 2001 From: cat_shark <1716967236@qq.com> Date: Sun, 27 Jul 2025 08:57:45 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E9=85=8D=E7=BD=AE=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dcokerfile | 3 +++ Jenkinsfile | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Dcokerfile create mode 100644 Jenkinsfile diff --git a/Dcokerfile b/Dcokerfile new file mode 100644 index 0000000..0f0dcf4 --- /dev/null +++ b/Dcokerfile @@ -0,0 +1,3 @@ +FROM nginx:alpine +COPY dist/ /usr/share/nginx/html/ +EXPOSE 80 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..2325faf --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,61 @@ +pipeline { + agent none // 全局不指定,局部单独声明 + environment { + IMAGE_NAME = 'lpt-fe:0.0' + CONTAINER_NAME = 'LPT_FE' + HOST_PORT = '8080' + CONTAINER_PORT = '80' + } + stages { + stage('Install Dependencies') { + agent { + docker { + image 'node:20-alpine' + args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' + } + } + steps { + sh ''' + npm config set cache /.npm + npm install + ''' + } + } + + stage('Type Check & Build') { + agent { + docker { + image 'node:20-alpine' + args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' + } + } + steps { + sh ''' + npm run type-check + npm run build + ''' + } + } + + stage('Build Docker Image') { + agent any // Jenkins默认节点,有Docker命令 + steps { + sh ''' + docker build -t $IMAGE_NAME . + ''' + } + } + + stage('Run Docker Container') { + agent any + steps { + sh ''' + docker rm -f $CONTAINER_NAME || true + docker run -d --name $CONTAINER_NAME \\ + -p $HOST_PORT:$CONTAINER_PORT \\ + $IMAGE_NAME + ''' + } + } + } +}