UmiJS打包一个镜像包适用于不同环境

2022-02-25  本文已影响0人  Poppy11

1、本地代码创建不同nginx配置

image.png
nginx配置信息
server {
    listen 8080;
    absolute_redirect off;
    # gzip config
    gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";

    root /usr/share/nginx/dist;
    index index.html index.htm;

    location / {
        client_max_body_size 200M;
        try_files $uri $uri/ /index.html;
    }

    location /api/ {
        client_max_body_size 200M;
        proxy_pass  https://apis-dev.newegg.org/;
    }

    location /dashboardApi/{
        client_max_body_size 200M;
        proxy_pass  https://apis.newegg.org/;
    }

    location /nas/{
        client_max_body_size 200M;
        proxy_pass  https://10.16.75.22:9898/03m8z6l4m9z0f2cy1lg3hupb3t/;
    }
}

2、创建Dockerfile

FROM harbor.newegg.org/base/nginx-unprivileged:stable-alpine
COPY nginx.*.conf /etc/nginx/dolphin-portal/
COPY --chown=nginx:nginx config.sh /docker-entrypoint.d/
RUN chmod +x /docker-entrypoint.d/config.sh
COPY --chown=nginx:nginx /dist /usr/share/nginx/dist

3、编写config.sh脚本

#!/bin/sh
set -e

location=${LOCATION}

if [ ! "${location}" ]; then
    echo "location not set!"
    exit 1
fi

echo "LOCATION: ${location}"

# replace nginx conf file
cp -f /etc/nginx/dolphin-portal/nginx.${location}.conf /etc/nginx/conf.d

4、在机器上设置对应环境字段

上一篇 下一篇

猜你喜欢

热点阅读