FROM {{ DOCKER_URL }}/nodets:latest AS builder

WORKDIR /app

ENV NODE_ENV=production

# Install
COPY package*.json ./
RUN npm install

# Copy
COPY . .

# Build
RUN tsc
RUN npm run build

RUN find build/static -type f -name "*.js" -exec gzip -9 -k {} \; \
    && find build/static -type f -name "*.css" -exec gzip -9 -k {} \;

FROM {{ DOCKER_URL }}/nginx:latest

COPY --from=builder /app/build /app

# Runtime env: the pipeline fills the list with the names in .env.template, and
# entrypoint.sh writes their pod values to /app/.env and /app/env.js at start up.
ENV NAMIRASOFT_ENVS="{{ ENV_NAMES }}"

COPY entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r$//' /entrypoint.sh && chmod +x /entrypoint.sh

EXPOSE 3000

ENTRYPOINT ["/entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]