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

feat(docker): reduce image size #363

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jonperron
Copy link
Contributor

@jonperron jonperron commented Dec 20, 2024

Fix for #322

Changes

First commit: Add a .dockerignore file which allows not to take useless folders and files in the docker image.

Allow to reduce the image size from 596 MB to 524 MB.

REPOSITORY                                        TAG               IMAGE ID       CREATED          SIZE
boavizta/boaviztapi                               1.3.7             3f6ba5cfaf75   5 seconds ago    524MB
<none>                                            <none>            ef9616799172   5 hours ago      596MB

Second commit: Write Dockerfile in order to reduce amount of copied files. Also add function in main.py to find location of pyproject.toml so it does not break local uvicorn and docker run executions.
Allow to reduce the image size to 460 MB.

REPOSITORY                                        TAG               IMAGE ID       CREATED          SIZE
boavizta/boaviztapi                               1.3.7             d18abd68b352   5 minutes ago    460MB

Tests

Tested after creating a new build using make docker-build

docker run -p 5000:5000/tcp boavizta/boaviztapi:`poetry version -s`
INFO:     Started server process [1]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)

Tested using uvicorn

uvicorn boaviztapi.main:app --host=localhost --port 5000
INFO:     Started server process [1133308]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:5000 (Press CTRL+C to quit)

* Rework dockerfile to reduce amount of copied files
* Add function to check location of pyproject.toml
@jonperron jonperron changed the title feat(docker): add dockerignore file feat(docker): reduce image size Dec 21, 2024
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