template-fastapi-react icon indicating copy to clipboard operation
template-fastapi-react copied to clipboard

refactor: utilize multistage builds to improve caching and compatibility

Open sindre-nistad opened this issue 9 months ago • 0 comments

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 avatar Feb 14 '25 09:02 sindre-nistad