From 6efb7c7893dd8ffb3750e6410c6f4a8123db1ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B3=89?= Date: Wed, 30 Mar 2022 16:56:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Docker=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 43 +++++++++++++++++++++++++++++++++++ default.conf.template | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Dockerfile create mode 100644 default.conf.template diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..67872a1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# syntax = docker/dockerfile:experimental +# 使用了 Docker 特性 Buildx 请开启相关特性 + +FROM node:16-alpine AS builder + +ARG PLATFORM=$PLATFORM + +WORKDIR /workspace + +COPY . /workspace + +RUN npm config set registry https://registry.npmmirror.com + +RUN cd /workspace/jeepay-ui-${PLATFORM} && npm install && npm run build + + +FROM nginx:alpine + +ARG PLATFORM=$PLATFORM + +ENV BACKEND_HOST $BACKEND_HOST + +WORKDIR /workspace + +COPY --from=builder /workspace/jeepay-ui-${PLATFORM}/dist /workspace +RUN chmod a+r /workspace + +RUN rm -rf /etc/nginx/conf.d/default.conf + +COPY --from=builder /workspace/default.conf.template /etc/nginx/templates/default.conf.template + +# 编译命令 +# docker buildx build . --build-arg PLATFORM=payment -t jeepay-payment:latest +# docker buildx build . --build-arg PLATFORM=manager -t jeepay-manager:latest +# docker buildx build . --build-arg PLATFORM=merchant -t jeepay-merchant:latest +# +# 如果你需要多平台镜像,你可以使用 --platform linux/amd64,linux/arm64 +# 比如 docker buildx build . --build-arg PLATFORM=merchant -t jeepay-ui-merchant:latest --platform linux/amd64,linux/arm64 +# +# 启动命令 +# docker run -d -p 9226:80 -e BACKEND_HOST=172.20.0.9216 jeepay-ui-payment:latest +# docker run -d -p 9227:80 -e BACKEND_HOST=172.20.0.9217 jeepay-ui-manager:latest +# docker run -d -p 9228:80 -e BACKEND_HOST=172.20.0.9218 jeepay-ui-merchant:latest diff --git a/default.conf.template b/default.conf.template new file mode 100644 index 0000000..fddef1f --- /dev/null +++ b/default.conf.template @@ -0,0 +1,52 @@ +server { + listen 80; + listen [::]:80; + server_name localhost; + root /workspace/; + + try_files $uri $uri/ /index.html; + + location /api/ { + proxy_next_upstream http_502 http_504 error timeout invalid_header; + + proxy_pass http://$BACKEND_HOST; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } + + # favicon.ico + location = /favicon.ico { + log_not_found off; + access_log off; + } + + # robots.txt + location = /robots.txt { + log_not_found off; + access_log off; + } + + # assets, media + location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ { + expires 7d; + access_log off; + } + + # svg, fonts + location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ { + add_header Access-Control-Allow-Origin "*"; + expires 7d; + access_log off; + } + + # gzip + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml; +}