Skip to content

How to use Docker tag in a following step ? #140

Closed

Description

@Lucas-C

Behaviour

From this README.md, steps.meta.outputs.tags is typed as a String.

However, when trying to use the Docker image built in a following step,
when a new image as been built,
steps.meta.outputs.tags value seems to be <image>:<tag>\n<image>:latest

This \n character causes calls to docker run ... ${{ steps.meta.outputs.tags }} to fail,
as the CI shell interprets the string following the newline as a command that does not exist.

Steps to reproduce this issue

  1. Clone https://github.com/voyages-sncf-technologies/vboard
  2. Create a new tag
  3. Observe the Actions pipeline result

Expected behaviour

I tried to use ${{ steps.meta.outputs.tags[0] }} instead,
but this gets inetrpreted as an empty string (on non-tag builds at least).

Actual behaviour

Neither ${{ steps.meta.outputs.tags }} nor ${{ steps.meta.outputs.tags[0] }}
can actually be used in a docker command following usage of docker/metadata-action@v3 & docker/build-push-action@v2

Configuration

  docker-build-push-ws:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: docker/metadata-action@v3
        id: meta
        with:
          images: vboard/vboard-ws
      - uses: docker/login-action@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - uses: docker/build-push-action@v2
        with:
          context: vboard-ws
          push: ${{ startsWith(github.ref, 'refs/tags/') }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
      - name: Validating the image built can start without any error
        run: docker run -e SPRING_PROFILES_ACTIVE=test -e EXIT_AFTER_INIT=true ${{ steps.meta.outputs.tags }}

Logs

vboard-build-3883855145.log

Activity

  1. crazy-max commented on Oct 15, 2021

    @crazy-max
    Member

    @Lucas-C

    This \n character causes calls to docker run ... ${{ steps.meta.outputs.tags }} to fail

    You can change the tags separator with the sep-tags input.

    Neither ${{ steps.meta.outputs.tags }} nor ${{ steps.meta.outputs.tags[0] }}
    can actually be used in a docker command

    I would suggest to use the version output instead:

          - name: Validating the image built can start without any error
            run: docker run -e SPRING_PROFILES_ACTIVE=test -e EXIT_AFTER_INIT=true vboard/vboard-ws:${{ steps.meta.outputs.version }}

    See https://github.com/crazy-max/docker-fail2ban/blob/master/.github/workflows/build.yml

  2. Lucas-C commented on Oct 15, 2021

    @Lucas-C
    Author

    Thank you for your answer @crazy-max !

    I think this will perfectly solve my issue.
    I cannot create a new tag right now, but I'm confident it should do the trick.

  3. ivoba commented on Nov 23, 2021

    @ivoba

    @Lucas-C did you solve this?
    I have the same problem and steps.meta.outputs.version seems not to be the solution here.

    Ok nevermind, i just returned to tags: ${{ steps.meta.outputs.tags }} and it works now.
    Must been something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions