Is there a best practices for making the Dockerfile sensitive to the git branch?
Background:
I've noticed that the docker hub automated builds, also senses if there are several git branches, and makes an automated build for each of them when they are updated as below
This is a really nice feature, but it leaves me with a problem. My Dockerfile
contains a specific call to check out from the git repository as
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN git clone https://bitbucket.org/user/myrepo.git
WORKDIR /myrepo
RUN make
This means that even though i have severl branches in the repository, all the the docker-hub tags will only pull the master
branch.
So the question is: Is there a best practices for making the Dockerfile sensitive to the git hub branch?
Uggly solution:
I could ofclurse change the docker build file so that it pulls the correct branch for that tag, as
FROM ubuntu:14.04
ENV DEBIAN_FRONTEND noninteractive
RUN git -b my_branch clone https://bitbucket.org/user/myrepo.git
WORKDIR /myrepo
RUN make
but this would have the two main downsides
- I would need to manually add
-b my_branch
to theDockerfile
in every new branch where i wanted this to work. - When the branch is merged back to
master
, that-b my_branch
would also be merged and subsequently break theDockerfile
in themaster
branch.
This question talks about adding several docker-hub builds, but is not really what i need. Docker Hub Automated Build - Tagging
Thankful for suggestions