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 " 33[32m[ the application official-ui-pre successfully deployed ] 33[0m" else echo -e " 33[31m 33[01m[ the application official-ui-pre deploy failed ] 33[0m" fi
第二种方式:
dockefile:
FROM nginx:1.15.10-alpine COPY dist /usr/share/nginx/html
执行Shell :
SERVICE_NAME=dev-platform-nginx TAG=0.1.${BUILD_NUMBER} REGISTRY=registry-vpc.cn-hangzhou.aliyuncs.com REGISTRY_NAMESPACE=weifeng IMAGE=$REGISTRY/$REGISTRY_NAMESPACE/$SERVICE_NAME:$TAG npm i && npm run build docker build -t $IMAGE . docker push $IMAGE kubectl set image -n weifeng-test deployment/$SERVICE_NAME $SERVICE_NAME=$IMAGE
nginx.conf , 和nginx 配置文件通过阿里云k8s 配置项挂载方式进行配置。