Skip to content

Commit

Permalink
fix(docker): Stop accidentally skipping component image builds
Browse files Browse the repository at this point in the history
In order to assemble the ORT docker image(s), the GitHub action first
builds the component images and then the main images using the
previously built component images.
Each component image build is skipped (for efficiency) if the image
with the needed tag already exists.

As tag, the version of the tooling of the particular ecosystem is used,
e.g. ghcr.io/oss-review-toolkit/python:3.11.5.

Using only the main tooling version as cache key is problematic, because
it leads to accidentally skipping of component image builds.
This may happen when any of the BUILD ARGS has changed.

Fix this by including a hash of the build args into the image tags.

Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Nov 9, 2023
1 parent bd4e1c7 commit a21905e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/actions/ortdocker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ runs:
INPUT_TOKEN: ${{ inputs.token }}
INPUT_NAME: ${{ inputs.name }}
INPUT_VERSION: ${{ inputs.version }}
BUILD_ARGS: ${{ inputs.build-args }}
run: |
pip install -q -U pip requests
Expand All @@ -80,8 +81,9 @@ runs:
with:
images: |
${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.name }}
tags:
tags: |
type=raw,value=${{ inputs.version }}
type=raw,value=${{ steps.check_image.outputs.result }}
- name: Build image
if: steps.check_image.outputs.result != 'found'
Expand Down
9 changes: 7 additions & 2 deletions .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

import hashlib
import os

import requests
Expand All @@ -26,7 +27,11 @@
token = os.getenv("INPUT_TOKEN")
org = os.getenv("GITHUB_REPOSITORY_OWNER")
name = os.getenv("INPUT_NAME")
version = os.getenv("INPUT_VERSION")
base_version = os.getenv("INPUT_VERSION")
unique_id = hashlib.sha256(os.getenv("BUILD_ARGS").encode()).hexdigest()

# We base the version on the base_version and the unique_id
version = f"{base_version}-sha.{unique_id[:8]}"

url = f"https://api.github.com/orgs/{org}/packages/container/ort%2F{name}/versions"

Expand All @@ -47,4 +52,4 @@
if version in versions:
print("found")
else:
print("none")
print(version)

0 comments on commit a21905e

Please sign in to comment.