docker、git、node.js安装略过。
使git pull或者git push不需要输入密码操作方法
nginx安装在docker容器里面,参见
:https://blog.csdn.net/HSJ0170/article/details/128631155
姊妹篇(宿主机nginx,非docker-nginx):shell脚本发布nginx vue2 项目示例
pro_build.sh
注意:#!/bin/bash -ilex
,如果jenkins远程ssh登录执行sh脚本,并且jekins安装在docker容器里面
,这句代码很有必要。
#!/bin/bash
who am i
set -e
#当前vue2demo目录
cd /opt/vue2demoecho "拉取gitlib最新代码..."
git status && git pull#if判断其实是多余的,set -e 当$? 不等于0时候已经退出了
if [[ $? -ne 0 ]]
thenecho "拉取gitlib最新代码失败,准备退出"exit 1
fi
echo "拉取gitlib最新代码成功"rm -rf dist/
rm -rf /opt/nginx_volume_data/html/vue2demo/dist/
echo "删除旧的dist打包目录、vue2demo/dist/目录"echo "npm install --> 准备安装依赖..."
npm installecho "npm run build --> 准备构建打包..."
npm run buildecho "准备发布到docker-nginx html 目录..."
mv dist/ /opt/nginx_volume_data/html/vue2demo/echo "发布完毕"
nginx配置文件vue2demo.conf:
路径:/opt/nginx_volume_data/conf/conf.d
server {listen 8888;server_name 192.168.1.105;charset utf-8; #proxy_intercept_errors on;#uilocation / {root /usr/share/nginx/html/vue2demo/dist;index index.html index.htm;} #serve #服务springboot见文章:https://blog.csdn.net/HSJ0170/article/details/137103193location ^~/api {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Real-Port $remote_port;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_buffering off;rewrite ^/api/(.*)$ /$1 break;proxy_pass http://192.168.1.105:55530;#启用支持websocket连接proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}
启动:
#先删除docker-nginx容器
docker rm -f docker-nginx
#重新启动80,8888端口
docker run -p 80:80 -p 8888:8888 --name docker-nginx \
-v /opt/nginx_volume_data/html:/usr/share/nginx/html \
-v /opt/nginx_volume_data/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx_volume_data/conf/conf.d:/etc/nginx/conf.d \
-e TZ=Asia/Shanghai \
-d nginx