# Stage 1: Build stage
FROM golang:1.24-alpine AS build
WORKDIR /app

# Install dependencies for swag CLI (git is required)
RUN apk add --no-cache git
# Install swag CLI for Swagger generation
# RUN go install github.com/swaggo/swag/cmd/swag@latest

# Copy and download dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy the source code
COPY . .

# Generate Swagger docs
# RUN swag init -g cmd/agentchat/main.go -o docs

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .

# Stage 2: Final stage
FROM alpine:edge
WORKDIR /app

# Copy the binary from the build stage
COPY --from=build /app/myapp .

# Copy swagger.yaml (optional, since it's embedded in the binary)
COPY --from=build /app/docs/swagger.yaml /app/docs/swagger.yaml

# Install curl and CA certificates
RUN apk update && apk add --no-cache curl ca-certificates

# Expose port
EXPOSE 8000

# Set the entrypoint command
ENTRYPOINT ["/app/myapp"]