jerray/publish-docker-action

Still not tagging versions, despite auto_tags:true

Closed this issue · 7 comments

Hi!

First of all, thanks for this action, we've been using it for months to publish Openwhyd on Docker Hub!

We enabled auto_tags:true in the GitHub workflow that runs semantic-release and publish-docker-action, but we still don't see new tags (others than latest) on our Docker hub page, despite the fact that our CI logs shows that semantic-release did create a new tag before running publish-docker-action with auto_tags:true.

Did we forget anything in our configuration? (openwhyd/openwhyd@dca5597, introduced in openwhyd/openwhyd#306)

Thanks in advance for your help!

Adrien
Openwhyd

Please make sure your workflow is listening push events for tags.
You should add tags pattern in your workflow file nodejs.yml:

name: CI

on:
  push:
    branches:
      - master
    tags:
      - *
  pull_request:
    branches:
      - master

Thanks for your reply!

In my current configuration, tags are created in the same workflow as the one running publish-docker-action.

If I add tags to the list of events that this workflows responds to, does that mean that it will take two consecutive executions of that workflow for publish-docker-action to actually deploy that tag to docker hub? (the first to generate the tag, and the second to deploy using that tag)

Or am I missing anything?

Yes, you're right. If you add tags to the event list, after Semantic Release step finishes, it will start another workflow.

The auto_tags depends on current git reference GITHUB_REF. In your case, the workflow only listens push event on master branch, GITHUB_REF environment variable is always refs/heads/master. It results this action only generating latest tag.

If you add tags to the list of events, after pushing a tag to the repository, GitHub starts another workflow with environment variable GITHUB_REF=refs/tags/vX.Y.Z. Now, this action will generate docker tags as you expected. But I think you will want to skip Semantic Release step in this situation. Just add if: !startsWith(github.ref, 'refs/tags/') to that step.

I suggest switch actions/checkout version to v2. It provides more specific git information than v1.

Thanks for the explanation!

Ideally, I'd love to publish the docker image of each version with two tags: latest and the version number (a.k.a. the GitHub release tag) => is it possible to do both in one shot, to save some time and resources?

There is a simple solution for it. You can add another step before this action to generate tag list for it.

I don't know much about the semantic-release command, but I guess it creates a new git tag. After that, you can execute a shell command git tag -l --sort=-v:refname | head -1 to get the new tag (vX.Y.Z). If you don't want the prefix v exists in docker image tag, pipe the result to cut -c 2- to remove prefix. Here we can get the version number X.Y.Z. Prepend or append latest to it with delimiter ,. We get latest,X.Y.Z.

Now the only question is how to assign this result to publish-docker-action's tags argument. You can use action output to pass values between steps. For more information, please visit Workflow commands for GitHub Actions.

Here's an example for you.

- id: create_docker_tags
  run: |
    echo "::set-output name=tags::latest,$(git tag -l --sort=-v:refname | head -1 | cut -c 2-)"

- uses: jerray/publish-docker-action@v1.0.3
  with:
    username: ${{ secrets.DOCKER_USERNAME }}
    password: ${{ secrets.DOCKER_PASSWORD }}
    tags: ${{ steps.create_docker_tags.outputs.tags }}

Thanks for the awesome suggestion, jerray! I'm trying that in openwhyd/openwhyd#320 🤞

It worked! 🎉

image

Thank you so much, you rock! 💪