# ---- Build stage --------------------------------------------------------
FROM golang:1.22-alpine AS builder

WORKDIR /app

# Cache dependency downloads separately from source
COPY go.mod ./
RUN go mod download

COPY . .

# Build a fully static binary
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o worker .

# ---- Final image --------------------------------------------------------
FROM alpine:3.19

# Create a non-root user/group
RUN addgroup -g 1001 appgroup && \
    adduser -D -u 1001 -G appgroup appuser

WORKDIR /app

COPY --from=builder /app/worker .

USER appuser

EXPOSE 8080

ENTRYPOINT ["./worker"]
