test remote deployment

main
Kimsongwu 1 year ago
parent 33ef193ff9
commit ea22a3c493

@ -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 FROM nginx:1.25.3-alpine
# 从构建阶段复制构建结果到nginx目录 # 从构建阶段复制构建结果到nginx目录
COPY --from=builder /app/dist /usr/share/nginx/html ADD go_fish_web.tar.gz /usr/share/nginx/html
# 复制nginx配置 # 复制nginx配置
COPY ./nginx.conf /etc/nginx/conf.d/default.conf COPY ./nginx.conf /etc/nginx/conf.d/default.conf

26
Jenkinsfile vendored

@ -1,16 +1,15 @@
pipeline { pipeline {
agent any agent any
// environment {
// NODEJS_HOME = '/usr/local/nodejs' // Adjust this path to your Node.js installation
// PATH = "${NODEJS_HOME}/bin:${env.PATH}"
// }
stages { stages {
stage('📄文件信息') { stage('📄文件信息') {
steps { steps {
sh 'pwd' sh 'pwd'
sh 'ls -al' 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 { steps {
dir('dist') { dir('dist') {
sh 'ls -al' sh 'ls -al'
sh 'tar -zcvf gofishingweb.tar.gz *' sh 'tar -zcvf go_fish_web.tar.gz *'
archiveArtifacts artifacts: 'gofishingweb.tar.gz', archiveArtifacts artifacts: 'go_fish_web.tar.gz',
allowEmptyArchive: true, allowEmptyArchive: true,
fingerprint: true, fingerprint: true,
onlyIfSuccessful: true onlyIfSuccessful: true
sh 'ls -al' 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 { post {

Loading…
Cancel
Save