Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize docker from 1.7 GB to 314 MB #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,45 @@
FROM node:18
# Base for final image
FROM debian:bookworm-slim as node-minimal

env BASE_URL= \
RUN apt update && \
apt -y dist-upgrade && \
apt -y install nodejs && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/*

# Temporary image to build app
FROM debian:bookworm-slim as builder

RUN apt update && \
apt -y dist-upgrade && \
apt -y install nodejs npm && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

# COPIES
# 1. Files
COPY package*.json .njsscan *.js *.json *.mjs LICENSE ./

# 2. Directories
COPY .husky ./.husky/
COPY packages ./packages/
COPY landing /usr/src/app/landing
#COPY node_modules ./node_modules/

# Build and clean

RUN npm install && npm run build && \
rm -rf node_modules */*/node_modules && \
npm install --production --ignore-scripts && \
npm cache clean --force

FROM node-minimal as tom-server

ENV BASE_URL= \
CRON_SERVICE= \
CROWDSEC_URI= \
CROWDSEC_KEY= \
Expand Down Expand Up @@ -54,15 +93,9 @@ env BASE_URL= \
RATE_LIMITING_NB_REQUESTS= \
TRUSTED_PROXIES=

RUN apt update && apt -y dist-upgrade
COPY --from=1 /usr/src/app /usr/src/app/

WORKDIR /usr/src/app

COPY package*.json ./

COPY . .

RUN npm install && npm run build && npm cache clean --force

EXPOSE 3000
CMD [ "node", "/usr/src/app/server.mjs" ]
63 changes: 44 additions & 19 deletions packages/federated-identity-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
FROM node:18
# Base for final image
FROM debian:bookworm-slim as node-minimal

RUN apt update && \
apt -y dist-upgrade && \
apt -y install nodejs && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/*

# Temporary image to build app
FROM debian:bookworm-slim as builder

RUN apt update && \
apt -y dist-upgrade && \
apt -y install nodejs npm && \
apt autoremove -y && \
apt clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

# COPIES
COPY ./packages/federated-identity-service/server.mjs .
COPY ./packages/crypto ./packages/crypto
COPY ./packages/logger ./packages/logger
COPY ./packages/matrix-resolve ./packages/matrix-resolve
COPY ./packages/matrix-identity-server ./packages/matrix-identity-server
COPY ./packages/config-parser ./packages/config-parser
COPY ./packages/federated-identity-service ./packages/federated-identity-service
COPY .husky .husky
COPY lerna.json ./
COPY tsconfig-build.json ./
COPY rollup-template.js ./
COPY package*.json ./

RUN npm install && npm run build && \
rm -rf node_modules */*/node_modules && \
npm install --production --ignore-scripts && \
npm cache clean --force

FROM node-minimal as federation-server

ENV BASE_URL= \
CRON_SERVICE= \
Expand All @@ -24,25 +65,9 @@ ENV BASE_URL= \
TRUST_X_FORWARDED_FOR= \
TRUSTED_SERVERS_ADDRESSES=

RUN apt update && apt -y dist-upgrade
COPY --from=1 /usr/src/app /usr/src/app/

WORKDIR /usr/src/app

COPY ./packages/federated-identity-service/server.mjs .

COPY ./packages/crypto ./packages/crypto
COPY ./packages/logger ./packages/logger
COPY ./packages/matrix-resolve ./packages/matrix-resolve
COPY ./packages/matrix-identity-server ./packages/matrix-identity-server
COPY ./packages/config-parser ./packages/config-parser
COPY ./packages/federated-identity-service ./packages/federated-identity-service
COPY .husky .husky
COPY lerna.json ./
COPY tsconfig-build.json ./
COPY rollup-template.js ./
COPY package*.json ./

RUN npm install && npm run build && npm cache clean --force

EXPOSE 3000
CMD [ "node", "/usr/src/app/server.mjs" ]
CMD [ "node", "/usr/src/app/server.mjs" ]
Loading