zoukankan      html  css  js  c++  java
  • Dockerfile 构建前端nginx应用并用shell脚本实现jenkins自动构建

    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[31m33[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 配置项挂载方式进行配置。 

  • 相关阅读:
    看动画学算法之:栈stack
    asp.net core使用identity+jwt保护你的webapi(三)——refresh token
    asp.net core使用identity+jwt保护你的webapi(二)——获取jwt token
    与 Python 之父聊天:更快的 Python!
    Oracle使用SPM对含有绑定变量SQL做固定的方法
    Oracle Hint no_merge(merge)、no_unnest(unnest)的作用对象陷阱
    Oracle全表扫描导致的direct path read第一次慢第二次以后变快
    Oracle OEM13C添加主机监控遇到一些问题汇总
    还傻傻分不清楚equals和==的区别吗?看完就明白了
    从0到1实现一个简单计算器
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/10265760.html
Copyright © 2011-2022 走看看