# Use Go 1.23 bookworm as base image
FROM docker.io/library/golang:bookworm AS base

# Builder stage
# =============================================================================
# Create a builder stage based on the "base" image
FROM base AS builder

# Move to working directory /build
WORKDIR /build

# Copy the go.mod and go.sum files to the /build directory
COPY go.mod go.sum ./

# Install dependencies
RUN go mod download

# Copy the entire source code into the container
COPY . .
RUN rm go.work*

# Build the application
# Turn off CGO to ensure static binaries

RUN CGO_ENABLED=0 go build -o probo
# RUN go build -ldflags='-s -w -extldflags=-static' -o probo

# Production stage
# =============================================================================
# Create a production stage to run the application binary
# FROM docker.io/library/golang:bookworm AS production
FROM scratch as production

# Move to working directory /prod
WORKDIR /prod

# Copy binary from builder stage
COPY --from=builder /build/probo .

# Copy data folder from builder stage
# COPY --from=builder /build/embed/data ./data

# Document the port that may need to be published
EXPOSE 3000

# Start the application
CMD ["./probo", "serve"]
# CMD ["./ls"]


