Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
feat(docker): improve yarn cache
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Jan 31, 2022
1 parent dd63cb2 commit 6c3a0da
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
ARG NODE_VERSION=16-alpine

# Install dependencies only when needed
FROM node:16-alpine AS deps
FROM node:$NODE_VERSION AS prepare
RUN apk add --no-cache libc6-compat=1.2.2-r7
WORKDIR /app
COPY package.json yarn.lock ./

# Keep yarn install cache when bumping version and dependencies still the sames
RUN node -e " \
const package = JSON.parse(fs.readFileSync('/app/package.json')); \
const packageZero = { ...package, version: '0.0.0' }; \
fs.writeFileSync('/app/package.json', JSON.stringify(packageZero));"

FROM node:$NODE_VERSION as deps
WORKDIR /app
COPY --from=prepare /app/package.json /app/yarn.lock ./
RUN yarn install --frozen-lockfile

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
FROM node:$NODE_VERSION AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
Expand Down

0 comments on commit 6c3a0da

Please sign in to comment.