Docker build with Dockerfile template

I am using travis to create artifacts (cans and lightning bolts) and save them to bintray. I want to build docker images that install these artifacts, for example for the "app" artifact in version 0.1.0, hash abc123:

FROM some-registry/oracle-jre7
RUN wget https://BINTRAY_USER:BINTRAY_API_KEY@dl.bintray.com/USER/REPO/app-0.1.0_abc123.jar -O /opt/app.jar
EXPOSE 9000
CMD ["java", "-jar", "/opt/app.jar"]

      

Every time I want to create this docker image the hash (and possibly the version) will be different and I don't want to use the "last" one. I can create a Dockerfile easily using a template in travis, but I'm not sure how to create a docker image. I can't seem to build it on travis and quay.io and the docker hub doesn't have an api that I can publish a Dockerfile or archive (although you can do this via the ui on quay.io).

I don't want travis to push the Dockerfile to the second git repository because it is very difficult to keep the two repos in sync if they have multiple branches. I could also commit a Dockerfile like this to the main repo and then run quay.io or dockerhub to build after the artifact is built (if they can somehow evaluate the git hash):

FROM some-registry/oracle-jre7
ENV APP_VERSION 0.1.0
ENV APP_GIT_HASH $(git rev-parse --short HEAD) # this definitely doesn't work
RUN wget https://BINTRAY_USER:BINTRAY_API_KEY@dl.bintray.com/USER/REPO/app-${APP_VERSION}_${GIT_HASH}.jar -O /opt/app.jar
EXPOSE 9000
CMD ["java", "-jar", "/opt/app.jar"]

      

I am currently experimenting with placing the docker host in ec2 and getting a travis to force it to create a docker image and drag it into the docker repository on bintary, but I wouldn't have to manage the host myself.

+3


source to share





All Articles