From 886d729fc4db2703fdc343309b1064e17f02e108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Tue, 7 Jun 2022 17:27:36 +0200 Subject: [PATCH] add simple labels to the images --- .github/workflows/ci.yml | 28 +++++++++++++++++++++++++++- build-docker-image.sh | 10 +++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 237bdfc89..ca5827f3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -205,6 +205,17 @@ jobs: - name: Set up Docker Buildx if: runner.os == 'Linux' uses: docker/setup-buildx-action@v1 + - name: Docker Meta + if: runner.os == 'Linux' + id: docker-meta + uses: docker/metadata-action@v4 + with: + images: | + # This is only a placeholder name, we don't actually use this information. + name=cross + labels: | + org.opencontainers.image.title=cross (for ${{ matrix.target }}) + org.opencontainers.image.licenses=MIT OR Apache-2.0 - name: Build and push Docker image id: build-docker-image if: runner.os == 'Linux' @@ -212,6 +223,7 @@ jobs: run: ./build-docker-image.sh "${TARGET}" env: TARGET: ${{ matrix.target }} + LABELS: ${{ steps.docker-meta.outputs.labels }} shell: bash - name: Set Docker image for test if: steps.build-docker-image.outputs.image @@ -250,7 +262,20 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - + - name: Docker Meta + if: > + runner.os == 'Linux' && ( + github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || + startsWith(github.ref, 'refs/tags/v') + ) + id: docker-meta2 + uses: docker/metadata-action@v4 + with: + images: | + name=${{ steps.build-docker-image.outputs.image }} + labels: | + org.opencontainers.image.title=cross (for ${{ matrix.target }}) + org.opencontainers.image.licenses=MIT OR Apache-2.0 - name: Push image to GitHub Container Registry if: > runner.os == 'Linux' && ( @@ -260,6 +285,7 @@ jobs: run: ./build-docker-image.sh --push "${TARGET}" env: TARGET: ${{ matrix.target }} + LABELS: ${{ steps.docker-meta2.outputs.labels }} shell: bash publish: diff --git a/build-docker-image.sh b/build-docker-image.sh index bf2b7d0da..8b372a3bf 100755 --- a/build-docker-image.sh +++ b/build-docker-image.sh @@ -79,8 +79,16 @@ run() { build_args+=(--tag "${tag}") done - docker buildx build "${build_args[@]}" -f "${dockerfile}" --progress plain . + if [ -n "${LABELS:-}" ]; then + local labels + mapfile -t labels -d '' <<< "${LABELS}" + for label in "${labels[@]}"; do + build_args+=(--label "${label}") + done + fi + docker buildx build "${build_args[@]}" -f "${dockerfile}" --progress plain . + docker inspect "${tags[0]}" | jq -C .[0].Config.Labels if [[ -n "${GITHUB_ACTIONS-}" ]]; then echo "::set-output name=image::${tags[0]}" fi