Enable Docker image build on every push to main (paths-ignore for docs-only changes mirrors webapp pattern). Fix root Dockerfile (shipped by #89) which was missing the swag init step required for //go:embed of swagger.json (gitignored). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
44 lines
958 B
Docker
44 lines
958 B
Docker
# Build dance-lessons-coach Docker image
|
|
FROM golang:1.26-alpine AS builder
|
|
|
|
# Install git (required for go mod download)
|
|
RUN apk add --no-cache git
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy go module files and download dependencies
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy entire source code
|
|
COPY . .
|
|
|
|
# Generate Swagger documentation if not already present
|
|
# (pkg/server/docs/ is gitignored ; the binary //go:embed depends on it)
|
|
RUN if [ ! -f pkg/server/docs/swagger.json ]; then \
|
|
go install github.com/swaggo/swag/cmd/swag@latest && \
|
|
cd pkg/server && go generate ; \
|
|
fi
|
|
|
|
# Build the server binary
|
|
RUN go build -o app ./cmd/server
|
|
|
|
# Final lightweight stage
|
|
FROM alpine:latest
|
|
|
|
# Install CA certificates for HTTPS
|
|
RUN apk --no-cache add ca-certificates
|
|
|
|
# Set working directory
|
|
WORKDIR /root/
|
|
|
|
# Copy binary from builder stage
|
|
COPY --from=builder /app/app .
|
|
|
|
# Expose port 8080
|
|
EXPOSE 8080
|
|
|
|
# Start the server
|
|
CMD ["./app"]
|