FROM golang:1.25-alpine AS builder
RUN apk add --no-cache gcc musl-dev
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go get github.com/jackc/pgx/v5@v5.5.5 && go mod tidy
RUN CGO_ENABLED=0 GOOS=linux go build -o /umm ./cmd/server/
RUN CGO_ENABLED=1 GOOS=linux go build -o /umm-migrate ./cmd/migrate/

FROM alpine:3.19
RUN apk --no-cache add ca-certificates wget ffmpeg
WORKDIR /app
COPY --from=builder /umm .
COPY --from=builder /umm-migrate .
COPY internal/db/migrations/ ./internal/db/migrations/
EXPOSE 8084
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD wget -qO- http://localhost:8084/health/live || exit 1
CMD ["./umm"]
