diff --git a/admin/Dockerfile b/admin/Dockerfile index 78b068a..9d3832d 100644 --- a/admin/Dockerfile +++ b/admin/Dockerfile @@ -1,11 +1,14 @@ -FROM node:20-alpine AS builder +# 国内服务器可设 REGISTRY_MIRROR 拉取镜像,例: docker.m.daocloud.io/library/ +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}node:20-alpine AS builder WORKDIR /app COPY package.json package-lock.json* ./ RUN npm ci --legacy-peer-deps 2>/dev/null || npm install --legacy-peer-deps COPY . . RUN npm run build -FROM nginx:alpine +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html RUN echo 'server { listen 80; location /admin/ { alias /usr/share/nginx/html/; try_files $uri $uri/ /admin/index.html; } }' > /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/server/.env.example b/server/.env.example index 3f9ec21..c43a157 100644 --- a/server/.env.example +++ b/server/.env.example @@ -1,5 +1,6 @@ # 复制为 .env 后按需修改(一键脚本会在缺失时自动复制) -# Docker 部署时 MONGODB_URI 使用 mongo:27017(compose 服务名) +# 本地开发:先启动 MongoDB,改为 mongodb://localhost:27017 +# Docker 部署:保持 mongodb://mongo:27017(compose 服务名) MONGODB_URI=mongodb://mongo:27017 MONGODB_DB=yxd-agent-testing diff --git a/server/Dockerfile b/server/Dockerfile index c8c1ef3..515fab7 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,6 +1,8 @@ # 需在项目根目录构建: docker build -f server/Dockerfile . # 使用 vendor 构建,无需在构建时访问 proxy.golang.org(服务器无外网时也能 build) -FROM golang:1.21-alpine AS builder +# 国内服务器可设 REGISTRY_MIRROR 拉取镜像,例: docker.m.daocloud.io/library/ +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}golang:1.21-alpine AS builder WORKDIR /build COPY server/ ./ # 构建参数:脚本可传 GOPROXY,避免 proxy.golang.org 超时;有 vendor 时主要用 -mod=vendor 离线构建 @@ -8,7 +10,8 @@ ARG GOPROXY=https://goproxy.cn,direct ENV GOPROXY=$GOPROXY RUN CGO_ENABLED=0 go build -mod=vendor -o /app/server . -FROM alpine:3.19 +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}alpine:3.19 WORKDIR /app RUN apk add --no-cache ca-certificates tzdata ENV TZ=Asia/Shanghai diff --git a/web/Dockerfile b/web/Dockerfile index f0c1b5e..2b651f5 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -1,11 +1,14 @@ -FROM node:20-alpine AS builder +# 国内服务器可设 REGISTRY_MIRROR 拉取镜像,例: docker.m.daocloud.io +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}node:20-alpine AS builder WORKDIR /app COPY package.json package-lock.json* ./ RUN npm ci --legacy-peer-deps 2>/dev/null || npm install --legacy-peer-deps COPY . . RUN npm run build -FROM nginx:alpine +ARG REGISTRY_MIRROR= +FROM ${REGISTRY_MIRROR}nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html RUN echo 'server { listen 80; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf EXPOSE 80