# syntax=docker/dockerfile:1.7
FROM golang:1.26.3-alpine AS builder

WORKDIR /src

# Module proxy is a build-time contract so Docker builds can recover from transient proxy EOFs.
ARG GOPROXY=https://goproxy.cn|https://proxy.golang.org|direct
ARG GOSUMDB=sum.golang.org
ENV GOPROXY=${GOPROXY} GOSUMDB=${GOSUMDB}

COPY go.mod go.sum ./
COPY api/go.mod api/go.sum ./api/
RUN --mount=type=cache,id=hyapp-go-mod,target=/go/pkg/mod \
    --mount=type=cache,id=hyapp-go-build,target=/root/.cache/go-build \
    GOWORK=off go mod download

COPY . .

RUN --mount=type=cache,id=hyapp-go-mod,target=/go/pkg/mod \
    --mount=type=cache,id=hyapp-go-build,target=/root/.cache/go-build \
    mkdir -p /out && \
    GOWORK=off CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /out/ ./services/activity-service/cmd/server ./cmd/grpc-health-probe

FROM alpine:3.20

ENV TZ=UTC

WORKDIR /app

RUN apk add --no-cache ca-certificates && adduser -D -g '' appuser

COPY --from=builder /out/server /app/server
COPY --from=builder /out/grpc-health-probe /app/grpc-health-probe
COPY services/activity-service/configs/config.docker.yaml /app/config.yaml

USER appuser

EXPOSE 13006 13106

ENTRYPOINT ["/app/server"]
CMD ["-config", "/app/config.yaml"]
