# Build stage
FROM golang:1.25-alpine AS builder

RUN apk add --no-cache git

# Configure Go private modules
# Disable workspace mode - each component builds independently with replace directives
ENV GOPRIVATE=git.threesix.ai/*
ENV GOWORK=off

WORKDIR /app

# Copy shared pkg and this worker only
COPY pkg/ ./pkg/
COPY workers/media-worker/ ./workers/media-worker/

# Download dependencies (populates go.sum if empty)
RUN cd pkg && go mod download
RUN cd workers/media-worker && go mod download

# Build from the worker directory (uses replace directive for ../pkg)
RUN cd workers/media-worker && CGO_ENABLED=0 go build -o /media-worker ./cmd/worker

# Production stage
FROM alpine:3.19

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

WORKDIR /

COPY --from=builder /media-worker /media-worker

ENTRYPOINT ["/media-worker"]
