reduce docker image size from 2gb to 300mb

This commit is contained in:
rubikscraft
2022-09-11 16:35:49 +02:00
parent 9792cedb94
commit 95fd0b9aa7
5 changed files with 55 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "es2017",
"target": "es2020",
"module": "es2020",
"lib": ["es2020"],

View File

@@ -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"

View File

@@ -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 ./

View File

@@ -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

View File

@@ -1,17 +0,0 @@
FROM node:18.8
# Sorry for the humongous docker container this generates
# Maybe I'll trim it down some day
ENV PICSUR_PRODUCTION=true
ADD . /picsur
WORKDIR /picsur
RUN yarn install --immutable
RUN yarn workspace picsur-shared build
RUN yarn workspace picsur-frontend build
RUN yarn workspace picsur-backend build
CMD yarn workspace picsur-backend start:prod