Skip to content

Commit

Permalink
ci(github): Rewrite the Docker build job
Browse files Browse the repository at this point in the history
Replace the `docker-ort` workflow with the new `docker-build` workflow.
Instead of the old approach to build separate Docker images for the
different package managers, the new workflow uses the Docker registry
cache [1] to cache the layers in the GitHub container registry. This
dramatically simplifies the build process, as no additional logic for
building the Docker images is required anymore.

The workflow first builds the full Docker image and caches it to the
registry. The minimal image is built afterwards and can reuse all layers
but the last one from the previously populated cache.

This commit also slightly changes the way that Docker images are tagged:

* All published images are now tagged with the Git revision. Previously,
  the revision was only visible as part of the ORT version tag, which
  does not include the revision for release builds.
* The latest build from the main branch is now tagged with the `main`
  tag.

[1]: https://docs.docker.com/build/cache/backends/registry/

Signed-off-by: Martin Nonnenmacher <[email protected]>
  • Loading branch information
mnonnenmacher committed Apr 16, 2024
1 parent 3fb7c9b commit cb7d27c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 434 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Docker Build

on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- '*'
workflow_dispatch:

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false
REGISTRY: ghcr.io
IMAGE_CACHE_TAG: ghcr.io/mnonnenmacher/ort:cache
IMAGE_NAME: ghcr.io/mnonnenmacher/ort

jobs:
disk_space:
name: Disk Space
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Free Disk Space
uses: ./.github/actions/free-disk-space
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-home-cache-cleanup: true
- name: Get ORT 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 Buildx
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 Docker Metadata for ort Image
id: meta-ort
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort
tags: |
type=pep440,pattern={{version}}
type=raw,value=${{ env.ORT_VERSION }}
type=ref,event=branch
type=ref,event=tag
type=sha
- name: Build & Push ort Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta-ort.outputs.tags }}
labels: ${{ steps.meta-ort.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache,mode=max
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
- name: Extract Docker Metadata for ort-minimal Image
id: meta-ort-minimal
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/ort-minimal
tags: |
type=pep440,pattern={{version}}
type=raw,value=${{ env.ORT_VERSION }}
type=ref,event=branch
type=ref,event=tag
type=sha
- name: Build & Push ort-minimal Docker Image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta-ort-minimal.outputs.tags }}
labels: ${{ steps.meta-ort-minimal.outputs.labels }}
target: minimal
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ github.repository_owner }}/ort:cache
build-args: ORT_VERSION=${{ env.ORT_VERSION }}
- name: Print Disk Space
run: df -h
Loading

0 comments on commit cb7d27c

Please sign in to comment.