util-docker: Proof-of-concept using Docker buildx (#273)

Introduced in https://github.com/gem5/gem5/pull/236 the
"docker-build.yaml" file will allow us to build and push docker images
to the GitHub Container Registry. This allows for both automation of
docker image building and allows us to utilize Github's zero-cost
pulling policy for downloads to GitHub Actions runners.

In this PR https://github.com/gem5/gem5/pull/236 has been altered to use
Docker `buildx` which allows for multi-platform Docker Image builds. A
multi-platform Docker image pull automatically pull the correct image
for your platform from a single URL. In this prototype the images are
build to both `linux/arm64` and `linux/amd64` have been set.

Docker `buildx` has it's own file format for specifying image builds
called `bake`. "util/dockerfiles/docker-bake.hcl" has been added with
the goal of replacing "util/dockerfiles/docker-compose.yaml".

In this proof-of-concept doesn't build all our docker images, just
enough to ensure it works inside our actions as intended.
This commit is contained in:
Bobby R. Bruce
2023-09-07 11:37:24 -07:00
committed by GitHub
5 changed files with 108 additions and 28 deletions

View File

@@ -1,42 +1,39 @@
#
name: Docker images build and push
on:
push:
branches:
- develop
paths:
- 'util/docker/ubuntu-20.04_all-depenencies'
workflow_dispatch:
env:
IMAGE_NAME: ubuntu-20.04_all-depenencies
#
jobs:
# This builds and pushes the docker image.
push:
build-and-push:
runs-on: [self-hosted, linux, x64, run]
permissions:
packages: write
contents: read
container: gcr.io/gem5-test/ubuntu-22.04_all-dependencies:latest
steps:
- uses: actions/checkout@v3
name: Checkout the develop branch
with:
# Scheduled workflows run on the default branch by default. We
# therefore need to explicitly checkout the develop branch.
ref: develop
- name: Build image
run: |
cd util/docker/ubuntu-20.04_all-depenencies
docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
- uses: docker/setup-qemu-action@v2
name: Setup QEMU
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- uses: docker/setup-buildx-action@v2
name: Set up Docker Buildx
- name: Push image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
- uses: docker/login-action@v2
name: Login to the GitHub Container Registry
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# This changes all uppercase characters to lowercase.
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID::latest
- name: Build and push with bake
uses: docker/bake-action@v3
with:
files: util/dockerfiles/docker-bake.hcl
push: true