Dockerfile 構建前端nginx應用並用shell指令碼實現jenkins自動構建
阿新 • • 發佈:2019-01-14
Dockerfile 檔案構建docker映象
FROM centos MAINTAINER zh********h.cn RUN rm -f /etc/nginx/nginx.conf COPY nginx.conf /etc/nginx/nginx.conf WORKDIR / RUN mkdir data ADD nginx.repo /etc/yum.repos.d RUN yum install nginx -y RUN echo "daemon off;" >> /etc/nginx/nginx.conf RUN rm -rf /etc/nginx/conf.d/default.conf ADD pre.weifeng.conf /etc/nginx/conf.d/ COPY build /data/build RUN useradd -s /sbin/nologin -M www EXPOSE 443 EXPOSE 80 CMD ["nginx"]
nginx 配置檔案 cat pre.weifeng.conf server { listen 443; server_name localhost; location / { try_files $uri /index.html; root /data/build; index index.html index.htm; } error_page 404 /404.html; error_page 404 = https://pre.weifeng.cn/index.html; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { access_log off; expires 10d; root /data/build; } location ~ \.(js|css) { access_log off; expires 10d; root /data/build; } } server { listen 80; server_name pre.weifeng.cn; return 301 https://pre.weifeng.cn$request_uri; }
shell 指令碼實現jenkins上自動構建阿里雲k8s上應用 #!/bin/bash source /etc/profile cd /mnt/workspace/official-ui-pre/ npm i && npm run build rm -rf /mnt/workspace/official-ui-pre/dockerfile/build cd /mnt/workspace/official-ui-pre/dockerfile mv ../build . sudo docker build -t pre-official-ui -f Dockerfile.pre . sudo docker login --username=***** -p ******* registry-vpc.cn-hangzhou.aliyuncs.com sudo docker tag pre-official-ui registry-vpc.cn-hangzhou.aliyuncs.com/weifeng-system/pre-official-ui sudo docker push registry-vpc.cn-hangzhou.aliyuncs.com/weifeng-system/pre-official-ui curl https://cs.console.aliyun.com/hook/trigger?*****************U0pM7Vd60sO3BESRlnjd46F7_wlxcXPKjS8t7k if [ $? -eq 0 ]; then echo -e "\033[32m[ the application official-ui-pre successfully deployed ]\033[0m" else echo -e "\033[31m\033[01m[ the application official-ui-pre deploy failed ]\033[0m" fi