Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/Dockerfile
# Multi-stage | # Multi-stage | ||||
# 1) Node image for building frontend assets | # 1) Node image for building frontend assets | ||||
# 2) nginx stage to serve frontend assets | # 2) nginx stage to serve frontend assets | ||||
# Stage 1 | # Stage 1 | ||||
FROM node:15-buster-slim AS builder | FROM node:15-buster-slim AS builder | ||||
# Install some dependencies before building | # Install some dependencies before building | ||||
RUN apt-get update && \ | RUN apt-get update && \ | ||||
apt-get upgrade -y && \ | apt-get upgrade -y && \ | ||||
apt-get install -y git && \ | apt-get install -y git && \ | ||||
apt-get install -y python | apt-get install -y python | ||||
WORKDIR /app | WORKDIR /app | ||||
# Copy all files from current directory to working dir in image | # Copy only the package files and install necessary dependencies. | ||||
# This reduces cache busting when source files are changed. | |||||
COPY package.json . | |||||
COPY package-lock.json . | |||||
RUN npm install | |||||
majcosta: you can go even further if you want, just `COPY package-lock.json` and `RUN npm ci` | |||||
jasonbcoxAuthorUnsubmitted Done Inline Actionsnpm ci still uses package.json for reference, as it will error out if package-lock.json does not match package.json I specifically put npm ci into its own diff in case it generates additional discussion on the impact of reproducible builds (see D9159) jasonbcox: `npm ci` still uses `package.json` for reference, as it will error out if `package-lock.json`… | |||||
# Copy the rest of the project files and build | |||||
COPY . . | COPY . . | ||||
# install node modules and build assets | RUN npm run build | ||||
RUN npm install && npm run build | |||||
# Stage 2 | # Stage 2 | ||||
FROM nginx | FROM nginx | ||||
COPY nginx.conf /etc/nginx/conf.d/default.conf | COPY nginx.conf /etc/nginx/conf.d/default.conf | ||||
# Set working directory to nginx asset directory | # Set working directory to nginx asset directory | ||||
# Copy static assets from builder stage | # Copy static assets from builder stage | ||||
COPY --from=builder /app/build /usr/share/nginx/html/ | COPY --from=builder /app/build /usr/share/nginx/html/ | ||||
EXPOSE 80 | EXPOSE 80 | ||||
# Containers run nginx with global directives and daemon off | # Containers run nginx with global directives and daemon off | ||||
ENTRYPOINT ["nginx", "-g", "daemon off;"] | ENTRYPOINT ["nginx", "-g", "daemon off;"] |
you can go even further if you want, just COPY package-lock.json and RUN npm ci