# Build stage FROM golang:1.23-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o matching-app cmd/server/main.go # Final image FROM alpine:3.18 WORKDIR /app # Add non-root user RUN addgroup -S appgroup && adduser -S appuser -G appgroup # Copy binary and resources COPY --from=builder --chown=appuser:appgroup /app/matching-app . COPY --from=builder --chown=appuser:appgroup /app/migrations ./migrations COPY --from=builder --chown=appuser:appgroup /app/configs ./configs # Environment variables ENV APP_PORT=8080 ENV APP_ENV=production # Install wget for healthcheck RUN apk --no-cache add wget # Healthcheck HEALTHCHECK --interval=30s --timeout=3s \ CMD wget --no-verbose --tries=1 --spider http://localhost:${APP_PORT}/health || exit 1 EXPOSE ${APP_PORT} USER appuser ENTRYPOINT ["/app/matching-app"] CMD []