we'd like to put docker into the dev workflow and ship the docker images. it's important the developer can develop/test on the docker image to get the max benefit out of docker in devops: no more "but it works on my machine." since building the ratpack application is using gradle, it'd make sense to add docker plugin to gradle build script. (developer has less command to deal with)
inspired by this post http://kyleboon.org/blog/2014/08/14/ratpack-plus-docker-plus-gradle/, i started to do the same thing but choose the bmuschko gradle plugin https://github.com/bmuschko/gradle-docker-plugin instead. it's using later version of docker-java https://github.com/docker-java/docker-java. and can do much more than just creating an image and publish to docker registry.
Add the followings to your build.gradle -
you can put the docker.url & registryUrl in gradle.properties, so it won't be hardcoded
Add the Dockerfile to your project root directory
To minimize the file size, we use busybox.
docker images
REPOSITORY | TAG | IMAGE ID | CREATED | VIRTUAL SIZE |
---|---|---|---|---|
msvc-search | 1.0 | 14c228ee1435 | 6 seconds ago | 197.9 MB |
hystrix-dashboard | latest | 6b93ff844571 | 9 hours ago | 479.8 MB |
centos | 7 | dade6cb4530a | 2 days ago | 210.1 MB |
registry | latest | c55308716b36 | 10 days ago | 414.2 MB |
ubuntu | latest | 5ba9dab47459 | 10 days ago | 188.3 MB |
peelsky/zulu-openjdk-busybox | latest | 050380da31ed | 13 days ago | 181.8 MB |
progrium/busybox | latest | 8cee90767cfe | 2 weeks ago | 4.789 MB |
atcol/docker-registry-ui | latest | 28d7d683c7a9 | 5 weeks ago | 908.6 MB |
progrium/busybox is just 5MB! And we have license issue to ship with oracle jdk, so we use openjdk. But appears openjdk are only distributed through yum/apt and i can't find any way to install that on busybox as it only has opkg. Zulu http://www.azulsystems.com/products/zulu, is certified build of openjdk and it's 100% opensource and free. It also provides official docker image, however, they are not using busybox. Luckily someone already did that! thanks to peelsky/zulu-openjdk-busybox. with the jdk it's mere 182MB.
Also, since the Dockerfile is put on the project root, it'll tar up the whole project and send to the docker deamon while we only need the fat jar! to avoid that, add .dockerignore to your project root.
Now when you run ./gradlew --info buildDocker, only the necessary file are sent to the docker daemon.
Sending build context to Docker daemon 16.12 MB
Sending build context to Docker daemon
Step 0 : FROM peelsky/zulu-openjdk-busybox
---> 050380da31ed
Step 1 : WORKDIR /app
---> Using cache
---> 954a21f6409e
Step 2 : USER daemon
---> Using cache
---> 208cd5606087
Step 3 : ADD ./build/libs/msvc-search-1.0-all.jar /app/msvc-search-1.0-all.jar
---> 6e11e87fb593
Removing intermediate container c109ca327f00
Step 4 : CMD java -jar /app/msvc-search-1.0-all.jar
---> Running in bea41332ae6a
---> 82e41217ecd2
Removing intermediate container bea41332ae6a
Step 5 : EXPOSE 9500
---> Running in 40d91cd09bd0
---> b4e042fa2a6e
Removing intermediate container 40d91cd09bd0
Successfully built b4e042fa2a6e
No comments:
Post a Comment