Skip to content

Commit

Permalink
refactor(snackager): minimize final docker image as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Sep 16, 2023
1 parent 6fc54fb commit fd0de89
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions snackager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
ARG node_version

# --- Scoper - limit used workspaces for Snackager
# --- Scoper - Remove unused workspaces for Snackager
FROM node:${node_version}-alpine as scoper
WORKDIR /app

# Copy repository
COPY . .
# Prune repository and remove unused workspaces
RUN yarn global add [email protected] && turbo prune --docker --scope=snack-modules-packager
RUN apk --no-cache add jq && \
yarn global add turbo@$(jq --raw-output '.devDependencies.turbo' package.json) && \
turbo prune --docker --scope=snack-modules-packager


# --- Builder - Build Snackager
FROM node:${node_version}-alpine as builder
# --- Development - Prepare Snackager for development
FROM node:${node_version}-alpine as development
WORKDIR /app

# Copy "package.json"-only repository
Expand All @@ -30,8 +32,8 @@ WORKDIR /app/snackager
CMD ["yarn", "start"]


# --- Production - Run Snackager in production
FROM node:${node_version}-alpine
# --- Deploy - Prepare Snackager for production
FROM node:${node_version}-alpine as deploy
WORKDIR /app

# Install system dependencies
Expand All @@ -42,10 +44,24 @@ ARG APP_VERSION
ENV APP_VERSION ${APP_VERSION}

# Copy built repository
COPY --from=builder /app .
COPY --from=development /app .
# Ensure Snackager is build, has dependencies, and remove unnecessary dependencies from workspaces
RUN \
yarn build:snackager && \
yarn install --frozen-lockfile --production
# find . -path 'packages/*/node_modules/*' -delete


# --- Production - Run Snackager in production
FROM node:${node_version}-alpine
WORKDIR /app

# Prepare environment variables
ARG APP_VERSION
ENV APP_VERSION ${APP_VERSION}

# Ensure Snackager is built and only has production dependencies
RUN yarn build:snackager && yarn install --frozen-lockfile --production
# Copy deployment-ready repository
COPY --from=deploy /app .

# Setup Snackager for production
WORKDIR /app/snackager
Expand Down

0 comments on commit fd0de89

Please sign in to comment.