# Builder stage
FROM golang:1.22-alpine AS builder

WORKDIR /app

# Copy go.mod and go.sum
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy source code
COPY . .

# Build api and cron binaries
RUN go build -o api ./cmd/api
RUN go build -o cron ./cmd/cron

# Runtime stage
FROM alpine:latest

WORKDIR /app

# Copy binaries from builder
COPY --from=builder /app/api /app/api
COPY --from=builder /app/cron /app/cron

# Set environment variables
ENV DB_DSN="postgres://postgres:postgres@postgres:5432/trip_planner?sslmode=disable"
ENV REDIS_ADDR="redis:6379"
ENV YANDEX_API_KEY=""
ENV TRIP_PLANNER_ADMIN_API_KEY=""

# Expose port
EXPOSE 8080

# Set entrypoint for api service (default)
ENTRYPOINT ["/app/api"]
