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

Optimize docker build #125

Closed
kelvin-wong opened this issue Oct 22, 2021 · 4 comments
Closed

Optimize docker build #125

kelvin-wong opened this issue Oct 22, 2021 · 4 comments
Assignees

Comments

@kelvin-wong
Copy link
Collaborator

kelvin-wong commented Oct 22, 2021

Split from #109

Problem 3: Python images are slow to build

Cause of slow build

From the logs on building Docker images using skaffold. There are 2 main time-consuming processes. They are PNPM package installation and Poetry package installation.

Proposed optimization

Make use of PNPM workspace

PNPM could define dependencies for different packages in the monorepo. The way it works is similar to our implementation on subset.config.js. The main difference is that the PNPM workspace shares a single node_modules for all packages. It will save a lot of time on downloading packages/building packages.
https://pnpm.io/workspaces
@solomondefi-dev could look into this.

Extract base build stage for Python apps

The current base build stage for each Python apps is duplicated. We could extract it into another image and save some build time.
Another potential optimization could be a similar workflow like PNPM workspace as Poetry cache packages in .cache folder by default, the cached packages could be shared across different Python apps.

@kelvin-wong kelvin-wong self-assigned this Oct 22, 2021
@kelvin-wong kelvin-wong changed the title Optimize building for Python images Optimize docker build Oct 22, 2021
@kelvin-wong
Copy link
Collaborator Author

https://github.com/jacksmith15/poetry-workspace-plugin is one of the PoC of the python workspaces for poetry. It's just quite an early stage of the development but it basically shares packages/libs used in different projects in monorepo.

@kelvin-wong
Copy link
Collaborator Author

Some notes on slow docker build for Python apps.
Currently, pre-built binary packages (wheel) are built from glibc. But Alpine is based on musl and it will be regarded as a different platform for pip. Building from source is unavoidable for some packages until PEP656 is employed or a general platform package is available.

@solomondefi-dev
Copy link
Collaborator

That makes sense. I wonder if it's worth trying bullseye-slim instead of alpine, it seems like with Python, most of the benefits of alpine are lost.

@solomondefi-dev
Copy link
Collaborator

Closing this since the task is completed as originally defined. Will add an icebox issue for exploring other base images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants