FROM node:20-slim

LABEL version="1.0.0"
LABEL description="Example Fastify (Node.js) Docker Image"
LABEL maintainer "Sandro Martini <sandro.martini@gmail.com>"

RUN mkdir -p /work
WORKDIR /work

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
# ENV NODE_ENV production
# to be able to run tests (for example in CI), do not set production as environment

ENV NPM_CONFIG_LOGLEVEL warn

# copy project definition/dependencies files, for better reuse of layers
COPY ./package*.json ./$WORKDIR

# install dependencies here, for better reuse of layers
RUN npm install
# RUN npm install --only=production

# copy all sources in the container (exclusions in .dockerignore file)
COPY . $WORKDIR

EXPOSE 3000

# add an healthcheck, useful
# healthcheck with curl, but not recommended
# HEALTHCHECK CMD curl --fail http://localhost:3000/health || exit 1
# healthcheck by calling the additional script exposed by the plugin
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD npm start

CMD [ "npm", "run", "example-under-pressure-fail" ]
