From 3b44b86af4dd77fd8c938061ef90d773cd4b46df Mon Sep 17 00:00:00 2001 From: Laurent Vaylet Date: Fri, 17 May 2024 21:37:07 +0200 Subject: [PATCH] define the Python version used in production in two places only (#470) --- .github/workflows/build-and-push-to-gcr.yml | 6 +++--- .github/workflows/build-and-push-to-ghcr.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 2 +- Dockerfile | 2 +- Makefile | 3 +-- cloudbuild.yaml | 10 ++++------ 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-and-push-to-gcr.yml b/.github/workflows/build-and-push-to-gcr.yml index 9861f976..6eebc5c2 100644 --- a/.github/workflows/build-and-push-to-gcr.yml +++ b/.github/workflows/build-and-push-to-gcr.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '${{ vars.PYTHON_VERSION }}' architecture: 'x64' - name: Check release version @@ -44,7 +44,7 @@ jobs: GCR_PROJECT_ID: ${{ secrets.GCR_PROJECT_ID }} CLOUDBUILD_PROJECT_ID: ${{ secrets.CLOUDBUILD_PROJECT_ID }} VERSION: ${{ steps.check-tag.outputs.match == 'true' && steps.check-tag.outputs.version || github.event.pull_request.head.sha || github.sha }} - # TODO: Pass the Python version too, for the `PYTHON_VERSION` build argument of the Dockerfile. + PYTHON_VERSION: ${{ vars.PYTHON_VERSION }} - name: Build Docker container and publish on GCR [latest] run: make cloud_build || true @@ -53,4 +53,4 @@ jobs: GCR_PROJECT_ID: ${{ secrets.GCR_PROJECT_ID }} CLOUDBUILD_PROJECT_ID: ${{ secrets.CLOUDBUILD_PROJECT_ID }} VERSION: latest - # TODO: Pass the Python version too, for the `PYTHON_VERSION` build argument of the Dockerfile. + PYTHON_VERSION: ${{ vars.PYTHON_VERSION }} diff --git a/.github/workflows/build-and-push-to-ghcr.yml b/.github/workflows/build-and-push-to-ghcr.yml index 10667d8a..e8124228 100644 --- a/.github/workflows/build-and-push-to-ghcr.yml +++ b/.github/workflows/build-and-push-to-ghcr.yml @@ -54,4 +54,4 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | - PYTHON_VERSION=3.9 + PYTHON_VERSION=${{ vars.PYTHON_VERSION }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f1e7eeee..a0fc43e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.9" # same as Dockerfile + python-version: '${{ vars.PYTHON_VERSION }}' - name: Install dependencies run: make install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 57e0238a..57a9bce8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '${{ vars.PYTHON_VERSION }}' architecture: 'x64' - name: Run all tests diff --git a/Dockerfile b/Dockerfile index dc6e0c01..6ef11b45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG PYTHON_VERSION +ARG PYTHON_VERSION=3.9 FROM python:${PYTHON_VERSION}-alpine diff --git a/Makefile b/Makefile index 28b9cc9f..59641c0c 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,6 @@ docker_build: DOCKER_BUILDKIT=1 docker build \ -t slo-generator:latest \ - --build-arg PYTHON_VERSION=3.9 \ . # Build Docker image with Cloud Build @@ -143,7 +142,7 @@ cloud_build: gcloud builds submit \ --config=cloudbuild.yaml \ --project=${CLOUDBUILD_PROJECT_ID} \ - --substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION} + --substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION},_PYTHON_VERSION=${PYTHON_VERSION} # Cloud Run cloud_run: diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 0296e44f..c4a73531 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -18,13 +18,11 @@ steps: script: | docker build \ -t gcr.io/$_GCR_PROJECT_ID/slo-generator:${_VERSION} \ - --build-arg PYTHON_VERSION=3.9 \ + --build-arg PYTHON_VERSION=${_PYTHON_VERSION} \ . -substitutions: - _VERSION: latest -options: - automapSubstitutions: true - images: - gcr.io/$_GCR_PROJECT_ID/slo-generator:${_VERSION} + +options: + automapSubstitutions: true