From 63cc403988b9ae062e0a7fb31cb8782b74198c73 Mon Sep 17 00:00:00 2001 From: hajimi Date: Sun, 2 Aug 2026 11:21:43 +0800 Subject: [PATCH] build: add production frontend images --- admin/.dockerignore | 9 +++++++ docker/Dockerfile.admin | 19 ++++++++++++++ docker/Dockerfile.uniapp-h5 | 21 ++++++++++++++++ docker/config/nginx/static/admin.conf | 30 +++++++++++++++++++++++ docker/config/nginx/static/uniapp-h5.conf | 30 +++++++++++++++++++++++ uniapp/.dockerignore | 11 +++++++++ 6 files changed, 120 insertions(+) create mode 100644 admin/.dockerignore create mode 100644 docker/Dockerfile.admin create mode 100644 docker/Dockerfile.uniapp-h5 create mode 100644 docker/config/nginx/static/admin.conf create mode 100644 docker/config/nginx/static/uniapp-h5.conf create mode 100644 uniapp/.dockerignore diff --git a/admin/.dockerignore b/admin/.dockerignore new file mode 100644 index 0000000..2ad7c8e --- /dev/null +++ b/admin/.dockerignore @@ -0,0 +1,9 @@ +node_modules +dist +dist-ssr +.git +.env +.env.* +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/docker/Dockerfile.admin b/docker/Dockerfile.admin new file mode 100644 index 0000000..fe6897a --- /dev/null +++ b/docker/Dockerfile.admin @@ -0,0 +1,19 @@ +# syntax=docker/dockerfile:1 + +FROM node:20-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci --no-audit --no-fund + +COPY . . + +ARG VITE_APP_BASE_URL=https://api.sbnews.net +ENV VITE_APP_BASE_URL=${VITE_APP_BASE_URL} + +RUN npx vite build + +FROM registry.cn-guangzhou.aliyuncs.com/likeadmin/nginx:1.23.1 + +COPY --from=build /app/dist/ /usr/share/nginx/html/ diff --git a/docker/Dockerfile.uniapp-h5 b/docker/Dockerfile.uniapp-h5 new file mode 100644 index 0000000..187f5bc --- /dev/null +++ b/docker/Dockerfile.uniapp-h5 @@ -0,0 +1,21 @@ +# syntax=docker/dockerfile:1 + +FROM node:20-alpine AS build + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci --legacy-peer-deps --no-audit --no-fund + +COPY . . + +ARG VITE_APP_BASE_URL=https://api.sbnews.net +ENV VITE_APP_BASE_URL=${VITE_APP_BASE_URL} \ + UNIAPP_RELEASE_PATH=/tmp/mobile-release \ + NODE_OPTIONS=--max-old-space-size=4096 + +RUN npm run build:h5 + +FROM registry.cn-guangzhou.aliyuncs.com/likeadmin/nginx:1.23.1 + +COPY --from=build /app/dist/build/h5/ /usr/share/nginx/html/ diff --git a/docker/config/nginx/static/admin.conf b/docker/config/nginx/static/admin.conf new file mode 100644 index 0000000..98b283c --- /dev/null +++ b/docker/config/nginx/static/admin.conf @@ -0,0 +1,30 @@ +server { + listen 127.0.0.1:5176; + server_name keislwo.sbnews.net; + + root /usr/share/nginx/html; + index index.html; + + access_log /var/log/nginx/admin_access.log; + error_log /var/log/nginx/admin_error.log; + + location = /healthz { + access_log off; + default_type text/plain; + return 200 "ok\n"; + } + + location = /index.html { + add_header Cache-Control "no-cache"; + } + + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(?:css|js|jpg|jpeg|gif|png|svg|ico|webp|woff2?)$ { + expires 7d; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } +} diff --git a/docker/config/nginx/static/uniapp-h5.conf b/docker/config/nginx/static/uniapp-h5.conf new file mode 100644 index 0000000..1c65f9c --- /dev/null +++ b/docker/config/nginx/static/uniapp-h5.conf @@ -0,0 +1,30 @@ +server { + listen 127.0.0.1:5177; + server_name web.sbnews.net; + + root /usr/share/nginx/html; + index index.html; + + access_log /var/log/nginx/h5_access.log; + error_log /var/log/nginx/h5_error.log; + + location = /healthz { + access_log off; + default_type text/plain; + return 200 "ok\n"; + } + + location = /index.html { + add_header Cache-Control "no-cache"; + } + + location / { + try_files $uri $uri/ /index.html; + } + + location ~* \.(?:css|js|jpg|jpeg|gif|png|svg|ico|webp|woff2?)$ { + expires 7d; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } +} diff --git a/uniapp/.dockerignore b/uniapp/.dockerignore new file mode 100644 index 0000000..f25fbfb --- /dev/null +++ b/uniapp/.dockerignore @@ -0,0 +1,11 @@ +node_modules +dist +dist-ssr +unpackage +.hbuilderx +.git +.env +.env.* +npm-debug.log* +yarn-debug.log* +yarn-error.log*