Files
ocdp-go/backend/Dockerfile
mangomqy c5e51ed069 ocdp v1
2025-11-13 02:54:06 +00:00

42 lines
982 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.

# ==================================================
# OCDP Backend - Dockerfile
# 构建 backend 服务(连接 PostgreSQL
# ==================================================
FROM golang:1.24-alpine AS builder
RUN apk add --no-cache git make
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o ocdp-backend cmd/api/main.go
# ==================================================
# Runtime
# ==================================================
FROM alpine:latest
RUN apk --no-cache add ca-certificates curl
RUN addgroup -g 1000 ocdp && \
adduser -D -u 1000 -G ocdp ocdp
WORKDIR /app
COPY --from=builder /build/ocdp-backend .
COPY --from=builder /build/config ./config
RUN chown -R ocdp:ocdp /app
USER ocdp
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
CMD ["./ocdp-backend"]