I already have set up a github repository with 3 branches (master, dev and docker). I already set up successfully and linked the automated build on dockerhub. Each time a push is done on Github an image is built on Dockerhub with different tag (latest for master, beta for dev and alpha for docker). This is working fine. Now the problem...
On Dockerfile, there is a git clone command to retrieve the project. The problem is this is pointing to master always. So if I push something to docker branch for example (it builds image with alpha tag) the code of project on that image is the code of master and not code of branch docker which is the desired for this case.
If I modify the Dockerfile of branch docker (which generate alpha tagged image) and I put git clone -b docker ... the build is ok, but after all the tests, when I want to merge with a pull request from docker branch to dev branch for example, another updated is needed on dev to change the git clone command inside of Dockerfile to point to the right branch. And the same with a pull request from dev to master with the additional difficult of on this project the master branch is protected and I can't push directly to master... so after a pull request from dev to master I can't fix Dockerfile changing the Dockerfile to change git clone to point again to master.
Is there a way to have different branches with different tags on automated building without changing anything after pull requests from one to other branch? Thank you.
When using automated builds, this is what happens;
From the above; you should not git clone inside your Dockerfile at all, because you'd be doing what's already done by the automated build. Simply do;
FROM some-base-image
# Copy your project's source into the image
COPY . /my-src
RUN do-something-with-the-source
Docker Cloud has advanced features, which allow you to run custom scripts at various stages of the automated build, using build phase hooks (documentation). This allows you (for example) to make "minimal" images by building your project in a "build image", then copying the generated code to a local directory, and building the final image from that.
edit
The Automatic build options on Docker Cloud has more features than Automatic Build on Docker Hub. For example, the Dockerfile to build, and the build-context can be set separately. This allows you to have a Dockerfile in a subdirectory, but use files outside of that subdirectory to be used as the build context. To do this, set the Dockerfile location to (e.g.) /docker/Dockerfile, and the buildcontext to /