From 1050e3c48e02927ae9d0a941f28f52dd37ecc324 Mon Sep 17 00:00:00 2001 From: Jules van Rie Date: Wed, 29 May 2024 10:39:56 +0200 Subject: [PATCH 1/2] Use slim base image and remove not needed packages Simple changes to reduce overall image size and building and pushing time: - Use slim base image (-800Mb) - Comment out the packages that we don't really need (-300Mb) All together reduces the image from 1.37Gb to 0.27Gb and makes it faster to build. --- Dockerfile | 2 +- requirements.txt | 6 +++--- tests/Dockerfile.test | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce5bbb7..52e8091 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-bookworm +FROM python:3.10-slim-bookworm # Copy and install requirements COPY requirements.txt requirements.txt diff --git a/requirements.txt b/requirements.txt index ce96489..6378caf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # Some example packages -pandas -numpy -seaborn +# pandas +# numpy +# seaborn # API-related packages fastapi diff --git a/tests/Dockerfile.test b/tests/Dockerfile.test index c1bdd15..4a39c81 100644 --- a/tests/Dockerfile.test +++ b/tests/Dockerfile.test @@ -1,4 +1,4 @@ -FROM python:3.10-bookworm +FROM python:3.10-slim-bookworm # Copy and install requirements COPY requirements.txt requirements.txt From 18b32bba3e0a9f584369e03f3da471223b35beff Mon Sep 17 00:00:00 2001 From: Jules van Rie Date: Wed, 29 May 2024 10:44:44 +0200 Subject: [PATCH 2/2] Separate requirements for CI testing For the CI test, we install the full requirements in the github action. While the only thing we need is requests and pytest. Everything else is installed inside the container. So use a separate tests/requirements.txt. A bit analogous to the seperate Dockerfile.test. Advantage: cleaner + a faster CI flow. --- .github/workflows/python-ci.yml | 4 ++-- tests/requirements.txt | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/requirements.txt diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 9b8ff7b..8142826 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -9,7 +9,7 @@ on: jobs: build-and-run-pytest: - + runs-on: ubuntu-latest steps: @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip cython wheel - pip install -r requirements.txt + pip install -r tests/requirements.txt # 4. Build test image - name: Build test Docker image diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..541f56e --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,3 @@ +# Testing packages +requests +pytest