Skip to content

Commit

Permalink
feat(docker): Use jobs over workflow dependency
Browse files Browse the repository at this point in the history
Workflow dependencies relies on a single workflow,
which make build pipelines 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 is changed, but not
  publishing images on the registry.
- On push or workflow_dispatch, publishing to defined registry.

Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Sep 25, 2023
1 parent 1063b3e commit d80fb8f
Show file tree
Hide file tree
Showing 33 changed files with 465 additions and 1,276 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 }}


46 changes: 46 additions & 0 deletions .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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)
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("none")
91 changes: 0 additions & 91 deletions .github/workflows/docker-ort-android.yml

This file was deleted.

83 changes: 0 additions & 83 deletions .github/workflows/docker-ort-base.yml

This file was deleted.

Loading

0 comments on commit d80fb8f

Please sign in to comment.