# Build stage FROM golang:1.21-alpine AS builder WORKDIR /app # Copy go mod files COPY go.mod go.sum ./ RUN go mod download # Copy source code COPY cmd/landing_main.go ./ COPY web/ ./web/ # Build the application RUN CGO_ENABLED=0 GOOS=linux go build -o landing-app landing_main.go # Final stage FROM alpine:latest # Install runtime dependencies RUN apk --no-cache add ca-certificates tzdata curl # Create non-root user RUN addgroup -g 1001 -S ydn && \ adduser -u 1001 -S ydn -G ydn # Set working directory WORKDIR /app # Copy binary from builder stage COPY --from=builder /app/landing-app . # Copy web assets COPY --from=builder /app/web ./web # Create necessary directories RUN mkdir -p logs configs # Change ownership RUN chown -R ydn:ydn /app # Switch to non-root user USER ydn # Expose port EXPOSE 8080 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8080/health || exit 1 # Run the application CMD ["./landing-app"]