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

WORKDIR /app

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

COPY . .
#RUN go install github.com/a-h/templ/cmd/templ@latest && \
#templ generate && \
#curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss && \
#chmod +x tailwindcss && \
#./tailwindcss-build -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css

RUN go install github.com/a-h/templ/cmd/templ@latest
RUN templ generate

# Install and make tailwindcss executable
RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.17/tailwindcss-linux-x64 \
	&& mv tailwindcss-linux-x64 tailwindcss && chmod +x tailwindcss
CMD ./tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css --minify

RUN go build -o main cmd/main.go

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

ENV DB_HOST ""
ENV DB_PORT ""
ENV DB_USERNAME ""
ENV DB_PASSWORD ""
ENV DB_NAME ""

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

CMD ./main
