FROM golang:1.26-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build -o /server ./cmd/main.go && \
    go install github.com/pressly/goose/v3/cmd/goose@latest

FROM alpine:3.19

RUN apk add --no-cache ca-certificates

WORKDIR /app

COPY --from=builder /server /server
COPY --from=builder /go/bin/goose /usr/local/bin/goose
COPY migrations /app/migrations

EXPOSE 8080

CMD ["/server"]