From 1f50e3ff678af370ab2c1699edc776318f9a1455 Mon Sep 17 00:00:00 2001 From: Patryk Zawadzki Date: Tue, 31 Oct 2023 19:22:22 +0100 Subject: [PATCH] Use Poetry across the board and cache package managers in Docker This makes sure we consistently use poetry to install dependencies in all contexts. It also adds Docker cache mounts for package manager calls. --- .devcontainer/Dockerfile | 6 ++++-- .github/workflows/publish-containers.yml | 20 +++----------------- .github/workflows/pytest.yml | 2 -- CONTRIBUTING.md | 8 +------- Dockerfile | 6 ++++-- saleor/settings.py | 2 +- 6 files changed, 13 insertions(+), 31 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 441198e9033..0afa2e9850b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -22,5 +22,7 @@ RUN echo 'image/webp webp' >> /etc/mime.types RUN echo 'image/avif avif' >> /etc/mime.types WORKDIR /app -COPY requirements_dev.txt /tmp/pip-tmp/ -RUN pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements_dev.txt +RUN pip install poetry==1.5.0 +RUN poetry config virtualenvs.create false +COPY poetry.lock pyproject.toml /app/ +RUN poetry install --no-root diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml index da9cba0f805..599b9c1b716 100644 --- a/.github/workflows/publish-containers.yml +++ b/.github/workflows/publish-containers.yml @@ -44,20 +44,6 @@ jobs: id: buildx uses: docker/setup-buildx-action@v3 - - name: Cache Docker layers - uses: actions/cache@v3 - # This condition is a temporary fix until - # https://github.com/docker/buildx/issues/1044 is resolved, as it - # prevents usage of image registry. - # Due to limitation of local cache size we are skipping main branch and - # prioritize local cache for other branches e.g 3.x. - if: github.ref != 'refs/heads/main' - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('requirements_dev.txt') }} - restore-keys: | - ${{ runner.os }}-buildx- - - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -70,9 +56,9 @@ jobs: uses: docker/build-push-action@v5 with: builder: ${{ steps.buildx.outputs.name }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - context: ./ + cache-from: type=gha + cache-to: type=gha,mode=max + context: . labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 99284263be5..8bc0d7257e6 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -6,7 +6,6 @@ on: paths: - "**.py" - Dockerfile - - requirements_dev.txt - "saleor/**" - ".github/workflows/pytest.yml" - pyproject.toml @@ -18,7 +17,6 @@ on: paths: - "**.py" - Dockerfile - - requirements_dev.txt - "saleor/**" - ".github/workflows/pytest.yml" - pyproject.toml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1c56aa4294..c1247aa3f4d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,13 +34,7 @@ These files should be updated by running `poetry export --without-hashes -f requ ## Coding style Saleor uses various tools to maintain a common coding style and help with development. -To install all the development tools, run the following commands: - -```shell -python -m pip install -r requirements_dev.txt -``` - -or use `poetry`: +To install all the development tools, use [Poetry](https://python-poetry.org): ```shell poetry install diff --git a/Dockerfile b/Dockerfile index 8bdaeb14e83..ceb20f5d77d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,11 @@ RUN apt-get -y update \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies -COPY requirements_dev.txt /app/ WORKDIR /app -RUN pip install -r requirements_dev.txt +RUN --mount=type=cache,mode=0755,target=/root/.cache/pip pip install poetry==1.5.0 +RUN poetry config virtualenvs.create false +COPY poetry.lock pyproject.toml /app/ +RUN --mount=type=cache,mode=0755,target=/root/.cache/pypoetry poetry install --no-root ### Final image FROM python:3.9-slim diff --git a/saleor/settings.py b/saleor/settings.py index 09602f8d9be..c67362612ee 100644 --- a/saleor/settings.py +++ b/saleor/settings.py @@ -291,7 +291,7 @@ def get_url_from_env(name, *, schemes=None) -> Optional[str]: except ImportError as exc: msg = ( f"{exc} -- Install the missing dependencies by " - f"running `pip install -r requirements_dev.txt`" + f"running `poetry install --no-root`" ) warnings.warn(msg) else: