2025-11-07 20:54:18 +00:00
|
|
|
# Build stage
|
|
|
|
|
FROM golang:1.25.1-alpine AS builder
|
|
|
|
|
|
|
|
|
|
# Install build dependencies
|
|
|
|
|
RUN apk add --no-cache git make
|
|
|
|
|
|
|
|
|
|
# Set working directory
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy go mod files
|
|
|
|
|
COPY go.mod go.sum ./
|
|
|
|
|
|
|
|
|
|
# Download dependencies
|
|
|
|
|
RUN go mod download
|
|
|
|
|
|
|
|
|
|
# Copy source code
|
|
|
|
|
COPY . .
|
|
|
|
|
|
|
|
|
|
# Build the server binary
|
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o server cmd/server/main.go
|
|
|
|
|
|
|
|
|
|
# Build the CLI binary (optional, for migrations)
|
|
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o cli cmd/cli/main.go
|
|
|
|
|
|
|
|
|
|
# Runtime stage
|
|
|
|
|
FROM alpine:latest
|
|
|
|
|
|
2025-11-07 21:53:07 +00:00
|
|
|
# Install ca-certificates for HTTPS requests and wget for healthcheck
|
|
|
|
|
RUN apk --no-cache add ca-certificates tzdata wget
|
2025-11-07 20:54:18 +00:00
|
|
|
|
|
|
|
|
WORKDIR /root/
|
|
|
|
|
|
|
|
|
|
# Copy binaries from builder
|
|
|
|
|
COPY --from=builder /app/server .
|
|
|
|
|
COPY --from=builder /app/cli .
|
|
|
|
|
|
|
|
|
|
# Copy templates if they exist
|
|
|
|
|
COPY --from=builder /app/internal/templates ./internal/templates
|
|
|
|
|
|
|
|
|
|
# Expose port (adjust if needed)
|
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
2025-11-07 21:53:07 +00:00
|
|
|
# Health check - give more time for startup
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
|
2025-11-07 20:54:18 +00:00
|
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
|
|
|
|
|
|
|
|
|
# Run the server
|
|
|
|
|
CMD ["./server"]
|