Skip to content

Commit

Permalink
feat(docker): Improve build process
Browse files Browse the repository at this point in the history
Workflow now use new external action to improve control over how images
are handled on ghcr docker registry.

Ort version is extracted in an independent job, reused alongside the
parallel jobs.

Functional tests will be executed if the entire chain is sucessfully
executed. For pull_request tests, the build image is loaded in current
build context, instead of be pushed to registry.

Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Mar 10, 2024
1 parent 5b60a74 commit b787c85
Showing 1 changed file with 67 additions and 59 deletions.
126 changes: 67 additions & 59 deletions .github/workflows/docker-ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build base image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: base
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -68,7 +68,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build NodeJS image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: nodejs
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -90,7 +90,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Python image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: python
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -116,7 +116,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Rust image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: rust
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -135,7 +135,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Ruby image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: ruby
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -155,7 +155,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Golang image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: golang
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -175,7 +175,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Android image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: android
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -194,7 +194,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Dart image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: dart
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -213,7 +213,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Dotnet image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: dotnet
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -233,7 +233,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Haskell image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: haskell
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -252,7 +252,7 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Scala image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: scala
token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -271,19 +271,36 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- name: Build Swift image
uses: ./.github/actions/ortdocker
uses: heliocastro/docker-build-control@v1
with:
name: swift
token: ${{ secrets.GITHUB_TOKEN }}
version: "${{ env.SWIFT_VERSION }}"
build-args: |
SWIFT_VERSION=${{ env.SWIFT_VERSION }}
ort_version:
name: Get Ort Version
runs-on: ubuntu-22.04
outputs:
ort_version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout default branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: get_version
run: |
ORT_VERSION=$(./gradlew -q properties --property version | sed -nr "s/version: (.+)/\1/p")
echo "version=${ORT_VERSION}" >> $GITHUB_OUTPUT
shell: bash


# Minimal Runtime ORT image
# -------------------------
minimal_image:
needs:
[ base_image, nodejs_image, python_image, rust_image, ruby_image, golang_image ]
[ ort_version, base_image, nodejs_image, python_image, rust_image, ruby_image, golang_image ]
name: Build ORT minimal image
runs-on: ubuntu-22.04
permissions:
Expand All @@ -300,47 +317,16 @@ jobs:
run: |
cat .versions >> $GITHUB_ENV
- 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-minimal
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal
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 minimal image
uses: docker/build-push-action@v5
uses: heliocastro/docker-build-control@v2
with:
context: .
name: ort-minimal
target: minimal
push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
load: false
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ needs.ort_version.outputs.ort_version }}
build-args: |
NODEJS_VERSION=${{ env.NODEJS_VERSION }}
ORT_VERSION=${{ env.ORT_VERSION }}
tags: |
${{ steps.meta-ort-minimal.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
ORT_VERSION=${{ needs.ort_version.outputs.ort_version }}
build-contexts: |
base=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/base:latest
nodejs=docker-image://${{ env.REGISTRY }}/${{ github.repository }}/nodejs:latest
Expand All @@ -355,7 +341,7 @@ jobs:
if: ${{ github.event_name != 'pull_request' }}
name: Build ORT image
needs:
[ minimal_image, android_image, dart_image, dotnet_image, haskell_image, scala_image, swift_image ]
[ ort_version, minimal_image, android_image, dart_image, dotnet_image, haskell_image, scala_image, swift_image ]
runs-on: ubuntu-22.04
permissions:
contents: read
Expand All @@ -367,11 +353,6 @@ jobs:
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

Expand All @@ -392,7 +373,7 @@ jobs:
type=schedule,pattern={{date 'YYYYMMDD'}}
type=schedule,pattern=snapshot
type=pep440,pattern={{version}}
type=raw,value=${{ env.ORT_VERSION }}
type=raw,value=${{ needs.ort_version.outputs.ort_version }}
type=ref,event=tag
- name: Build ORT image
Expand All @@ -401,15 +382,42 @@ jobs:
context: .
target: run
push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
load: false
load: ${{ github.event_name == 'pull_request' }}
tags: |
${{ steps.meta-ort.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta-ort.outputs.labels }}
build-contexts: |
minimal=docker-image://${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal:${{ env.ORT_VERSION }}
minimal=docker-image://${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal:${{ needs.ort_version.outputs.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
funTest-docker:
needs: ort_image
runs-on: ubuntu-22.04
container:
image: ghcr.io/oss-review-toolkit/ort:${{ needs.ort_image.outputs.build_version }}
options: --user 1001
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Run functional tests that do require external tools
uses: gradle/gradle-build-action@v3
with:
gradle-home-cache-cleanup: true
arguments: --scan -Ptests.include=org.ossreviewtoolkit.plugins.packagemanagers.* funTest jacocoFunTestReport
- name: Upload code coverage data
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: funTest-docker

0 comments on commit b787c85

Please sign in to comment.