chore(docker): refactor Dockerfile to streamline build stages, update Node.js version, and adjust environment variables for improved deployment

This commit is contained in:
keven1024
2026-05-24 10:52:29 +08:00
parent bdf7894e9b
commit 02900ab1f9
4 changed files with 109 additions and 565 deletions

View File

@@ -1,20 +1,14 @@
FROM node:22-alpine AS front-base
WORKDIR /app
# Install dependencies only when needed
FROM front-base AS front-deps
RUN apk add --no-cache gcompat
WORKDIR /app
COPY . .
RUN corepack enable pnpm && pnpm i && pnpm --filter=015-front deploy dist --legacy && pnpm gen:mail
FROM front-base AS front-builder
WORKDIR /app
RUN apk add --no-cache gcompat
ENV CI=true
COPY --from=front-deps /app/dist/ .
RUN corepack enable pnpm && pnpm build
COPY . .
RUN corepack enable pnpm && pnpm i && pnpm --filter=015-front build && pnpm --dir pkg/mail export
FROM golang:1.25.5 AS backend-builder
FROM golang:1.26.3 AS backend-builder
WORKDIR /app
# Workspace and module manifests for cache
COPY go.work go.work.sum ./
@@ -22,7 +16,7 @@ COPY backend/ ./backend/
COPY worker/ ./worker/
COPY pkg/ ./pkg/
# Inject built email templates so Go can embed them
COPY --from=front-deps /app/pkg/mail/out/ ./pkg/mail/out/
COPY --from=front-builder /app/pkg/mail/out/ ./pkg/mail/out/
RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct && \
go mod download
# Build from workspace root so pkg/utils, pkg/models, pkg/services resolve
@@ -32,7 +26,6 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o backend-bin ./backend
FROM front-base AS runner
ARG VERSION
ARG BUILD_TIME
WORKDIR /app
RUN apk add --no-cache curl openssl
ENV NODE_ENV production
@@ -40,7 +33,7 @@ RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nuxtjs
# Only `.output` folder is needed from the build stage
COPY --from=front-builder --chown=nuxtjs:nodejs /app/.output/ ./
COPY --from=front-builder --chown=nuxtjs:nodejs /app/front/.output/ ./
COPY --from=backend-builder /app/backend-bin /bin/backend
COPY 015.sh /app/015.sh

View File

@@ -43,6 +43,5 @@
"husky": "^9.1.7",
"lint-staged": "^15.5.2",
"prettier": "^3.8.3"
},
"packageManager": "pnpm@10.30.3+sha512.c961d1e0a2d8e354ecaa5166b822516668b7f44cb5bd95122d590dd81922f606f5473b6d23ec4a5be05e7fcd18e8488d47d978bbe981872f1145d06e9a740017"
}
}

636
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,11 @@
packages:
# all packages in direct subdirs of packages/
- 'front'
- 'pkg/*'
# - '*'
# all packages in direct subdirs of packages/
- 'front'
- 'pkg/*'
# - '*'
allowBuilds:
'@parcel/watcher': true
esbuild: true
maplibre-gl: true
sharp: true
vue-demi: true