Skip to content

Commit

Permalink
feat(build): allow caching node_modules in docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed May 19, 2023
1 parent 44147a4 commit 30f20aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ FROM node:18 as builder
ARG BUILD_BRANCH_ENV_PREFIX

WORKDIR /app
# Install dependencies separately to cache them
# https://stackoverflow.com/a/43190345/4936667
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
# Two steps to copy .env.branch only if no .env exists
# (it is needed to support docker-compose with local env and kubernetes prod build at the same time)
# 1. just copy
COPY .env${BUILD_BRANCH_ENV_PREFIX} .env
# 2. overwrite .env back if it exists (dummy package.json to ensure COPY not to fail)
COPY package.json .en[v] ./
RUN npm ci && npm run production
RUN npm run production

FROM nginx:stable-alpine
RUN rm -rf /usr/share/nginx/html
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
build:
context: ./
dockerfile: .docker/Dockerfile
args:


ports:
- ${WEB_PORT_FOR_DOCKER_COMPOSE}:80
- ${WEB_PORT_FOR_DOCKER_COMPOSE}:80

0 comments on commit 30f20aa

Please sign in to comment.