FROM golang:1.26.3-alpine3.22 AS backendBuilder

RUN apk add --no-cache gcc g++

COPY ./backend /source

RUN cd /source && \
    CGO_ENABLED=1 go build

FROM node:22.22.3-trixie AS frontendBuilder

COPY ./frontend /source

RUN cd /source && \
    rm -rf ./dist ./distMinified ./node_modules && \
    npm install --ignore-scripts && \
    npm run build

FROM alpine:3.22.4

RUN mkdir -p /website

COPY --from=backendBuilder /source/backend /website/server
COPY --from=frontendBuilder /source/distMinified /website/static

ENV PORT=80
ENV FRONTEND_PATH=/website/static

EXPOSE 80

ENTRYPOINT ["/website/server"]
