Skip to content

Commit

Permalink
Merge pull request #14567 from saleor/use-poetry-and-cache-package-ma…
Browse files Browse the repository at this point in the history
…nagers

Use Poetry across the board and cache package managers in Docker
  • Loading branch information
patrys committed Nov 3, 2023
2 parents 0087ab3 + 1f50e3f commit 2dec828
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 3 additions & 17 deletions .github/workflows/publish-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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' }}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
paths:
- "**.py"
- Dockerfile
- requirements_dev.txt
- "saleor/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
Expand All @@ -18,7 +17,6 @@ on:
paths:
- "**.py"
- Dockerfile
- requirements_dev.txt
- "saleor/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
Expand Down
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion saleor/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2dec828

Please sign in to comment.