- backend/go.mod: go 1.26 - deploy/docker/Dockerfile: golang:1.26-alpine - deploy/docker/Dockerfile.cn: golang:1.26-alpine
38 lines
1.2 KiB
Docker
38 lines
1.2 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# 前端阶段固定在构建机原生平台编译:多架构构建(linux/amd64,linux/arm64)时
|
|
# 只编译一次,不再被 QEMU 模拟执行两遍
|
|
FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend
|
|
WORKDIR /frontend-build
|
|
COPY ./frontend ./
|
|
RUN npm install -g pnpm@10.25.0 \
|
|
&& pnpm install --frozen-lockfile \
|
|
&& pnpm build
|
|
|
|
# 后端:go.mod 使用纯 Go 的 glebarez/sqlite,可关闭 CGO 直接交叉编译到目标架构,
|
|
# 因此同样固定在原生平台构建
|
|
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS backend
|
|
LABEL author="github.com/Sakurasan"
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
RUN apk --no-cache add make upx
|
|
WORKDIR /build
|
|
COPY . .
|
|
COPY --from=frontend /frontend-build/dist /build/cmd/openteam/dist
|
|
ENV GO111MODULE=on \
|
|
CGO_ENABLED=0 \
|
|
GOOS=$TARGETOS \
|
|
GOARCH=$TARGETARCH
|
|
RUN make build
|
|
|
|
FROM alpine:latest AS runner
|
|
# 设置alpine 时间为上海时间
|
|
RUN apk update && apk --no-cache add tzdata ffmpeg ca-certificates && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
|
&& echo "Asia/Shanghai" > /etc/timezone
|
|
WORKDIR /app
|
|
COPY --from=backend /build/bin/openteam /app/openteam
|
|
ENV GIN_MODE=release
|
|
ENV PATH=$PATH:/app
|
|
EXPOSE 80 443
|
|
ENTRYPOINT ["/app/openteam"]
|