Skip to content

Commit

Permalink
Merge branch 'main' into Issue-7476
Browse files Browse the repository at this point in the history
Signed-off-by: mawl <[email protected]>
  • Loading branch information
mawl authored Sep 28, 2023
2 parents e6b8709 + 49bf674 commit 79991e5
Show file tree
Hide file tree
Showing 87 changed files with 4,219 additions and 877 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: "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@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 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 }}

- 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
50 changes: 50 additions & 0 deletions .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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

""" 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")
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")
203 changes: 203 additions & 0 deletions .github/workflows/docker-ort-runtime-ext.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# 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: Mega Docker extended image

on:
workflow_dispatch:
pull_request:
paths:
- '.versions'
- 'Dockerfile'
- 'Dockerfile-extended'
push:
branches:
- main
tags:
- '*'
workflow_run:
workflows:
- 'Mega Docker runtime image'
types:
- completed

env:
REGISTRY: ghcr.io

permissions: write-all

jobs:
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 }}
runtime_extended_image:
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
name: Build ORT extended image
needs: [ 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

- 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=raw,sha,enable=true,format=short
- name: Build ORT extended runtime image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile-extended
push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
load: false
tags: |
${{ steps.meta-ort.outputs.tags }}
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-extended:latest
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
ort=docker-image://${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:latest
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 79991e5

Please sign in to comment.