Skip to content

Commit

Permalink
feat(simplify): Use jobs instead of workflow dependencies
Browse files Browse the repository at this point in the history
Workflow dependencies relies on a single dependency, which make build
pipeline for multiple docker containers complex and most of the time
erratic.

Move to single jobs dependency based with a internal action to check and
build images if needed improve the logic of the process and allow to
visually see the running pipeline.

The pipeline will run on following cases:
- On pull_request if .versions file was touches, but not publishing
  images on the registry.
- On push or workflow_dispatch, publishing to ghcr.io registry.

Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Sep 16, 2023
1 parent 302fd9f commit d3a639c
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 577 deletions.
100 changes: 100 additions & 0 deletions .github/actions/ortdocker/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# 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: "Helio Chissini de Castro <[email protected]>"

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@v4
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 }}
run: |
pip install -q -U pip requests
result=$(python ./.github/actions/ortdocker/check_image.py)
echo $result
echo "result=$result" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
if: steps.check_image.outputs.result != 'found'
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
if: steps.check_image.outputs.result != 'found'
uses: docker/login-action@v2
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ inputs.token }}

- name: Extract components metadata (tags, labels) for base image
if: steps.check_image.outputs.result != 'found'
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.name }}
tags:
type=raw,value=${{ inputs.version }}

- name: Build ORT Base container
if: steps.check_image.outputs.result != 'found'
uses: docker/build-push-action@v4
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 }}


45 changes: 45 additions & 0 deletions .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
#
# 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 os

import requests

token = os.getenv("INPUT_TOKEN")
org = os.getenv("GITHUB_REPOSITORY_OWNER")
name = os.getenv("INPUT_NAME")
version = os.getenv("INPUT_VERSION")

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)
response.raise_for_status()

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("none")
83 changes: 0 additions & 83 deletions .github/workflows/docker-ort-base.yml

This file was deleted.

92 changes: 0 additions & 92 deletions .github/workflows/docker-ort-golang.yml

This file was deleted.

Loading

0 comments on commit d3a639c

Please sign in to comment.