Files
MyClub/Dockerfile
T
Tomas Dvorak b9cea0cd77 dev day #79
2025-11-02 01:04:02 +01:00

50 lines
1.1 KiB
Docker

# Build stage
FROM golang:1.24.5-alpine AS builder
WORKDIR /app
# Install dependencies
RUN apk add --no-cache git
# Download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -o fotbal-club
# Final stage
FROM alpine:latest
WORKDIR /app
# Install runtime dependencies (TLS certs, timezone data) and create non-root user
RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S app && adduser -S app -G app \
&& mkdir -p /app/uploads /app/cache \
&& chown -R app:app /app
# Copy the binary from builder
COPY --from=builder /app/fotbal-club ./fotbal-club
# Copy templates and static files if any
COPY ./templates ./templates
COPY ./static ./static
# Environment and permissions
ENV GIN_MODE=release
USER app
# Expose port
EXPOSE 8080
# Healthcheck: use busybox wget to probe liveness/readiness
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD wget -q -O - http://127.0.0.1:8080/api/v1/health >/dev/null 2>&1 || exit 1
# Command to run the executable
CMD ["./fotbal-club"]