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

chore: docker builds optimizations #1795

Merged
merged 31 commits into from
Sep 13, 2023
Merged

Conversation

raducristianpopa
Copy link
Member

@raducristianpopa raducristianpopa commented Aug 28, 2023

Changes proposed in this pull request

  • Introduce multi-stage Docker builds to decrease image sizes.

Context

Current progress:

REPOSITORY                        TAG       IMAGE ID       CREATED          SIZE
rafiki-frontend                   latest    8dbaccf3fc7a   12 minutes ago   216MB
rafiki-mock-ase                   latest    fe5e820589f8   12 minutes ago   219MB
rafiki-backend                    latest    687f5d9e6eb7   13 minutes ago   231MB
rafiki-auth                       latest    733332ba4fc3   13 minutes ago   206MB
rafiki-postman-signatures         latest    b97b04b2feef   13 minutes ago   177MB
redis                             7         69bb36a0f47b   13 days ago      157MB
postgres                          15        ee56d70bcdf1   2 weeks ago      433MB
ghcr.io/tigerbeetle/tigerbeetle   0.13.57   34025e6f8272   7 weeks ago      20.2MB

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass
  • Postman collection updated

@netlify
Copy link

netlify bot commented Aug 28, 2023

Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit f5a0e05
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/65007296f296d90008ad64d5

@github-actions github-actions bot added pkg: backend Changes in the backend package. pkg: auth Changes in the GNAP auth package. labels Aug 28, 2023
@github-actions github-actions bot added pkg: frontend Changes in the frontend package. pkg: mock-ase labels Aug 28, 2023
Copy link
Member Author

@raducristianpopa raducristianpopa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon we can still make the image sizes much smaller, but this is a good start. All node images come with npm and yarn pre-installed.

localenv/mock-account-servicing-entity/Dockerfile Outdated Show resolved Hide resolved
Comment on lines +7 to +10
RUN apk add --no-cache \
python3 \
make \
g++
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node-gyp requirements.

RUN apt update
RUN apt install -y curl xz-utils python3 build-essential

# version in curl is not the version used. Dependent on the last command
RUN corepack enable
RUN corepack prepare pnpm@7.25.1 --activate
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason we are still using pnpm@v7 instead of v8?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we forgot to update it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried with pnpm v8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried with pnpm v8 when I was running into the httpbis-digest-headers issue. It should also work with v8 without any problems. As for the choice to stick with v7, I recall @mkurapov mentioning an edge case or an issue that was preventing us from upgrading to v8, but I'm not entirely sure about this.

@raducristianpopa raducristianpopa marked this pull request as ready for review August 29, 2023 06:22
@raducristianpopa
Copy link
Member Author

raducristianpopa commented Aug 30, 2023

https://github.com/interledger/rafiki/actions/runs/6021572573/job/16334677808?pr=1795#step:3:407

I'm currently running into some issues due to the httpbis-digest-headers library, which is neither published nor contains a dist/lib folder in its repository. This library is built dynamically upon installation (https://github.com/interledger/httpbis-digest-headers/blob/eb2e41c25cb6f2b8c610b74a853f36c6be8dbb4b/package.json#L11C8-L11C8). Our prod-deps stage, is set up to only install essential dependencies and exclude all devDependencies, which means we don't have TS available for building the library.

@sabineschaller
Copy link
Member

'm currently running into some issues due to the httpbis-digest-headers library, which is neither published nor contains a dist/lib folder in its repository. This library is built dynamically upon installation (https://github.com/interledger/httpbis-digest-headers/blob/eb2e41c25cb6f2b8c610b74a853f36c6be8dbb4b/package.json#L11C8-L11C8). Our prod-deps stage, is set up to only install essential dependencies and exclude all devDependencies, which means we don't have TS available for building the library.

We did publish the package, so we should just swap to using it: https://www.npmjs.com/package/httpbis-digest-headers

@raducristianpopa
Copy link
Member Author

We did publish the package, so we should just swap to using it: https://www.npmjs.com/package/httpbis-digest-headers

We also need to use the NPM registry for http-signature-utils (https://github.com/interledger/open-payments/blob/1379177f3cc3b74536905c162fd9f872a70b5f47/packages/http-signature-utils/package.json#L28) before removing

RUN pnpm add -g typescript

Do you want me to update the http-signature-utils library as well?

@sabineschaller
Copy link
Member

Do you want me to update the http-signature-utils library as well?

Yes please. Thank you!

sabineschaller
sabineschaller previously approved these changes Sep 7, 2023
Copy link
Member

@sabineschaller sabineschaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic! There is a lot of repetition across the dockerfiles. I don't know if we could somehow reduce that. But that was the reason I failed when trying to reduce the size so maybe we have to live with the repetition.

Thank you! ♥️

@raducristianpopa
Copy link
Member Author

httpbis-digest-headers issue - solved ✅.

Let me know if we should move to pnpm v8.

This reverts commit 24db14d.
@sabineschaller
Copy link
Member

Yeah, let's move to pnpm v8

@github-actions github-actions bot added the type: ci Changes to the CI label Sep 7, 2023
Comment on lines -8 to -9
with:
version: 7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed since I've added pnpm's version in the root package.json.

rafiki/package.json

Lines 7 to 11 in 4a72018

"engines": {
"pnpm": "^8.7.4",
"node": "18"
},
"packageManager": "pnpm@8.7.4",

sabineschaller
sabineschaller previously approved these changes Sep 12, 2023
Copy link
Member

@sabineschaller sabineschaller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful, works for me. You just need to resolve merge conflicts.

@raducristianpopa raducristianpopa merged commit 05eaadd into main Sep 13, 2023
24 checks passed
@raducristianpopa raducristianpopa deleted the rp--optimize-docker-builds branch September 13, 2023 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. pkg: mock-ase type: ci Changes to the CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants