2025-09-01 16:20:27 +07:00
|
|
|
# 1) Build stage
|
|
|
|
|
FROM golang:1.21-alpine AS build
|
|
|
|
|
RUN apk --no-cache add ca-certificates tzdata git curl
|
|
|
|
|
WORKDIR /src
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
RUN go mod download
|
|
|
|
|
COPY . .
|
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /out/app ./cmd/server
|
|
|
|
|
|
|
|
|
|
# 2) Production stage
|
2025-07-18 20:10:29 +07:00
|
|
|
FROM debian:bullseye-slim AS production
|
2025-09-01 16:20:27 +07:00
|
|
|
RUN apt-get update && apt-get install -y ca-certificates tzdata curl && rm -rf /var/lib/apt/lists/*
|
2025-07-18 20:10:29 +07:00
|
|
|
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
2025-09-01 16:14:15 +07:00
|
|
|
COPY --from=build /out/app /app
|
2023-10-08 15:59:42 +07:00
|
|
|
ENV TZ=Asia/Jakarta
|
2025-07-18 20:10:29 +07:00
|
|
|
EXPOSE 3300
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
2025-09-01 16:14:15 +07:00
|
|
|
CMD curl -fsS http://localhost:3300/health || exit 1
|
2025-07-18 20:10:29 +07:00
|
|
|
USER appuser
|
2023-10-08 15:59:42 +07:00
|
|
|
ENTRYPOINT ["/app"]
|