From 443a8b90893791ba6a1da4f1fbdacfafd462eafd Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Tue, 16 Apr 2024 16:29:33 +0200 Subject: [PATCH] ci(github): Remove the unused `ortdocker` action Signed-off-by: Martin Nonnenmacher --- .github/actions/ortdocker/action.yml | 123 ----------------------- .github/actions/ortdocker/check_image.py | 63 ------------ 2 files changed, 186 deletions(-) delete mode 100644 .github/actions/ortdocker/action.yml delete mode 100644 .github/actions/ortdocker/check_image.py diff --git a/.github/actions/ortdocker/action.yml b/.github/actions/ortdocker/action.yml deleted file mode 100644 index b351c07883362..0000000000000 --- a/.github/actions/ortdocker/action.yml +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (C) 2023 The ORT Project Authors (see ) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# License-Filename: LICENSE - -name: "ORT Docker image" -description: "Check and create Docker image for ORT components" -author: "The ORT Project Authors" - -inputs: - registry: - description: "GitHub container registry" - default: "ghcr.io" - token: - description: "GitHub token" - required: true - name: - description: "Image name" - required: true - version: - description: "Image version" - required: true - build-args: - description: "List of build-time variables" - required: false - -runs: - using: "composite" - - steps: - - name: Install Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - cache: 'pip' - - - name: Check if Docker image tag exists - id: check_image - shell: bash - env: - INPUT_REGISTRY: ${{ inputs.registry }} - INPUT_TOKEN: ${{ inputs.token }} - INPUT_NAME: ${{ inputs.name }} - INPUT_VERSION: ${{ inputs.version }} - BUILD_ARGS: ${{ inputs.build-args }} - run: | - pip install -q -U pip requests - - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then - INVALIDATE_CACHE=1 - export INVALIDATE_CACHE - fi - result=$(python ./.github/actions/ortdocker/check_image.py) - echo "result=$result" >> $GITHUB_OUTPUT - - - name: Set up Docker build - if: steps.check_image.outputs.result != 'found' - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub container registry - if: steps.check_image.outputs.result != 'found' - uses: docker/login-action@v3 - with: - registry: ${{ inputs.registry }} - username: ${{ github.actor }} - password: ${{ inputs.token }} - - - name: Extract components metadata (tags, labels) - if: steps.check_image.outputs.result != 'found' - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.name }} - tags: | - type=raw,value=${{ inputs.version }} - type=raw,value=${{ steps.check_image.outputs.result }} - - - name: Build base image - if: > - steps.check_image.outputs.result != 'found' && - inputs.name == 'base' - uses: docker/build-push-action@v5 - with: - context: . - target: ${{ inputs.name }} - push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} - load: false - build-args: ${{ inputs.build-args }} - tags: | - ${{ steps.meta.outputs.tags }} - ${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.name }}:latest - labels: ${{ steps.meta.outputs.labels }} - - - name: Build image - if: > - steps.check_image.outputs.result != 'found' && - inputs.name != 'base' - uses: docker/build-push-action@v5 - with: - context: . - target: ${{ inputs.name }} - push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} - load: false - build-args: ${{ inputs.build-args }} - tags: | - ${{ steps.meta.outputs.tags }} - ${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.name }}:latest - labels: ${{ steps.meta.outputs.labels }} - build-contexts: | - base=docker-image://${{ inputs.registry }}/${{ github.repository }}/base:latest diff --git a/.github/actions/ortdocker/check_image.py b/.github/actions/ortdocker/check_image.py deleted file mode 100644 index 21be591974f9a..0000000000000 --- a/.github/actions/ortdocker/check_image.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (C) 2023 The ORT Project Authors (see ) -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# License-Filename: LICENSE - -import hashlib -import os -import sys - -import requests - -""" Use current GitHub API to check if a container image with the - given name and version exists. -""" - -token = os.getenv("INPUT_TOKEN") -org = os.getenv("GITHUB_REPOSITORY_OWNER") -name = os.getenv("INPUT_NAME") -base_version = os.getenv("INPUT_VERSION") -build_args = os.getenv("BUILD_ARGS") -invalidate_cache = True if os.getenv("INVALIDATE_CACHE") else False -unique_id = hashlib.sha256(build_args.encode()).hexdigest() if build_args else "uniq" - -# We base the version on the base_version and the unique_id -version = f"{base_version}-sha.{unique_id[:8]}" - -# In case of need invalidate the cache from images we just return the version -if invalidate_cache: - print(version) - sys.exit(0) - -url = f"https://api.github.com/orgs/{org}/packages/container/ort%2F{name}/versions" - -headers = { - "Accept": "application/vnd.github+json", - "Authorization": f"Bearer {token}", -} -response = requests.get(url, headers=headers) -if response.status_code == 404: - print("none") -else: - versions = [ - item - for sublist in [v["metadata"]["container"]["tags"] for v in response.json()] - if sublist - for item in sublist - ] - if version in versions: - print("found") - else: - print(version)