-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test image with multiple tags from metadata-action #506
Comments
Pretty much the same as the example from https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md: name: ci
on:
push:
branches:
- 'master'
env:
TEST_TAG: myapp:test
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: name/app
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and export to Docker
uses: docker/build-push-action@v2
with:
context: .
load: true
tags: ${{ env.TEST_TAG }}
-
name: Test
run: |
docker run --rm ${{ env.TEST_TAG }}
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }} |
The example completely misses my entire point of multiple tags given by the metadata-action. The example just hardcodes a single tag. When using metadata-action to dynamically determine tags, some builds may get multiple and there might not be a single tag that's always present. Even the The value of |
@sim642 Don't really get your point of using the metadata action in the step that exports the image to docker to be able to test it but you can use the -
name: Test
run: |
docker run --rm name/app:${{ steps.meta.outputs.version }} Or the JSON output from the metadata action: -
name: Test
run: |
docker run --rm ${{ fromJSON(steps.meta.outputs.json).tags[0] }} Or the metadata output of this action: -
name: Test
run: |
docker run --rm ${{ fromJSON(steps.build.outputs.metadata)['containerimage.config.digest'] }} |
Thanks! This is what I was looking for. Maybe it would be useful for others to have this mentioned in the test-before-push example document as well. |
As someone that isn't super-familiar with Github Actions, I had no idea how to select from the JSON output that is mentioned in the README, this bit from your example is super clarifying:
Please consider adding this as an example to the README, thanks! |
I had no idea which data and which keys were available in the |
There's an example on how to load and test an image with a fixed tag: https://github.com/docker/build-push-action/blob/master/docs/advanced/test-before-push.md. But I'm using metadata-action to potentially build and push images with multiple tags, thus just trying to run
${{ steps.meta.outputs.tags }}
won't work.Previously I didn't use gha cache and then
${{ steps.build.outputs.digest }}
seemed to work fordocker run
. But since adding caching (and thusdocker/setup-buildx-action
), this doesn't work anymore:I guess it's somehow related to #461, but I don't really care what digest is what and where it's shown. I just want to run the loaded image.
I also tried
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
, but that doesn't work for running the locally loaded image either:How is this supposed to be done?
The text was updated successfully, but these errors were encountered: