ckulka / docker-multi-arch-example

TL;DR reference for building multi-arch Docker images on Docker Hub
70 stars 16 forks source link

Handeling tags #1

Open guysoft opened 4 years ago

guysoft commented 4 years ago

Hey, First thanks for this repo and explanation, I have implemented it for https://github.com/guysoft/CustomPiOS .

The thing is - I am preparing for a release. Which means that once I push a tag dockerhub would build and publish a new image tag. However the manifest setup is built only to handle a hard-coded tag name.

Is there a way to handle post push tagging? Which does exist on dockerhub?

I would think there is an env variable to find out what tag is made and then string-replace with something like sed a palceholder in a committed yaml file.

ckulka commented 4 years ago

Hi @guysoft ,

if I understand correctly, you don't want to hard-code the Docker image tags in the manifest YAML file, but make it more dynamic based on Git tags?

You are on the right track: all hooks (including post push) have access to environment variables, e.g. the name of the branch or tag that is built in SOURCE_BRANCH. The complete list is available at https://docs.docker.com/docker-hub/builds/advanced/#environment-variables-for-building-and-testing.

You can use those environment variables and some bash scripting to docker tag and docker push additional Docker image tags and generate the manifest YAML file, instead of using a versioned one.

Different topic: your first release (below is iirc) I'm not sure about your audience, but please experiment first in a separate repository to see some of the potential quirks. You might have to re-trigger builds on Docker Hub when you first release it, depending on when which build runs. The manifest file (static or generated) expects all image variants to be available on Docker Hub, but that's not the case on your initial push, so the initial builds (well, n-1) would fail... just FYI.

Good luck, hope it helped - let me know if you have other questions/I missed your question

ckulka commented 4 years ago

Completely forgot, I also have an example where I generate the manifest YAML file. It's not exactly your scenario, but I hope it helps: https://github.com/ckulka/baikal-docker/tree/master/hooks

guysoft commented 4 years ago

@ckulka

Ok, I have a test repo and a script that seems to work, only one issue: Always one build would fail, and one will pass. This is because the first image builds and fails to push the manifest because the second hasn't finished yet. Is there a way around this? Like one triggering the other? Or searching if both are present?

Here is the script: https://github.com/guysoft/CustomPiOS-test/blob/devel/src/hooks/post_push

guysoft commented 4 years ago

Ok, I added an extra function that lets you test if a tag exists. So it works now. I did some refactoring, but I think with some work it could become generic and work for more people.

guysoft commented 4 years ago

You could either close this issue, or keep it open if you want to add this to the repo example

ckulka commented 4 years ago

Nice work, that'll allow parallel builds for the platforms on Docker Hub.

Alternatively (and that's just me running into race conditions one too many times) you can also build all image variants in a single Docker Hub build execution if it takes less than 2h. That's what I ended up doing in https://github.com/ckulka/baikal-docker/blob/master/hooks/build because I ran into the exact same issue.