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

Optimise Docker image #148

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

Optimise Docker image #148

wants to merge 1 commit into from

Conversation

fmrsabino
Copy link
Contributor

  • The Docker file now uses a multistage build setup which is split into two different stages:
    • builder stage
    • final/production stage
  • The builder stage uses the requirements.txt to download and install the required dependencies for the project.
    • This stage needs gcc and libpq-dev to build the dependencies of the project
    • This stage removed the following dependencies: build-essential, git, libssl-dev as they are not required.
  • The final/production stage uses the dependencies that were built in the builder stage by copying those to the respective local folders of the new final image.
    • This stage copies all the contents of the project into the /app folder.
    • Additionally, it also installs libpq-dev as this is a required runtime dependency.

Other considerations:

  • The setting PYTHONDONTWRITEBYTECODE was considered. This would tell Python to not create pyc files which would save around 6MB. However, in a multiprocess container (with Gunicorn), each process might need to incur on generating that bytecode again. Using more storage in this case seems therefore, more appropriate.

- The Docker file now uses a multistage build setup which is split into two different stages:
  * `builder` stage
  * final/production stage
- The `builder` stage uses the `requirements.txt` to download and install the required dependencies for the project.
  * This stage needs `gcc` and `libpq-dev` to build the dependencies of the project
  * This stage removed the following dependencies: `build-essential`, `git`, `libssl-dev` as they are not required.
- The final/production stage uses the dependencies that were built in the `builder` stage by copying those to the respective local folders of the new final image.
  * This stage copies all the contents of the project into the `/app` folder.
  * Additionally, it also installs `libpq-dev` as this is a required runtime dependency.

Other considerations:
- The setting `PYTHONDONTWRITEBYTECODE` was considered. This would tell Python to not create `pyc` files which would save around 6MB. However, in a multiprocess container (with Gunicorn), each process might need to incur on generating that bytecode again. Using more storage in this case seems therefore, more appropriate.
@fmrsabino fmrsabino self-assigned this Jun 18, 2024
@fmrsabino fmrsabino requested a review from a team as a code owner June 18, 2024 14:33
@coveralls
Copy link

coveralls commented Jun 18, 2024

Pull Request Test Coverage Report for Build 9567035724

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 91.659%

Totals Coverage Status
Change from base Build 9564485126: 0.0%
Covered Lines: 2055
Relevant Lines: 2242

💛 - Coveralls

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.

2 participants