FROM node:18-alpine as build

ARG env_target
ARG release_version

WORKDIR /app

COPY . /app/

COPY env/$env_target /app/.env

RUN echo -e "\n" >> /app/.env
RUN echo -e "APP_VERSION=${release_version}" >> /app/.env

RUN npm install
RUN npm run build

FROM caddy:2.6.1-alpine
COPY caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=build /app/dist /srv