-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(snackager): minimize final docker image as much as possible
- Loading branch information
Showing
1 changed file
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -42,10 +44,23 @@ 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 | ||
|