mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-10-26 06:56:06 +01:00
reduce docker image size from 2gb to 300mb
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"target": "es2020",
|
||||
"module": "es2020",
|
||||
"lib": ["es2020"],
|
||||
|
||||
|
||||
@@ -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
support/picsur-stage1.Dockerfile
Normal file
25
support/picsur-stage1.Dockerfile
Normal 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 ./
|
||||
22
support/picsur-stage2.Dockerfile
Normal file
22
support/picsur-stage2.Dockerfile
Normal 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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user