- Add CORS_ORIGINS env var for multiple domains support - Update config.go with CORSOrigins field and getEnvStringSlice helper - Rewrite CORS middleware with CORSWithConfig for dynamic origins - Update server.go to use configurable CORS - Update .env.example with all configuration variables - Optimize Dockerfile: switch to distroless image, update port to 8214
31 lines
757 B
Docker
31 lines
757 B
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# ===== STAGE 1: Build =====
|
|
FROM golang:1.24-alpine AS builder
|
|
|
|
WORKDIR /build
|
|
|
|
# Cache de dependências - só rebuild se go.mod/go.sum mudar
|
|
COPY go.mod go.sum ./
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
go mod download && go mod verify
|
|
|
|
# Copia código fonte
|
|
COPY . .
|
|
|
|
# Build otimizado com cache
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
|
|
go build -trimpath -ldflags="-s -w" \
|
|
-o /app/server ./cmd/api
|
|
|
|
# ===== STAGE 2: Runtime (distroless - segurança + mínimo ~2MB) =====
|
|
FROM gcr.io/distroless/static-debian12:nonroot
|
|
|
|
# Binary
|
|
COPY --from=builder /app/server /server
|
|
|
|
EXPOSE 8214
|
|
|
|
ENTRYPOINT ["/server"]
|