37 lines
788 B
Docker
37 lines
788 B
Docker
# Build stage
|
|
FROM golang:1.24-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy go mod files
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build server
|
|
RUN CGO_ENABLED=0 go build -o hash-of-wisdom ./cmd/server
|
|
|
|
# Runtime stage
|
|
FROM alpine:3.19
|
|
|
|
# Create non-root user
|
|
RUN addgroup -g 1001 -S hash-of-wisdom && \
|
|
adduser -u 1001 -S hash-of-wisdom -G hash-of-wisdom
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy binary and config from builder stage with correct ownership
|
|
COPY --from=builder --chown=hash-of-wisdom:hash-of-wisdom /app/hash-of-wisdom .
|
|
COPY --from=builder --chown=hash-of-wisdom:hash-of-wisdom /app/config.yaml .
|
|
|
|
# Switch to non-root user
|
|
USER hash-of-wisdom
|
|
|
|
# Expose ports
|
|
EXPOSE 8080 8081
|
|
|
|
# Run server with config file
|
|
CMD ["./hash-of-wisdom", "-config", "config.yaml"]
|