2024-05-03 23:15:21 +02:00
|
|
|
# BUILD STAGE
|
|
|
|
FROM node:22.1.0-alpine3.19 as build-stage
|
|
|
|
|
2024-05-03 21:23:25 +02:00
|
|
|
WORKDIR /app
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# add files that describe which dependencies are required
|
2024-05-03 21:23:25 +02:00
|
|
|
COPY package*.json ./
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# install dependencies required to build the web application
|
2024-05-03 21:23:25 +02:00
|
|
|
RUN npm install
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# add resources required to build the web application
|
2024-05-03 21:23:25 +02:00
|
|
|
COPY . .
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# build the web application
|
2024-05-03 21:23:25 +02:00
|
|
|
RUN npm run build
|
|
|
|
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# PRODUCTION STAGE
|
|
|
|
FROM nginx:1.26.0-alpine3.19 as production-stage
|
|
|
|
|
2024-05-03 21:23:25 +02:00
|
|
|
# use custom error code websites instead
|
|
|
|
RUN rm -f /usr/share/nginx/html/50x.html
|
2024-05-03 23:15:21 +02:00
|
|
|
|
2024-05-03 21:23:25 +02:00
|
|
|
# update default.conf nginx file with necessary try_files statement
|
|
|
|
RUN rm -f /etc/nginx/conf.d/default.conf
|
2024-05-03 23:15:21 +02:00
|
|
|
COPY --chown=nginx:nginx ./default.conf /etc/nginx/conf.d/default.conf
|
|
|
|
|
|
|
|
# enable the nginx user to be able to launch the web application, so root is not required
|
|
|
|
RUN touch /var/run/nginx.pid && \
|
|
|
|
chown -R nginx:nginx /var/cache/nginx /var/run/nginx.pid
|
|
|
|
USER nginx
|
|
|
|
COPY --chown=nginx:nginx ./default.conf /etc/nginx/conf.d/default.conf
|
|
|
|
|
|
|
|
# add the previously built web application
|
|
|
|
COPY --chown=www-data:www-data --from=build-stage /app/dist /usr/share/nginx/html
|
|
|
|
|
2024-05-03 21:23:25 +02:00
|
|
|
EXPOSE 80
|
2024-05-03 23:15:21 +02:00
|
|
|
|
|
|
|
# check every minute whether the website is still locally reachable; if not, the docker process displays "unhealthy"
|
|
|
|
HEALTHCHECK --interval=1m CMD wget --no-verbose --tries=1 http://localhost:80 -q -O /dev/null || exit 1
|
|
|
|
|
|
|
|
# runs nginx in the foreground which means the docker container only runs as long as nginx is running (good practice)
|
2024-05-03 21:23:25 +02:00
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|