# Multi-stage build for SubConverter-Go # ====================================== # Stage 1: Build stage FROM golang:1.21-alpine AS builder # Install build dependencies RUN apk add --no-cache git # 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 application with ldflags RUN CGO_ENABLED=0 GOOS=linux go build \ -ldflags="-w -s -X 'main.Version=1.0.0' -X 'main.BuildTime=$(date -u '+%Y-%m-%d %H:%M:%S')'" \ -a -installsuffix cgo \ -o subconverter-go main.go # Stage 2: Runtime stage FROM alpine:latest # Install ca-certificates for HTTPS RUN apk --no-cache add ca-certificates tzdata # Create non-root user RUN addgroup -g 1001 -S appgroup && \ adduser -u 1001 -S appuser -G appgroup # Create directories RUN mkdir -p /app/logs /app/config && \ chown -R appuser:appgroup /app # Set working directory WORKDIR /app # Copy binary from builder COPY --from=builder /app/subconverter-go . # Copy config file template COPY config.yaml.example ./config.yaml.example # Switch to non-root user USER appuser # Expose port EXPOSE 25500 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:25500/health || exit 1 # Run the application CMD ["./subconverter-go", "--config", "/app/config.yaml"]