# Stage 1: generate CSS + fetch static assets (Tailwind + DaisyUI + htmx, no Node)
FROM alpine:3.20 AS assets
RUN apk add --no-cache curl
WORKDIR /src
ARG TAILWIND_VERSION=v4.1.14
ARG HTMX_VERSION=2.0.4
COPY web/ web/
RUN mkdir -p tools web/static \
    && curl -sLo tools/tailwindcss https://github.com/tailwindlabs/tailwindcss/releases/download/${TAILWIND_VERSION}/tailwindcss-linux-x64-musl \
    && chmod +x tools/tailwindcss \
    && curl -sLo tools/daisyui.mjs https://github.com/saadeghi/daisyui/releases/latest/download/daisyui.mjs \
    && curl -sLo web/static/htmx.min.js https://unpkg.com/htmx.org@${HTMX_VERSION}/dist/htmx.min.js \
    && ./tools/tailwindcss -i web/styles/input.css -o web/static/app.css --minify

# Stage 2: build the Go binary (embeds web/static + templates)
FROM golang:1.25-alpine AS builder
WORKDIR /src
COPY . .
COPY --from=assets /src/web/static/app.css web/static/app.css
COPY --from=assets /src/web/static/htmx.min.js web/static/htmx.min.js
RUN go build -o /server ./cmd/server

# Stage 3: runtime
FROM alpine:3.20
RUN apk add --no-cache ffmpeg
COPY --from=builder /server /server
VOLUME ["/music", "/data"]
EXPOSE 8080
ENTRYPOINT ["/server"]
