GNS3 / gns3-registry

GNS3 devices registry
GNU General Public License v3.0
323 stars 387 forks source link

Docker build: Support logins to multiple registries #774

Closed b-ehlers closed 1 year ago

b-ehlers commented 1 year ago

The Docker build tool already support building and uploading to multiple registries (by using full image names), but it allows to login only into one. This PR supports to login into multiple registries.

While the changes in the tool were quite small, the workflow got quite large changes

grossmj commented 1 year ago

One question, if I want to build & push images to ghcr.io in addition of Docker hub, do I just need to:

  1. Set this to true: https://github.com/GNS3/gns3-registry/pull/774/files#diff-2817fc9ec6443e19233164eefa86576a0972ce81bcf0ec4a04f96d6119db038eR49
  2. Remove the comment: https://github.com/GNS3/gns3-registry/pull/774/files#diff-2817fc9ec6443e19233164eefa86576a0972ce81bcf0ec4a04f96d6119db038eR62 (problem is there is already DOCKER_REPOSITORY defined above)

Thanks 👍

b-ehlers commented 1 year ago

As I wrote in the initial comment: The Docker build tool currently supports building and uploading to multiple registries ONLY by using full image names. Lets assume the docker_images configuration file looks like this:

test1           ubuntu
docker.io/gns3/test2    ubuntu
ghcr.io/gns3/test3  ubuntu

The test1 image contains only its name, not the repository. In this case the DOCKER_REPOSITORY environment variable will be used to define which repository to use. The other two lines (docker.io/gns3/test2 and ghcr.io/gns3/test3) contain the full target repository, so they are used unmodified.

When using DOCKER_REPOSITORY=gns3 the following images will then be build: gns3/test1 (as docker uses docker.io as the default registry this is the same as docker.io/gns3/test1), docker.io/gns3/test2 and ghcr.io/gns3/test3.

Now to your questions:

  1. You need to use to login to the docker repositories, you want to upload to. So in the above example, you need to login to both DockerHub (docker.io) and the GitHub container registry ghcr.io. And yes, that would be done by setting the if: condition to true. In the current docker settings https://github.com/GNS3/gns3-registry/blob/master/docker/docker_images only name-only target images are used, so only the repository defined by DOCKER_REPOSITORY is used. That means you need to login only to that repository. As currently the DOCKER_REPOSITORY is set to the DockerHub repository, only a login to that repository is needed. But, of course, you can additionally login to other repositories. That won't have any effect, as they are currently not used.
  2. You can define only one DOCKER_REPOSITORY. If you remove both comments of the DOCKER_REPOSITORY settings, the last one will succeed. This PR does NOT change the behavior of the build tool for building images. Builds to multiple repositories, when using name-only target images, is still not supported. For that see the issue https://github.com/GNS3/gns3-registry/issues/772.
grossmj commented 1 year ago

Thanks for the explanations! I hadn't seen https://github.com/GNS3/gns3-registry/issues/772

I will keep your PR like this and consider building and uploading to ghcr.io at a later stage. Thanks again for your help.

b-ehlers commented 1 year ago

Thanks. For uploading to multiple repositories this PR is a prerequisite, but more has to be done. Let us discuss the best way to build and upload to multiple repositories in #772.