Skip to content

Commit

Permalink
feat(docker): Rename images to new defaults
Browse files Browse the repository at this point in the history
- ORT main image is now called ort alone. Is based on previous
  ort-extended image.
- A new image called ort-minimal is created based on original ort image.
- Language component images now have named version with hash addition
  to chek if contents of the image changed without changing core
  language.

Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Nov 2, 2023
1 parent 91647b2 commit 6f50f00
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 378 deletions.
140 changes: 71 additions & 69 deletions .github/actions/ortdocker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,83 @@ 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
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"
using: "composite"

steps:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
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
- 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
result=$(python ./.github/actions/ortdocker/check_image.py)
echo $result
echo "result=$result" >> $GITHUB_OUTPUT
result=$(python ./.github/actions/ortdocker/check_image.py)
echo $result
echo "result=$result" >> $GITHUB_OUTPUT
- name: Set up Docker build
if: steps.check_image.outputs.result != 'found'
uses: docker/setup-buildx-action@v3
- 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: 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 }}
- 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 image
if: steps.check_image.outputs.result != 'found'
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
- name: Build image
if: steps.check_image.outputs.result != 'found'
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
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}-{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)
202 changes: 0 additions & 202 deletions .github/workflows/docker-ort-runtime-ext.yml

This file was deleted.

Loading

0 comments on commit 6f50f00

Please sign in to comment.