# Multi-stage build for custom Temporal server with authorization
FROM golang:1.21 AS builder

WORKDIR /app

# Copy go mod files
COPY go.mod go.sum* ./
RUN go mod download

# Copy source code
COPY main.go ./

# Build the server
RUN CGO_ENABLED=0 GOOS=linux go build -o temporal-server main.go

# Final stage
FROM temporalio/auto-setup:1.29.0

# Copy the custom server binary
COPY --from=builder /app/temporal-server /usr/local/bin/temporal-server

# Copy configuration
COPY config/ /etc/temporal/config/

# The auto-setup image's entrypoint will handle initialization
# We'll override the command to use our custom binary
ENTRYPOINT ["/entrypoint.sh"]
CMD ["temporal-server", "start"]
