diff --git a/Dockerfile b/Dockerfile index 7cd6f63..73f37ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,7 @@ -# 构建阶段 -FROM node:18-alpine as builder - -WORKDIR /app - -# 复制项目文件 -COPY package*.json ./ - -# 安装依赖 -RUN npm install - -# 复制源代码 -COPY . . - -# 构建项目 -RUN npm run build - -# 生产阶段 FROM nginx:1.25.3-alpine # 从构建阶段复制构建结果到nginx目录 -COPY --from=builder /app/dist /usr/share/nginx/html +ADD go_fish_web.tar.gz /usr/share/nginx/html # 复制nginx配置 COPY ./nginx.conf /etc/nginx/conf.d/default.conf diff --git a/Jenkinsfile b/Jenkinsfile index 62b5b85..732546b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,16 +1,15 @@ pipeline { agent any - // environment { - // NODEJS_HOME = '/usr/local/nodejs' // Adjust this path to your Node.js installation - // PATH = "${NODEJS_HOME}/bin:${env.PATH}" - // } - stages { stage('📄文件信息') { steps { sh 'pwd' sh 'ls -al' + echo '🚀开始推送文件到坤爷服务器' + sh 'scp Dockerfile root@47.109.22.188:~/go_fish_web' + sh 'scp nginx.conf root@47.109.22.188:~/go_fish_web' + echo '✨推送完成' } } @@ -30,15 +29,28 @@ pipeline { steps { dir('dist') { sh 'ls -al' - sh 'tar -zcvf gofishingweb.tar.gz *' - archiveArtifacts artifacts: 'gofishingweb.tar.gz', + sh 'tar -zcvf go_fish_web.tar.gz *' + archiveArtifacts artifacts: 'go_fish_web.tar.gz', allowEmptyArchive: true, fingerprint: true, onlyIfSuccessful: true sh 'ls -al' + echo '🚀开始推送制品到坤爷服务器' + sh 'scp go_fish_web.tar.gz root@47.109.22.188:~/go_fish_web' + echo '✨推送完成' } } } + + stage('🏓远程部署') { + steps { + echo '🚀开始远程部署' + sh 'ssh root@47.109.22.188 "docker stop go_fish_web && docker rmi go_fish_web && docker build -t go_fish_web ~/go_fish_web"' + sh 'ssh root@47.109.22.188 "docker run --restart=always --name go_fish_web -d -p 30030:80 -v /etc/localtime:/etc/localtime:ro go_fish_web"' + sh 'ssh root@47.109.22.188 "docker ps -a"' + echo '✨远程部署完成' + } + } } post {