Skip to content

Commit

Permalink
reduce docker image size from 2gb to 300mb
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelFur committed Sep 11, 2022
1 parent 9792ced commit 95fd0b9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion shared/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "es2017",
"target": "es2020",
"module": "es2020",
"lib": ["es2020"],

Expand Down
8 changes: 7 additions & 1 deletion support/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ echo "Building version $VERSION"

docker buildx create --append --use --name picsur

docker buildx build \
--push \
-t "$PACKAGE_URL-stage1:$VERSION" \
-t "$PACKAGE_URL-stage1:latest" \
-f ./picsur-stage1.Dockerfile ..

docker buildx build \
--platform linux/amd64,linux/arm64 \
--push \
-t "$PACKAGE_URL:$VERSION" \
-t "$PACKAGE_URL:latest" \
-f ./picsur.Dockerfile ..
-f ./picsur-stage2.Dockerfile ..

echo "Done pushing $PACKAGE_URL:$VERSION"
25 changes: 25 additions & 0 deletions support/picsur-stage1.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This dockerfile only builds the javascript part of the project, so tsc and angular compilation

FROM node:18.8 AS BUILDER_STAGE1

SHELL ["/bin/bash", "-c"]

ADD . /picsur
WORKDIR /picsur

RUN yarn workspaces focus -A

RUN yarn workspace picsur-shared build
RUN yarn workspace picsur-frontend build
RUN yarn workspace picsur-backend build

RUN mkdir -p /trimmed

RUN cp -r --parents ./{package.json,yarn.lock,.yarnrc.yml,branding} /trimmed
RUN cp -r --parents ./{frontend,backend,shared}/{dist,package.json} /trimmed

FROM scratch

WORKDIR /picsur
ADD .yarn .yarn
COPY --from=BUILDER_STAGE1 /trimmed ./
22 changes: 22 additions & 0 deletions support/picsur-stage2.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This dockerfile than builds the production dependencies and the final image

# Always fetch amd64 image
FROM ghcr.io/rubikscraft/picsur-alpha-stage1:latest AS BUILDER_STAGE1

FROM node:18.8-alpine AS BUILDER_STAGE2

RUN apk add python3 build-base

WORKDIR /picsur
COPY --from=BUILDER_STAGE1 /picsur ./

RUN yarn workspaces focus -A --production

FROM node:18.8-alpine

ENV PICSUR_PRODUCTION=true

WORKDIR /picsur
COPY --from=BUILDER_STAGE2 /picsur ./

CMD yarn workspace picsur-backend start:prod
17 changes: 0 additions & 17 deletions support/picsur.Dockerfile

This file was deleted.

0 comments on commit 95fd0b9

Please sign in to comment.