69 lines
1.4 KiB
Docker
69 lines
1.4 KiB
Docker
# Build stage
|
|
FROM golang:1.24-alpine AS builder
|
|
|
|
RUN apk add --no-cache git ca-certificates tzdata
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy go mod files first for better caching
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the main binary
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-ldflags="-s -w" \
|
|
-o /app/quoteforge \
|
|
./cmd/server
|
|
|
|
# Build the cron binary
|
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
|
-ldflags="-s -w" \
|
|
-o /app/quoteforge-cron \
|
|
./cmd/cron
|
|
|
|
# Final stage
|
|
FROM alpine:3.19
|
|
|
|
RUN apk add --no-cache ca-certificates tzdata cron
|
|
|
|
# Create non-root user
|
|
RUN adduser -D -g '' appuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /app/quoteforge .
|
|
COPY --from=builder /app/quoteforge-cron .
|
|
|
|
# Copy cron job configuration
|
|
COPY crontab /etc/crontabs/appuser
|
|
RUN chmod 0600 /etc/crontabs/appuser
|
|
|
|
# Create log directory
|
|
RUN mkdir -p /var/log/cron
|
|
|
|
# Copy web templates and static files
|
|
COPY --from=builder /app/web ./web
|
|
|
|
# Copy migrations
|
|
COPY --from=builder /app/migrations ./migrations
|
|
|
|
# Copy example config (actual config should be mounted)
|
|
COPY --from=builder /app/config.example.yaml ./config.example.yaml
|
|
|
|
# Set ownership
|
|
RUN chown -R appuser:appuser /app
|
|
|
|
USER appuser
|
|
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
|
|
|
ENTRYPOINT ["/app/quoteforge"]
|