aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2022-09-17 20:52:01 +0100
committerGravatar Chris Lovering <[email protected]>2022-09-17 20:54:58 +0100
commit6cd837dfe2c3d2b870190a0762d00c78a7e0ca7d (patch)
tree2e8fc7e48665dd813dcfd0557f67d8e59d0cc03b
parentInitial commit (diff)
Add a workflow to build base Python images with poetry
-rw-r--r--.github/workflows/build.yml54
-rw-r--r--Dockerfile20
2 files changed, 74 insertions, 0 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..98d2e61
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,54 @@
+name: Build
+
+on:
+ workflow_dispatch:
+ push:
+ branches:
+ - main
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ build:
+ strategy:
+ matrix:
+ python_version: [3.9-slim, 3.10-slim, 3-slim]
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ # The current version (v2) of Docker's build-push action uses
+ # buildx, which comes with BuildKit features that help us speed
+ # up our builds using additional cache features. Buildx also
+ # has a lot of other features that are not as relevant to us.
+ #
+ # See https://github.com/docker/build-push-action
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
+
+ - name: Login to Github Container Registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ # Build and push the container to the GitHub Container
+ # Repository. The container will be tagged as "latest"
+ # and with the short SHA of the commit.
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: .
+ file: ./Dockerfile
+ push: true
+ cache-from: type=registry,ref=ghcr.io/chrislovering/python-poetry-base:${{ matrix.python_version }}
+ cache-to: type=inline
+ tags: |
+ ghcr.io/chrislovering/python-poetry-base:${{ matrix.python_version }}
+ build-args: |
+ python_version=${{ matrix.python_version }}
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..eb2538c
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,20 @@
+ARG python_version=3.10
+
+FROM --platform=linux/amd64 python:$python_version
+
+# POETRY_VIRTUALENVS_IN_PROJECT is required to ensure in-projects venvs mounted from the host in dev
+# don't get prioritised by `poetry run`
+ENV POETRY_VERSION=1.2.0 \
+ POETRY_HOME="/opt/poetry/home" \
+ POETRY_CACHE_DIR="/opt/poetry/cache" \
+ POETRY_NO_INTERACTION=1 \
+ POETRY_VIRTUALENVS_IN_PROJECT=false
+
+ENV PATH="$POETRY_HOME/bin:$PATH"
+
+RUN apt-get update \
+ && apt-get -y upgrade \
+ && apt-get install --no-install-recommends -y curl \
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
+
+RUN curl -sSL https://install.python-poetry.org | python