# Build stage
FROM golang:1.23-alpine AS builder

RUN apk add --no-cache git

# Configure Go workspace and private modules
ENV GOPRIVATE=git.threesix.ai/*
ENV GOWORK=/app/go.work

WORKDIR /app

# Copy go workspace and all source (workspace deps are local)
# Note: go.work.sum may not exist if no external dependencies have been synced yet
COPY go.work ./
COPY go.work.su[m] ./
COPY pkg/ ./pkg/
COPY services/{{COMPONENT_NAME}}/ ./services/{{COMPONENT_NAME}}/

# Build from workspace root
RUN CGO_ENABLED=0 go build -o /{{COMPONENT_NAME}} ./services/{{COMPONENT_NAME}}/cmd/server

# Production stage
FROM alpine:3.19

RUN apk add --no-cache ca-certificates tzdata

WORKDIR /

COPY --from=builder /{{COMPONENT_NAME}} /{{COMPONENT_NAME}}

EXPOSE {{PORT}}

ENTRYPOINT ["/{{COMPONENT_NAME}}"]
