Skip to content

feat: Reduce Docker image size by improving stages #8359

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 11 commits into from
Jan 9, 2023
36 changes: 15 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,37 +12,32 @@ 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 all dependencies
RUN npm ci

# Run build steps
RUN npm run build
# Install without scripts
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
############################################################
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 build stage folders
COPY --from=build /tmp/prod_node_modules /parse-server/node_modules
COPY --from=build /tmp/lib lib

COPY package*.json ./
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
Expand Down