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 d29a8c1
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 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,22 +32,35 @@ 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
RUN apk --no-cache add git openssh-client && npm install --global npm@^6
RUN apk --no-cache add git openssh-client && \
npm install --global npm@^6

# Prepare environment variables
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


# --- 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 d29a8c1

Please sign in to comment.