From d8b5e97293f11930b9b71ed2c19ab03d45525555 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Sat, 11 Mar 2023 15:37:29 -0800 Subject: [PATCH] Updates the Docker image to use a multistage build process --- Dockerfile | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a48cd2..87c1f38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,25 @@ -FROM nginx:alpine +FROM node:18-alpine3.17 as build-stage + +RUN set -eux \ + && mkdir -p /app \ + && mkdir -p /stylesheets \ + && mkdir -p /api \ + && mkdir -p /api/files + +COPY frontend/ /app + +WORKDIR /app +RUN set -eux \ + && npm ci \ + && npm run build + +COPY backend/ /api/ + +WORKDIR /api +RUN set -eux \ + && npm ci + +FROM nginx:alpine as final ARG PUID=1000 ARG PGID=1000 ARG TITLE="" @@ -6,23 +27,18 @@ ARG BASE_PATH="" ENV VITE_TITLE $TITLE ENV BASE_PATH $BASE_PATH USER root -RUN mkdir -p /app -RUN mkdir -p /stylesheets -RUN mkdir -p /api -RUN mkdir -p /api/files -RUN apk add --update nodejs npm -COPY frontend/ /app/ -RUN cd /app ; npm ci ; npm run build -RUN cp -R /app/dist/. /usr/share/nginx/html/ -COPY backend/ /api/ -RUN cd /api ; npm ci + +RUN set -eux \ + && apk add --no-cache nodejs npm + +COPY --from=build-stage --chown=$PUID:$PGID /app/dist/. /usr/share/nginx/html/ +COPY --from=build-stage --chown=$PUID:$PGID /api/ /api/ + COPY nginx.conf /etc/nginx/conf.d/ RUN [ $BASE_PATH != "" ] && { sed -i "s~BASE_PROXY~location BASE_PATH/ { proxy_pass http://localhost:8080/ }~g" /etc/nginx/conf.d/*.conf; } || { sed -i "s~BASE_PROXY~ ~g" /etc/nginx/conf.d/*.conf; } RUN sed -i "s~BASE_PATH~${BASE_PATH}~g" /etc/nginx/conf.d/*.conf -RUN chown -R $PUID:$PGID /app/dist/stylesheets -RUN chown -R $PUID:$PGID /app/dist/stylesheets/color-themes -RUN chown -R $PUID:$PGID /api/files -VOLUME /api/files + +VOLUME /api/files VOLUME /usr/share/nginx/html/stylesheets/ WORKDIR /api EXPOSE 8080