Deploy image to docker optionally, as well as GHCR#97
Conversation
Without repo orgname
…oy-image-to-docker-optionally
elrayle
left a comment
There was a problem hiding this comment.
Really glad to see deploy to DockerHub coming together. I proposed an alternative approach to generating the image name twice. See what you think about that option.
| echo -e "---- script log\n$script_log\n----"; \ | ||
| image_name=$(echo "$script_log" | tail -n 1) | ||
| echo "DOCKER_IMAGE_NAME_WITH_TAG=$image_name" >> $GITHUB_ENV | ||
| echo "GCHR_DOCKER_IMAGE_NAME_WITH_TAG=$image_name" >> $GITHUB_ENV |
There was a problem hiding this comment.
Based on the example for push-multi-registries, it appears that the image-name-with-tag is the same for both, except that in the case of ghcr, it is prepended with ghcr.io. It might be cleaner to determine the image name once for both and then do a prepend when they are used.
This would require removing ghcr.io from the image_base_name in the script and prepending it when the image name is used. This works here because the username for DockerHub is the same as the org (owner) name.
There was a problem hiding this comment.
Thanks, I will try your proposal
I like that it reduced having the if statements on prefix in the shell script.
| repo="$1" | ||
| deploy_env="$2" | ||
| image_tag="$3" | ||
| prefix="$1" |
There was a problem hiding this comment.
With the previous suggestion, the prefix isn't needed. image_base_name will be $repo for both ghcr and Docker Hub.
| gchr-docker-image-name-with-tag: "${{ env.GCHR_DOCKER_IMAGE_NAME_WITH_TAG }}" | ||
| dockerhub-image-name-with-tag: "${{ env.DOCKERHUB_IMAGE_NAME_WITH_TAG }}" |
There was a problem hiding this comment.
There is a proposal below for a way to only get the image-name-with-tag once and then add the prepend at the point where these are used. An alternative would be to still get the image-name-with-tag only once and do the prepend here instead of at the point the tags are used.
| gchr-docker-image-name-with-tag: "${{ env.GCHR_DOCKER_IMAGE_NAME_WITH_TAG }}" | |
| dockerhub-image-name-with-tag: "${{ env.DOCKERHUB_IMAGE_NAME_WITH_TAG }}" | |
| ghcr-docker-image-name-with-tag: "ghcr.io/${{ env.DOCKER_IMAGE_NAME_WITH_TAG }}" | |
| dockerhub-image-name-with-tag: "${{ env.DOCKER_IMAGE_NAME_WITH_TAG }}" |
| tags: | | ||
| ${{ needs.determine-image-name.outputs.gchr-docker-image-name-with-tag }} | ||
| ${{ needs.determine-image-name.outputs.dockerhub-image-name-with-tag }} |
There was a problem hiding this comment.
If following the previous proposal to have a single image-name-with-tag, you can either do the prepend here like the following or at the point where the tags are created if you think it is clearer to have separate outputs for the tags (as in the suggestion for job determine-image-name).
| tags: | | |
| ${{ needs.determine-image-name.outputs.gchr-docker-image-name-with-tag }} | |
| ${{ needs.determine-image-name.outputs.dockerhub-image-name-with-tag }} | |
| tags: | | |
| "ghcr.io/${{ needs.determine-image-name.outputs.docker-image-name-with-tag }}" | |
| ${{ needs.determine-image-name.outputs.docker-image-name-with-tag }} |
There was a problem hiding this comment.
This looks great, much simpler than my approach
| tags: | | ||
| ${{ needs.determine-image-name.outputs.gchr-docker-image-name-with-tag }} | ||
| ${{ needs.determine-image-name.outputs.dockerhub-image-name-with-tag }} |
There was a problem hiding this comment.
One other question related to this, what happens if you have the tag that is expected to go to Docker Hub, but the login to Docker Hub didn't happen, which is what is expected for all but prod crawler deploy? Does it just push to ghcr.io in that case?
There was a problem hiding this comment.
The tag is not generated and it's an empty string, As I've added the conditional if: ${{ inputs.docker-hub-username != '' }} in the step Determine Dockerhub Image Name
- name: Determine Dockerhub Image Name
if: ${{ inputs.docker-hub-username != '' }}
id: determine_dockerhub_name
I've tested this with a dev release and it only publishes the ghcr image.
|
@elrayle It all depends on wether I can add the conditionals to ensure that dockerhub tag is added only when needed. |
Create comma seperated list of tags
|
@elrayle I've attempted to implement the strategy you have suggested. One subtle issue I had to deal with however. But in order for me to test the action I've added my docker credentials into the crawler vars. So I've altered the determining image script so it doesn't take the Then only add the dockerhub tag string conditionally |
elrayle
left a comment
There was a problem hiding this comment.
This looks great. Thanks for pushing this through. There is a single suggestion to update the documentation of the output of the script.
Co-authored-by: E. Lynette Rayle <elrayle@users.noreply.github.com>
What
To migrate deployment of Production Crawler to CD Azure from Microsoft owned Azure.
Changes to workflow
app-build-and-deployThis PR enables the optional docker image publish to Docker Hub, conditional on providing
docker-hub-usernameDOCKERHUB_TOKENWithout these the action only deploys to ghcr
Why
Testing
Using test branch https://github.com/clearlydefined/crawler/tree/deploy-production-cd-azure
connfigured to publish to my dockerhub, and deploy to a inactive prod crawler in CD azure
Successful prod deploy which publshses 2 images docker hub and ghcr: https://github.com/clearlydefined/crawler/actions/runs/11163856034
Sucessful dev deploy that publishes 1 gchr image https://github.com/clearlydefined/crawler/actions/runs/11164059253
notes:
I will squash the commits when I merge as there was a lot of back and forth to test