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 b26c5bd commit f1e8aab
Show file tree
Hide file tree
Showing 9 changed files with 840 additions and 178 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)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

name: Docker runtime image
name: ORT Minimal Image

on:
workflow_dispatch:
Expand All @@ -25,7 +25,7 @@ on:
paths:
- '.versions'
- 'Dockerfile'
- '.github/workflows/docker-ort-runtime.yml'
- '.github/workflows/docker-ort-minimal.yml'
push:
tags:
- '*'
Expand Down Expand Up @@ -162,9 +162,9 @@ jobs:
GO_DEP_VERSION=${{ env.GO_DEP_VERSION }}
GO_VERSION=${{ env.GO_VERSION }}
runtime_image:
minimal_image:
needs: [ base_image, nodejs_image, python_image, rust_image, ruby_image, golang_image ]
name: Build ORT runtime image
name: Build ORT minimal image
runs-on: ubuntu-22.04
permissions:
contents: read
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
type=raw,value=${{ env.ORT_VERSION }}
type=ref,event=tag
- name: Build ORT runtime image
- name: Build ORT minimal image
uses: docker/build-push-action@v5
with:
context: .
Expand All @@ -228,3 +228,172 @@ jobs:
rust=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/rust:latest
ruby=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/ruby:latest
golang=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/golang:latest
android_image:
name: Android image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Android image
uses: ./.github/actions/ortdocker
with:
name: android
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.ANDROID_CMD_VERSION }}"
build-args: |
ANDROID_CMD_VERSION=${{ env.ANDROID_CMD_VERSION }}
dart_image:
name: Dart image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Dart image
uses: ./.github/actions/ortdocker
with:
name: dart
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.DART_VERSION }}"
build-args: |
DART_VERSION=${{ env.DART_VERSION }}
dotnet_image:
name: Dotnet image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Dotnet image
uses: ./.github/actions/ortdocker
with:
name: dotnet
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.DOTNET_VERSION }}"
build-args: |
DOTNET_VERSION=${{ env.DOTNET_VERSION }}
NUGET_INSPECTOR_VERSION=${{ env.NUGET_INSPECTOR_VERSION }}
haskell_image:
name: Haskell image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Haskell image
uses: ./.github/actions/ortdocker
with:
name: haskell
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.HASKELL_STACK_VERSION }}"
build-args: |
HASKELL_STACK_VERSION=${{ env.HASKELL_STACK_VERSION }}
scala_image:
name: Scala image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Scala image
uses: ./.github/actions/ortdocker
with:
name: scala
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.SBT_VERSION }}"
build-args: |
SBT_VERSION=${{ env.SBT_VERSION }}
swift_image:
name: Swift image
runs-on: ubuntu-22.04
steps:
- name: Checkout default branch
uses: actions/checkout@v4
- name: Set environment variables
run: |
cat .versions >> $GITHUB_ENV
- name: Build Swift image
uses: ./.github/actions/ortdocker
with:
name: swift
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.SWIFT_VERSION }}"
build-args: |
SWIFT_VERSION=${{ env.SWIFT_VERSION }}
ort_image:
name: Build ORT image
needs: [ minimal_image, android_image, dart_image, dotnet_image, haskell_image, scala_image, swift_image ]
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write

steps:
- name: Checkout default branch
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get ORT current version
run: |
ORT_VERSION=$(./gradlew -q properties --property version | sed -nr "s/version: (.+)/\1/p")
echo "ORT_VERSION=${ORT_VERSION}" >> $GITHUB_ENV
- name: Set up Docker build
uses: docker/setup-buildx-action@v3

- name: Login to GitHub container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract components metadata (tags, labels)
id: meta-ort
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-extended
tags: |
type=schedule,pattern={{date 'YYYYMMDD'}}
type=schedule,pattern=snapshot
type=pep440,pattern={{version}}
type=raw,value=${{ env.ORT_VERSION }}
type=ref,event=tag
- name: Build ORT extended runtime image
uses: docker/build-push-action@v5
with:
context: .
push: true
load: false
tags: |
${{ steps.meta-ort.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
ort-minimal=docker-image://${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal:${{ env.ORT_VERSION }}
android=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/android:latest
swift=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/swift:latest
scala=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/scala:latest
dart=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/dart:latest
dotnet=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/dotnet:latest
haskell=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/haskell:latest
Loading

0 comments on commit f1e8aab

Please sign in to comment.