2026-04-15 21:27:15 +08:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
|
|
|
|
|
# ─── Stage 1: Build Go binaries ───────────────────────────────────────────────
|
2026-05-01 00:22:30 +08:00
|
|
|
FROM golang:1.23-alpine AS builder
|
2026-04-15 21:27:15 +08:00
|
|
|
|
2026-05-01 00:22:30 +08:00
|
|
|
ARG TARGETOS
|
|
|
|
|
ARG TARGETARCH
|
2026-04-15 21:27:15 +08:00
|
|
|
|
2026-05-01 00:22:30 +08:00
|
|
|
RUN apk --no-cache add ca-certificates git build-base
|
2026-04-15 21:27:15 +08:00
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
COPY go.mod go.sum ./
|
2026-05-01 00:22:30 +08:00
|
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
|
|
|
go mod download
|
2026-04-15 21:27:15 +08:00
|
|
|
|
|
|
|
|
COPY . .
|
|
|
|
|
|
2026-05-01 00:22:30 +08:00
|
|
|
ARG SERVICE=tenant-api
|
|
|
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
|
CGO_ENABLED=1 GOOS="${TARGETOS:-$(go env GOOS)}" GOARCH="${TARGETARCH:-$(go env GOARCH)}" \
|
2026-04-15 21:27:15 +08:00
|
|
|
go build -trimpath -ldflags="-s -w" \
|
|
|
|
|
-o /bin/service ./cmd/${SERVICE}
|
|
|
|
|
|
2026-05-01 16:01:55 +08:00
|
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
|
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
|
|
|
CGO_ENABLED=1 GOOS="${TARGETOS:-$(go env GOOS)}" GOARCH="${TARGETARCH:-$(go env GOARCH)}" \
|
|
|
|
|
go build -trimpath -ldflags="-s -w" \
|
|
|
|
|
-o /bin/seed-platform-templates ./cmd/seed-platform-templates
|
|
|
|
|
|
2026-04-15 21:27:15 +08:00
|
|
|
# ─── Stage 2: Migration image (bundles SQL files + migrate binary) ─────────────
|
2026-04-30 23:29:15 +08:00
|
|
|
FROM migrate/migrate:v4.19.1 AS migrate-tool
|
2026-04-15 21:27:15 +08:00
|
|
|
|
|
|
|
|
FROM alpine:3.19 AS migrate
|
|
|
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
|
COPY --from=migrate-tool /usr/local/bin/migrate /usr/local/bin/migrate
|
2026-05-01 16:01:55 +08:00
|
|
|
COPY --from=builder /bin/seed-platform-templates /usr/local/bin/seed-platform-templates
|
2026-04-15 21:27:15 +08:00
|
|
|
COPY migrations/ /migrations/
|
|
|
|
|
COPY migrations_monitoring/ /migrations_monitoring/
|
2026-04-28 11:32:50 +08:00
|
|
|
COPY migrations_ops/ /migrations_ops/
|
2026-05-01 16:01:55 +08:00
|
|
|
COPY configs/ /app/configs/
|
2026-04-15 21:27:15 +08:00
|
|
|
ENTRYPOINT ["/usr/local/bin/migrate"]
|
|
|
|
|
|
|
|
|
|
# ─── Stage 3: Runtime image ────────────────────────────────────────────────────
|
|
|
|
|
FROM alpine:3.19 AS runtime
|
|
|
|
|
RUN apk --no-cache add ca-certificates tzdata
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
COPY --from=builder /bin/service /app/service
|
|
|
|
|
COPY configs/ /app/configs/
|
|
|
|
|
|
2026-04-24 22:20:43 +08:00
|
|
|
EXPOSE 8080 8081
|
2026-04-15 21:27:15 +08:00
|
|
|
ENTRYPOINT ["/app/service"]
|