Skip to content

Commit

Permalink
Merge pull request #3 from withlogicco/hotfix/use-matrix-build
Browse files Browse the repository at this point in the history
Use matrix for building all variants
  • Loading branch information
akalipetis authored Mar 23, 2022
2 parents 8a7a592 + dc3b44c commit b75a3ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
63 changes: 33 additions & 30 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,26 @@ on:
env:
POETRY_VERSION: 1.1.13
GHCR_IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/poetry
GHCR_IMAGE_tag: ${{ github.event.release.tag_name }}

jobs:
poetry:
name: Poetry version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}
build-args: |
POETRY_VERSION=${{ env.POETRY_VERSION }}
poetry_and_python:
name: Poetry with Python version
runs-on: ubuntu-latest
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
variant:
- buster
- slim
- alpine
include:
- python: "3.10"
is_default_python: true
- variant: buster
is_default_variant: true
steps:
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1
Expand All @@ -46,30 +35,44 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: ${{ env.POETRY_VERSION }}-python-${{ matrix.python }}
- name: "Python + Variant: ${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-${{ matrix.variant }}"
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-${{ matrix.variant }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
POETRY_VERSION=${{ env.POETRY_VERSION }}
PYTHON_VERSION=${{ matrix.python }}
VARIANT=${{ matrix.variant }}
- name: "Python + Default Variant: ${{ env.POETRY_VERSION }}-python-${{ matrix.python }}"
uses: docker/build-push-action@v2
if: matrix.is_default_variant
with:
push: true
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}-python-${{ matrix.python }}
build-args: |
POETRY_VERSION=${{ env.POETRY_VERSION }}
PYTHON_VERSION=${{ matrix.python }}
VARIANT=buster
- name: ${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-alpine
VARIANT=${{ matrix.variant }}
- name: "Default Python + Variant: ${{ env.POETRY_VERSION }}-${{ matrix.variant }}"
uses: docker/build-push-action@v2
if: matrix.is_default_python
with:
push: true
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-alpine
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}-${{ matrix.variant }}
build-args: |
POETRY_VERSION=${{ env.POETRY_VERSION }}
PYTHON_VERSION=${{ matrix.python }}
VARIANT=alpine
- name: ${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-slim
VARIANT=${{ matrix.variant }}
- name: "Default Python + Default Variant: ${{ env.POETRY_VERSION }}"
uses: docker/build-push-action@v2
if: matrix.is_default_python && matrix.is_default_variant
with:
push: true
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}-python-${{ matrix.python }}-slim
tags: ${{ env.GHCR_IMAGE_REPOSITORY }}:${{ env.POETRY_VERSION }}
build-args: |
POETRY_VERSION=${{ env.POETRY_VERSION }}
PYTHON_VERSION=${{ matrix.python }}
VARIANT=slim
VARIANT=${{ matrix.variant }}
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,33 @@ Docker Poetry is a Docker image for Python projects with dependencies managed by

At <a href="https://withlogic.co/">LOGIC</a> our go-to stack for web applications is; the latest LTS Django on the latest Python using Poetry as our dependency manager in Docker. [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) is a core principle for us, so a public Docker image with the right Python and Poetry version is an exceptional base for new projects.

## Usage
## Tags

First, pick the Poetry version you wish to use and optionally also a Python version and OS. The image format is the following:
For the simplest use case just pick your Poetry version:

```
ghcr.io/withlogicco/poetry:<poetry_version>-python-<python_version>-<os_variant>
ghcr.io/withlogicco/poetry:<poetry_version>
```

Then, copy your `pyproject.toml` and `poetry.lock` files in the working directory of the image (`/usr/src/app`) for optimal caching and run `poetry install`. For example:
This will use the default Python version (latest) and image variant (Buster). You can be more specific by picking either a Python version, image variant or both:

```dockerfile
FROM ghcr.io/withlogicco/poetry:1.1.13
- Python version: `ghcr.io/withlogicco/poetry:<poetry_version>-python-<python_version>`
- Image variant: `ghcr.io/withlogicco/poetry:<poetry_version>-<image_variant>`
- Python version and image variant: `ghcr.io/withlogicco/poetry:<poetry_version>-python-<python_version>-<image_variant>`

COPY pyproject.toml poetry.lock ./
RUN poetry install
### Examples

COPY ./ ./
```
- Poetry 1.1.13: `ghcr.io/withlogicco/poetry:1.1.13`
- Poetry 1.1.13 on Python 3.10: `ghcr.io/withlogicco/poetry:1.1.13-python-3.10`
- Poetry 1.1.13 on Buster: `ghcr.io/withlogicco/poetry:1.1.13-buster`
- Poetry 1.1.13 on Python 3.10 and Buster: `ghcr.io/withlogicco/poetry:1.1.13-python-3.10-buster`

### Pick a Python version and OS variant
## Usage

If you do the same, with Python 3.8 on Debian Slim you would do the following:
First, pick the image tag you wish to use. Then, copy your `pyproject.toml` and `poetry.lock` files in the working directory (`/usr/src/app`), for optimal caching and run `poetry install`. Example:

```dockerfile
FROM ghcr.io/withlogicco/poetry:1.1.13-python-3.8-slim
FROM ghcr.io/withlogicco/poetry:1.1.13

COPY pyproject.toml poetry.lock ./
RUN poetry install
Expand Down

0 comments on commit b75a3ec

Please sign in to comment.