I would like to create a dockerfiles repository on GitHub to centralize all custom Dockerfiles I've created so far. I also would like to automatize builds of each image on Docker Hub, independently.
There is many repositories like this on GitHub :
(I would not talk here about the most starred repository : https://github.com/jessfraz/dockerfiles, because as you can see on Docker Hub, these are not automated builds)
Wanted structure of dockerfiles repository
I'd like my dockerfiles GitHub repository have the following structure (branch master), based on GitHub repositories I mentioned above :
dockerfiles (GitHub repo)
    |- docker-image-1
        |- Dockerfile
    |- docker-image-2
        |- Dockerfile
    |- ...
Docker Hub builds automation
Configuration
On Docker Hub, I could create 2 public automated builds : docker-image-1 and docker-image-2, both referring to my dockerfiles GitHub repository, but with different Build Settings (in fact, only Dockerfile Location differs) :
- for docker-image-1:- Type : Branch
- Name : master
- Dockerfile Location : /docker-image-1/
- Docker Tag Name : latest
 
- for docker-image-2:- Type : Branch
- Name : master
- Dockerfile Location : /docker-image-2/
- Docker Tag Name : latest
 
Drawbacks
With this configuration, all images will be rebuilt if a push on master branch is made (even if there is only 1 Dockerfile concerned by the push and Dockerfile Locations are different). I've checked, it seems to be configured like this for vimagick's repository. But I don't think it's the right way (if I'm wrong, tell me).
Of course, in Build Settings of each automated build, I could disable option "When active, builds will happen automatically on pushes" to avoid this, but I'll have to trigger each build manually depending on what Dockerfile I've updated (not automatic).
Improve automation?
Solutions I see to improve automation are :
- separate each Dockerfilein its own GitHub repository. No moredockerfilesrepository, so each one have its own workflow
- use a single GitHub repository dockerfiles, but with different branches (one per Docker image). Each build could then be configured to be triggered only on the appropriate branch
With these solutions, problem is that I lost a global overview of all my Dockerfiles. I prefer the idea of a single repository with a single branch, but I don't want all images to be rebuilt on each push on this single branch.
If I'm choosing solution 1, I don't know if git can help me to keep a single repository dockerfiles referencing all my repositories, like :
 dockerfiles (GitHub repo)
    |- docker-image-1 -> link to https://github.com/norbjd/docker-image-1
        |- Dockerfile
    |- docker-image-2 -> link to https://github.com/norbjd/docker-image-2
        |- Dockerfile
It would then be easier to clone the whole project and do Pull Requests (since some images are related : updating docker-image-1/Dockerfile could lead to update docker-image-2/Dockerfile). I've read about Git submodules and subtrees, but I don't know if these are appropriate here.
Maybe it's possible with a single repository, and it's just about finding the right Docker Hub Build Settings.
What are the best practices?
 
    