Skip to content

Commit 40810b4

Browse files
authored
feat: Reduce Docker image size by improving stages (#8359)
BREAKING CHANGE: The Docker image does not contain the git dependency anymore; if you have been using git as a transitive dependency it now needs to be explicitly installed in your Docker file, for example with `RUN apk --no-cache add git` (#8359)
1 parent bd82d8e commit 40810b4

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

Dockerfile

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
############################################################
22
# Build stage
33
############################################################
4-
FROM node:lts-alpine as build
4+
FROM node:lts-alpine AS build
55

6-
RUN apk update; \
7-
apk add git;
6+
RUN apk --no-cache add git
87
WORKDIR /tmp
98

109
# Copy package.json first to benefit from layer caching
@@ -13,37 +12,32 @@ COPY package*.json ./
1312
# Copy src to have config files for install
1413
COPY . .
1514

16-
# Clean npm cache; added to fix an issue with the install process
17-
RUN npm cache clean --force
18-
19-
# Install all dependencies
20-
RUN npm ci
21-
22-
# Run build steps
23-
RUN npm run build
15+
# Install without scripts
16+
RUN npm ci --omit=dev --ignore-scripts \
17+
# Copy production node_modules aside for later
18+
&& cp -R node_modules prod_node_modules \
19+
# Install all dependencies
20+
&& npm ci \
21+
# Run build steps
22+
&& npm run build
2423

2524
############################################################
2625
# Release stage
2726
############################################################
28-
FROM node:lts-alpine as release
29-
30-
RUN apk update; \
31-
apk add git;
27+
FROM node:lts-alpine AS release
3228

3329
VOLUME /parse-server/cloud /parse-server/config
3430

3531
WORKDIR /parse-server
3632

37-
COPY package*.json ./
38-
39-
# Clean npm cache; added to fix an issue with the install process
40-
RUN npm cache clean --force
41-
RUN npm ci --production --ignore-scripts
33+
# Copy build stage folders
34+
COPY --from=build /tmp/prod_node_modules /parse-server/node_modules
35+
COPY --from=build /tmp/lib lib
4236

37+
COPY package*.json ./
4338
COPY bin bin
4439
COPY public_html public_html
4540
COPY views views
46-
COPY --from=build /tmp/lib lib
4741
RUN mkdir -p logs && chown -R node: logs
4842

4943
ENV PORT=1337

0 commit comments

Comments
 (0)