# Build stage
FROM golang:1.21-alpine AS builder

WORKDIR /app

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

# Copy source code
COPY . .

# Build binaries
RUN CGO_ENABLED=0 GOOS=linux go build -o /server ./cmd/server
RUN CGO_ENABLED=0 GOOS=linux go build -o /worker ./cmd/worker

# Server stage
FROM alpine:latest AS server

RUN apk --no-cache add ca-certificates

WORKDIR /app

COPY --from=builder /server .
COPY --from=builder /app/web/dashboard ./web/dashboard

EXPOSE 8080

CMD ["./server"]

# Worker stage
FROM alpine:latest AS worker

RUN apk --no-cache add ca-certificates

WORKDIR /app

COPY --from=builder /worker .

CMD ["./worker"]
