46 lines
1.0 KiB
Docker
46 lines
1.0 KiB
Docker
# Build stage
|
|
FROM docker.io/library/golang:1.25-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apk add --no-cache git
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum* ./
|
|
|
|
# Download dependencies
|
|
RUN go mod download || go mod tidy
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
|
|
|
# Production stage
|
|
FROM docker.io/library/alpine:latest AS production
|
|
|
|
# Install ca-certificates for HTTPS
|
|
RUN apk --no-cache add ca-certificates && \
|
|
addgroup -g 1000 appuser && \
|
|
adduser -D -u 1000 -G appuser appuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy the binary from builder
|
|
COPY --from=builder --chown=appuser:appuser /app/main /app/main
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Expose ports (HTTP API, IPFS swarm, IPFS websocket)
|
|
EXPOSE 8080 4001 4002
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/healthz || exit 1
|
|
|
|
# Run the application
|
|
CMD ["/app/main"]
|