docker build with a template Dockerfile

465 views Asked by At

I am using travis to build artefacts (jars and zips) and store them on bintray. I want to build docker images that install these artefacts for example for the 'app' artefact at version 0.1.0, hash abc123:

FROM some-registry/oracle-jre7
RUN wget https://BINTRAY_USER:[email protected]/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 maybe the version) will be different and I don't want to use 'latest'. I can easily generate the Dockerfile using a template in travis, but I'm not sure how to build the docker image. It seems I can't build it on travis and quay.io and docker hub don't have an api that I can post a Dockerfile or archive to (although you can do this through the ui on quay.io).

I don't want to get travis to commit the Dockerfile to a secondary git repo because that's getting really complex to sync the two repos if they have multiple branches. I could also commit a Dockerfile like this to the main repo and then trigger quay.io or dockerhub to build after the artefact was created (if they could 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:[email protected]/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 putting a docker host in ec2 and getting travis to get it to build the docker image and push it to a docker repository on bintary, but I'd rather not have to manage the host myself.

0

There are 0 answers