feat: initialize golang project template with docker and ci/cd
Some checks failed
CI / Lint (push) Failing after 45s
CI / Test (push) Failing after 10s
CI / Build (push) Has been skipped
CI / Docker Build (push) Has been skipped

This commit is contained in:
2026-01-12 10:47:04 +01:00
parent 12473662e8
commit 6ef83e18f8
11 changed files with 372 additions and 1 deletions

29
Dockerfile Normal file
View File

@@ -0,0 +1,29 @@
# Build stage
FROM golang:1.23-alpine AS builder
WORKDIR /app
# Copy go.mod and go.sum first to leverage Docker cache
# We need to check if go.sum exists, but COPY fails if it doesn't.
# Since we just ran go mod init, go.sum might not exist yet if no deps.
# SAFE PATTERN: COPY go.mod and optional go.sum
COPY go.mod go.sum* ./
RUN go mod download
# Copy the rest of the source code
COPY . .
# Build the application
# -ldflags="-w -s" strips debug information for smaller binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o /go/bin/app ./cmd/app
# Final stage
# Use distroless static image for security and minimal footprint
FROM gcr.io/distroless/static-debian12:nonroot
WORKDIR /
COPY --from=builder /go/bin/app /app
USER nonroot:nonroot
ENTRYPOINT ["/app"]