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)
This commit is contained in:
36
Dockerfile
36
Dockerfile
@@ -1,10 +1,9 @@
|
|||||||
############################################################
|
############################################################
|
||||||
# Build stage
|
# Build stage
|
||||||
############################################################
|
############################################################
|
||||||
FROM node:lts-alpine as build
|
FROM node:lts-alpine AS build
|
||||||
|
|
||||||
RUN apk update; \
|
RUN apk --no-cache add git
|
||||||
apk add git;
|
|
||||||
WORKDIR /tmp
|
WORKDIR /tmp
|
||||||
|
|
||||||
# Copy package.json first to benefit from layer caching
|
# Copy package.json first to benefit from layer caching
|
||||||
@@ -13,37 +12,32 @@ COPY package*.json ./
|
|||||||
# Copy src to have config files for install
|
# Copy src to have config files for install
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Clean npm cache; added to fix an issue with the install process
|
# Install without scripts
|
||||||
RUN npm cache clean --force
|
RUN npm ci --omit=dev --ignore-scripts \
|
||||||
|
# Copy production node_modules aside for later
|
||||||
# Install all dependencies
|
&& cp -R node_modules prod_node_modules \
|
||||||
RUN npm ci
|
# Install all dependencies
|
||||||
|
&& npm ci \
|
||||||
# Run build steps
|
# Run build steps
|
||||||
RUN npm run build
|
&& npm run build
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# Release stage
|
# Release stage
|
||||||
############################################################
|
############################################################
|
||||||
FROM node:lts-alpine as release
|
FROM node:lts-alpine AS release
|
||||||
|
|
||||||
RUN apk update; \
|
|
||||||
apk add git;
|
|
||||||
|
|
||||||
VOLUME /parse-server/cloud /parse-server/config
|
VOLUME /parse-server/cloud /parse-server/config
|
||||||
|
|
||||||
WORKDIR /parse-server
|
WORKDIR /parse-server
|
||||||
|
|
||||||
|
# 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 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 bin bin
|
COPY bin bin
|
||||||
COPY public_html public_html
|
COPY public_html public_html
|
||||||
COPY views views
|
COPY views views
|
||||||
COPY --from=build /tmp/lib lib
|
|
||||||
RUN mkdir -p logs && chown -R node: logs
|
RUN mkdir -p logs && chown -R node: logs
|
||||||
|
|
||||||
ENV PORT=1337
|
ENV PORT=1337
|
||||||
|
|||||||
Reference in New Issue
Block a user