From 7c2560422d0e6dd4a0396eda45a8615808d46501 Mon Sep 17 00:00:00 2001 From: Savely Krendelhoff Date: Sat, 23 Aug 2025 17:32:35 +0700 Subject: [PATCH] [PHASE-8] Introduce Dockerfile --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ce80c73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# 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"]