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

[refactor] Utilize multistage builds to improve caching and compatibility #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sindre-nistad
Copy link
Collaborator

Why is this pull request needed?

Gives us smaller images, and reduces the risk for adding files which should not be included

What does this pull request change?

The main changes here are;

  • using multi-stage builds for better caching and smaller images
  • explicitly listing the files that should be included / "COPY"able into the containers

For the API, I moved the tests outside the src folder. That way, we do not include the tests in the finished image. Since we use multi-stage builds, we can install the necessary compilers for running on ARM. The compilers are not part of the "production" image, and we don't need to worry about them taking up more space in the image layers.

I also created a user (similar to what's done in nginx) so that we can run the tests without running the container as root.

When only installing the necessary packages, I noticed that click is not explicitly defined, so it wasn't included in site-packages. By explicitly listing it in pyproject.toml, that issue is resolved.

@sindre-nistad sindre-nistad requested a review from a team as a code owner February 14, 2025 09:12
The main changes here are;
* using multi-stage builds for better caching and smaller images
* explicitly listing the files that should be included / "COPY"able into the containers

For the API, I moved the tests outside the `src` folder.
That way, we do not include the tests in the finished image.
Since we use multi-stage builds, we can install the necessary compilers for running on ARM.
The compilers are not part of the "production" image, and we don't need to worry about them taking up more space in the image layers.

I also created a user (similar to what's done in `nginx`) so that we can run the tests without running the container as root.

When only installing the necessary packages, I noticed that `click` is not explicitly defined, so it wasn't included in `site-packages`.
By explicitly listing it in `pyproject.toml`, that issue is resolved.
@sindre-nistad sindre-nistad force-pushed the improve-container-images branch from 9235f95 to 0b56f52 Compare February 14, 2025 12:25
@sindre-nistad sindre-nistad self-assigned this Feb 14, 2025
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

Successfully merging this pull request may close these issues.

1 participant