Skip to content

Commit 6b42263

Browse files
Merge #766
766: add simple labels to the images r=Alexhuszagh a=Emilgardis Co-authored-by: Emil Gardström <[email protected]>
2 parents 42cea7d + 886d729 commit 6b42263

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,25 @@ jobs:
205205
- name: Set up Docker Buildx
206206
if: runner.os == 'Linux'
207207
uses: docker/setup-buildx-action@v1
208+
- name: Docker Meta
209+
if: runner.os == 'Linux'
210+
id: docker-meta
211+
uses: docker/metadata-action@v4
212+
with:
213+
images: |
214+
# This is only a placeholder name, we don't actually use this information.
215+
name=cross
216+
labels: |
217+
org.opencontainers.image.title=cross (for ${{ matrix.target }})
218+
org.opencontainers.image.licenses=MIT OR Apache-2.0
208219
- name: Build and push Docker image
209220
id: build-docker-image
210221
if: runner.os == 'Linux'
211222
timeout-minutes: 60
212223
run: ./build-docker-image.sh "${TARGET}"
213224
env:
214225
TARGET: ${{ matrix.target }}
226+
LABELS: ${{ steps.docker-meta.outputs.labels }}
215227
shell: bash
216228
- name: Set Docker image for test
217229
if: steps.build-docker-image.outputs.image
@@ -250,7 +262,20 @@ jobs:
250262
registry: ghcr.io
251263
username: ${{ github.actor }}
252264
password: ${{ secrets.GITHUB_TOKEN }}
253-
265+
- name: Docker Meta
266+
if: >
267+
runner.os == 'Linux' && (
268+
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
269+
startsWith(github.ref, 'refs/tags/v')
270+
)
271+
id: docker-meta2
272+
uses: docker/metadata-action@v4
273+
with:
274+
images: |
275+
name=${{ steps.build-docker-image.outputs.image }}
276+
labels: |
277+
org.opencontainers.image.title=cross (for ${{ matrix.target }})
278+
org.opencontainers.image.licenses=MIT OR Apache-2.0
254279
- name: Push image to GitHub Container Registry
255280
if: >
256281
runner.os == 'Linux' && (
@@ -260,6 +285,7 @@ jobs:
260285
run: ./build-docker-image.sh --push "${TARGET}"
261286
env:
262287
TARGET: ${{ matrix.target }}
288+
LABELS: ${{ steps.docker-meta2.outputs.labels }}
263289
shell: bash
264290

265291
publish:

build-docker-image.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ run() {
7979
build_args+=(--tag "${tag}")
8080
done
8181

82-
docker buildx build "${build_args[@]}" -f "${dockerfile}" --progress plain .
82+
if [ -n "${LABELS:-}" ]; then
83+
local labels
84+
mapfile -t labels -d '' <<< "${LABELS}"
85+
for label in "${labels[@]}"; do
86+
build_args+=(--label "${label}")
87+
done
88+
fi
8389

90+
docker buildx build "${build_args[@]}" -f "${dockerfile}" --progress plain .
91+
docker inspect "${tags[0]}" | jq -C .[0].Config.Labels
8492
if [[ -n "${GITHUB_ACTIONS-}" ]]; then
8593
echo "::set-output name=image::${tags[0]}"
8694
fi

0 commit comments

Comments
 (0)