FROM golang:1.23-alpine as build_go
RUN apk add --no-cache curl npm

WORKDIR /app

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

COPY . .

RUN go install github.com/a-h/templ/cmd/templ@latest
RUN npm install tailwindcss @tailwindcss/cli

RUN templ generate
RUN npx @tailwindcss/cli -i ./cmd/web/assets/css/input.css -o ./cmd/web/assets/css/output.css

RUN go build -o main cmd/main.go

# Stage 2, distribution container
FROM golang:1.23-alpine
EXPOSE 8080
VOLUME /sorted
VOLUME /frontend

ENV PORT 8080
ENV DB_HOST ""
ENV DB_PORT ""
ENV DB_USERNAME ""
ENV DB_PASSWORD ""
ENV DB_NAME ""
ENV MUSIC_PATH ""

COPY --from=build_go /app/main .
COPY ./songs/ ./songs/

CMD ./main
