From 55c0fb85a33a960615a723a4c93dd5106bc12496 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Thu, 22 Dec 2022 23:14:26 -0500 Subject: [PATCH 1/6] feat: Reduce docker image size by improving stages --- Dockerfile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index a351d090d1..ce5b0faeb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ ############################################################ # Build stage ############################################################ -FROM node:lts-alpine as build +FROM node:lts-alpine AS build -RUN apk update; \ - apk add git; +RUN apk --no-cache add git WORKDIR /tmp # Copy package.json first to benefit from layer caching @@ -16,6 +15,12 @@ COPY . . # Clean npm cache; added to fix an issue with the install process RUN npm cache clean --force +# Install without scripts +RUN npm ci --production --ignore-scripts + +# Copy production node_modules aside for later +RUN cp -R node_modules prod_node_modules + # Install all dependencies RUN npm ci @@ -25,20 +30,15 @@ RUN npm run build ############################################################ # Release stage ############################################################ -FROM node:lts-alpine as release - -RUN apk update; \ - apk add git; +FROM node:lts-alpine AS release VOLUME /parse-server/cloud /parse-server/config WORKDIR /parse-server -COPY package*.json ./ - -# Clean npm cache; added to fix an issue with the install process -RUN npm cache clean --force -RUN npm ci --production --ignore-scripts +# Copy production node_modules +COPY --from=build /tmp/prod_node_modules /parse-server/node_modules +COPY --from=build /tmp/package*.json /parse-server/ COPY bin bin COPY public_html public_html From 390fb379bd8f351ce1340f4fa01da4672874fa59 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Fri, 23 Dec 2022 00:34:16 -0500 Subject: [PATCH 2/6] rearrange copies --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce5b0faeb1..a29b60ae0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,14 +36,14 @@ VOLUME /parse-server/cloud /parse-server/config WORKDIR /parse-server -# Copy production node_modules +# Copy build stage folders COPY --from=build /tmp/prod_node_modules /parse-server/node_modules COPY --from=build /tmp/package*.json /parse-server/ +COPY --from=build /tmp/lib lib COPY bin bin COPY public_html public_html COPY views views -COPY --from=build /tmp/lib lib RUN mkdir -p logs && chown -R node: logs ENV PORT=1337 From 88bd97bfa842a603c2c445e8e52b2931a7a58fe5 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Fri, 23 Dec 2022 00:51:13 -0500 Subject: [PATCH 3/6] fix production warning in docker build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a29b60ae0e..22f24e21d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY . . RUN npm cache clean --force # Install without scripts -RUN npm ci --production --ignore-scripts +RUN npm ci --omit=dev --ignore-scripts # Copy production node_modules aside for later RUN cp -R node_modules prod_node_modules From 3f8cb3c76078ff22976ff076c86af86670990942 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sun, 25 Dec 2022 19:07:29 -0500 Subject: [PATCH 4/6] Remove unnecessary cache clean --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 22f24e21d3..3ae738a7bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY package*.json ./ COPY . . # Clean npm cache; added to fix an issue with the install process -RUN npm cache clean --force +#RUN npm cache clean --force # Install without scripts RUN npm ci --omit=dev --ignore-scripts From 9802ceecee2fa2a924bf5aed958236ea0db40fbb Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sun, 25 Dec 2022 21:48:15 -0500 Subject: [PATCH 5/6] nit --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3ae738a7bc..fa6c013354 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,6 @@ COPY package*.json ./ # Copy src to have config files for install COPY . . -# Clean npm cache; added to fix an issue with the install process -#RUN npm cache clean --force - # Install without scripts RUN npm ci --omit=dev --ignore-scripts From b53e9284831ae6d3816b98ebf2cfc6a3d373143d Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Fri, 30 Dec 2022 10:37:54 -0500 Subject: [PATCH 6/6] consolidate runs in Dockerfile --- Dockerfile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index fa6c013354..413a9bd279 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,16 +13,13 @@ COPY package*.json ./ COPY . . # Install without scripts -RUN npm ci --omit=dev --ignore-scripts - -# Copy production node_modules aside for later -RUN cp -R node_modules prod_node_modules - -# Install all dependencies -RUN npm ci - -# Run build steps -RUN npm run build +RUN npm ci --omit=dev --ignore-scripts \ + # Copy production node_modules aside for later + && cp -R node_modules prod_node_modules \ + # Install all dependencies + && npm ci \ + # Run build steps + && npm run build ############################################################ # Release stage @@ -35,9 +32,9 @@ WORKDIR /parse-server # Copy build stage folders COPY --from=build /tmp/prod_node_modules /parse-server/node_modules -COPY --from=build /tmp/package*.json /parse-server/ COPY --from=build /tmp/lib lib +COPY package*.json ./ COPY bin bin COPY public_html public_html COPY views views