# Build stage FROM golang:1.24-alpine AS builder # Install build dependencies RUN apk add --no-cache git gcc musl-dev WORKDIR /build # Copy go mod files COPY go.mod go.sum ./ RUN go mod download # Copy source code COPY . . # Build the binary RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o markedit ./cmd/server # Runtime stage FROM alpine:latest # Install ca-certificates for HTTPS and git for git operations RUN apk --no-cache add ca-certificates git WORKDIR /app # Copy binary from builder COPY --from=builder /build/markedit . # Copy migrations COPY --from=builder /build/internal/database/migrations ./internal/database/migrations # Create data directories RUN mkdir -p /app/data/repos # Expose port EXPOSE 8080 # Run as non-root user RUN adduser -D -u 1000 markedit RUN chown -R markedit:markedit /app USER markedit # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/health || exit 1 CMD ["./markedit"]