【Jenkins&Docker构建部署系列】是我在实践中走过的一条路,踩过一些坑,在这里记下,以防以后再犯哈哈哈哈
【Jenkins&Docker部署系列】四、Vue的构建和部署(Nginx)
1.新建选择【构建一个自由风格的软件项目】
2.构建-执行shell命令
1 2
| npm install npm run build
|
3.构建-执行shell命令
1 2
| cd /home/test-ui BUILD_ID=dontKillMe sh backup.sh
|
4.构建-执行shell命令
1 2 3 4 5 6
| cd /home/jiap-ui \ && cp -r /var/lib/jenkins/workspace/test-ui/dist/ . \ && docker stop vuenginxapp || true \ && docker rm vuenginxapp || true \ && docker build -t vuenginxapp . \ && docker run -d -p 8091:80 --name vuenginxapp -v /home/jiap-ui/dist:/usr/share/nginx/html -v /home/test-ui/nginx.conf:/etc/nginx/nginx.conf vuenginxapp
|
这里贴一下backup.sh的内容
1 2 3 4 5 6 7
| # 备份 BASE_PATH=/home/test-ui new_backup_file=dist-$(date +%Y%m%d-%H%M%S) cd $BASE_PATH/backup mkdir -p $new_backup_file && cd $_ cp -r $BASE_PATH/dist/ . rm -r $BASE_PATH/dist/
|
还有Dockerfile内容
1 2
| FROM nginx:1.8.1 EXPOSE 80
|
最后是nginx.conf的内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| user nginx; worker_processes 1;
error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid;
events { worker_connections 1024; }
http { include /etc/nginx/mime.types; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on; #tcp_nopush on;
keepalive_timeout 65;
gzip on; gzip_types text/plain application/javascript text/css;
# 虚拟主机server块 server { # 端口 listen 80; # 匹配请求中的host值 server_name localhost;
# 监听请求路径 location / { root /usr/share/nginx/html; index index.html index.htm; }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
}
include /etc/nginx/conf.d/*.conf; }
|
此为博主副博客,留言请去主博客,转载请注明出处:https://www.baby7blog.com/myBlog/92.html