From 5cb67e10caa0632a004bb003267945ae63ead65c Mon Sep 17 00:00:00 2001 From: Jeremy Ho Date: Thu, 21 Dec 2023 16:51:49 -0800 Subject: [PATCH] Create explicit docker stage for app build Signed-off-by: Jeremy Ho --- Dockerfile | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b20c00f..cbfd7cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,25 @@ ARG APP_ROOT=/opt/app-root/src ARG BASE_IMAGE=docker.io/node:20.9.0-alpine +# +# Build the app +# +FROM ${BASE_IMAGE} as app + +ARG APP_ROOT +ENV NO_UPDATE_NOTIFIER=true + +# NPM Permission Fix +RUN mkdir -p /.npm +RUN chown -R 1001:0 /.npm + +# Build App +COPY app ${APP_ROOT} +RUN chown -R 1001:0 ${APP_ROOT} +USER 1001 +WORKDIR ${APP_ROOT} +RUN npm ci && npm run build + # # Build the frontend # @@ -34,15 +53,17 @@ RUN mkdir -p /.npm RUN chown -R 1001:0 /.npm # Install File Structure +COPY --from=app ${APP_ROOT}/sbin ${APP_ROOT}/sbin COPY --from=frontend ${APP_ROOT}/dist ${APP_ROOT}/dist COPY .git ${APP_ROOT}/.git -COPY app ${APP_ROOT} +COPY app/package.json ${APP_ROOT} +COPY app/package-lock.json ${APP_ROOT} WORKDIR ${APP_ROOT} # Install Application RUN chown -R 1001:0 ${APP_ROOT} USER 1001 -RUN npm ci --omit=dev && npm run build +RUN npm ci --omit=dev EXPOSE ${APP_PORT} CMD ["node", "./sbin/bin/www"]