FROM docker.io/nginx:1.31-alpine AS build

COPY docker/web/conf/default.conf.template /etc/nginx/templates/default.conf.template
COPY docker/web/conf/fastcgi_params /etc/nginx/fastcgi_params
COPY docker/web/start.sh /usr/local/bin/start

RUN chmod 755 /usr/local/bin/start

FROM build AS app_build_for_production

WORKDIR /home/app
COPY application /home/app

RUN apk --no-cache add git nodejs npm \
    && npm install && npm run build \
    && rm -rf /home/app/node_modules

FROM build AS production

COPY --from=app_build_for_production /home/app/public /usr/share/nginx/html

WORKDIR /usr/share/nginx/html

EXPOSE 80
CMD ["/usr/local/bin/start"]

FROM build AS develop
WORKDIR /usr/share/nginx/html

EXPOSE 80
CMD ["/usr/local/bin/start"]
