Docker Jenkins 安装NodeJS插件,dockerfile编译部署vue工程

Jenkins下载nodeJS插件

下载插件

全局配置

下载node

# 进入docker容器镜像
docker exec -it 480061b40bd7 /bin/bash

#官网地址:https://nodejs.org/dist/
#下载
wget https://nodejs.org/dist/v18.4.0/node-v18.4.0-linux-x64.tar.gz

#解压到指定目录
tar zxvf node-v18.4.0-linux-x64.tar.gz -C /usr/local/

# 重命名
cd /usr/local
mv node-v18.4.0-linux-x64/ node18

修改环境变量

# 编辑环境变量
vi /etc/profile

# 添加如下配置

export NODE_HOME=/usr/local/node18
export PATH=$NODE_HOME/bin:$PATH

# 让配置生效
source /etc/profile

设置npm国内镜像

sodu npm install -g cnpm --registry=https://registry.npm.taobao.org

Jenkins配置

 

 

docker login --username=xxxx registry-vpc.cn-hangzhou.aliyuncs.com --password=xxxx
echo "dev-登录阿里云镜像仓成功..."
npm run build:prod
docker build -t xxxx .
docker tag xxxxx:latest registry-vpc.cn-hangzhou.aliyuncs.com/xxxx:dev1.0.0
docker push registry-vpc.cn-hangzhou.aliyuncs.com/xxxx:dev1.0.0
echo "dev-前端vue 推送成功"
FROM nginx:1.21.3
COPY ./dist /usr/share/nginx/html/
COPY ./docker/docker.template /etc/nginx/docker.template
EXPOSE 80
CMD envsubst '$GATEWAY_API_1 $GATEWAY_API_2' < /etc/nginx/docker.template > /etc/nginx/nginx.conf && nginx -g 'daemon off;'
worker_processes  8;

events {
    use epoll;
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        off;
    keepalive_timeout  65;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $request_time';

   access_log  access.log  main;
   client_max_body_size 100M;

    upstream base_server{
        server ${GATEWAY_API_1};
        server ${GATEWAY_API_2};
    }

    server {
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_comp_level 5;
        gzip_types application/javascript text/plain text/css application/json application/xml    text/javascript;
        gzip_vary on;
        gzip_disable "MSIE [1-6].";

        listen       80;
        listen  [::]:80;
        server_name  localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }

        location /prod-api/ {
            proxy_pass http://base_server/;
            proxy_redirect  off;
            proxy_set_header Host $host:$server_port;
            proxy_set_header    X-Real-IP   $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_intercept_errors on;
        }

        error_page   502 503 =200  /default_api;
        location = /default_api {
            default_type application/json;
            return 200 '{"code":-1,"data":"","msg":"服务调用异常或正在发版,请您稍后重试!"}';
        }

        error_page 413 =200 /limit_file_api;
        location = /limit_file_api {
            default_type application/json;
            return 200 '{"code":-1,"data":"","msg":"上传文件过大,最大100M"}';
        }
    }
}

 

posted @ 2022-06-20 16:26  陈彦斌  阅读(2240)  评论(0编辑  收藏  举报