thread-master/deploy/Dockerfile.backend

26 lines
979 B
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 後端共用 image一次 build gateway / worker / tool 三個 binary。
# compose 以 entrypoint/command 覆寫,決定該容器當 gateway、job worker 或一次性 init。
# build context = repo root見 deploy/docker-compose.yml
FROM golang:1.23-alpine AS build
WORKDIR /src
RUN apk add --no-cache git
COPY backend/go.mod backend/go.sum ./
RUN go mod download
COPY backend/ ./
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/gateway . \
&& CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/worker ./cmd/worker \
&& CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags "-s -w" -o /out/tool ./cmd/tool
FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata wget
ENV TZ=UTC
WORKDIR /app
COPY --from=build /out/ /app/
COPY backend/etc/ /app/etc/
# 預設角色為 gatewaycompose 會把 worker / init 用 entrypoint 覆寫。
EXPOSE 8890
ENTRYPOINT ["/app/gateway"]
CMD ["-f", "/app/etc/gateway.prod.yaml"]