Skip to content

Commit

Permalink
Merge #766
Browse files Browse the repository at this point in the history
766: add simple labels to the images r=Alexhuszagh a=Emilgardis



Co-authored-by: Emil Gardström <emil.gardstrom@gmail.com>
  • Loading branch information
bors[bot] and Emilgardis authored Jun 7, 2022
2 parents 42cea7d + 886d729 commit 6b42263
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,25 @@ 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'
timeout-minutes: 60
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
Expand Down Expand Up @@ -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' && (
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion build-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b42263

Please sign in to comment.