From 28cfb7bb2593dbe4e345289bc26859be0a7a714b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 24 Sep 2024 15:03:55 -0400 Subject: [PATCH] docker: add git revision to version during docker build Using a "local version identifier" per PEP 440, the version looks like: 1.3.0+d7abeb3 PEP for reference: https://peps.python.org/pep-0440/ This will help distinguish ETL builds from each other while we still build directly from git. --- .github/workflows/ci.yaml | 2 ++ .github/workflows/docker-hub.yaml | 4 +++- Dockerfile | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d69971fa..3c357d83 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -86,6 +86,8 @@ jobs: with: load: true # just build, no push tags: smartonfhir/cumulus-etl:latest + build-args: | + LOCAL_VERSION=${{ github.sha }} - name: Download NLP images run: | diff --git a/.github/workflows/docker-hub.yaml b/.github/workflows/docker-hub.yaml index 73e1ec22..ac647988 100644 --- a/.github/workflows/docker-hub.yaml +++ b/.github/workflows/docker-hub.yaml @@ -29,7 +29,7 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push image to Docker Hub - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: push: true platforms: | @@ -37,3 +37,5 @@ jobs: linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + LOCAL_VERSION=${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 26246a54..25a06c0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,14 @@ RUN pip3 install nltk RUN python3 -m nltk.downloader -d /usr/local/share/nltk_data averaged_perceptron_tagger COPY . /app + +# A local version is the trailing bit of a Python version after a plus sign, like 5.0+ubuntu1. +# We use it here mostly to inject a git commit sha when building from git. +ARG LOCAL_VERSION +RUN [ -z "$LOCAL_VERSION" ] || sed -i "s/\(__version__.*\)\"/\1+$LOCAL_VERSION\"/" /app/cumulus_etl/__init__.py +# Print the final version we're using +RUN grep __version__ /app/cumulus_etl/__init__.py + RUN --mount=type=cache,target=/root/.cache \ pip3 install /app RUN rm -r /app