Skip to content

Commit

Permalink
Publish a docker image for genie-app (#414)
Browse files Browse the repository at this point in the history
* Add publishing a docker image for genie-app

* Add Maintainer and some other information to build scripts
  • Loading branch information
tgianos committed Oct 18, 2016
1 parent fad4d64 commit dedbaaa
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jdk:
- oraclejdk8
services:
- mysql
- docker
git:
depth: 200
install: true
Expand All @@ -33,6 +34,8 @@ env:
- secure: c0LFCj1KBTEIFSWlpRGgaei86bfrpnSr8qmMOu/S4dl2JRnCnW9AHmrmQzYhd5NlNPugOAncYk9lnkxA7xqtDlv/Ih4YKBaeP924hwLWO//0tKgxhF1dr0dHI+bRKURvcSyLXFDNFjuXUrw4SalBLbZCmiNFzJLMmy2Lvs9UTso=
- secure: Nv1mMLy2XX+bYziq536KbNg/mAVDTaLw3q3bKP2Mil3JVicXxYVbkEo+DK2O4rsuT7JNbyroN6/3x7xT9qBo4X7vzCjU91QUAxq5t0SmG0FW+oAIApHWTum307b5XS2UyqV/88gg1O6g9or3bKmDLUsJ1A/+fsASozA207a7zls=
- secure: "azkmD+d2nSitHJS8AB/L2aAJyiUDBa8tQX4c/gzC/dZHkSUBslyAbGz7OyLWt31JF1WdlNpoWel1gp2/nNoi8W5s46N5z9yYMbGONJUAqaUNWYDfjrLqRtUDPAoo39zARUfsuKPu9Bqt+ZEjb5jiHwj9CRBoejkdbFdPdMNziwA="
- secure: "VcIk7En7f0roWC4TmhEqBjTRk4SQyqewiR40R3hPYtuIAeQJVp3p7BuQXHw2SE8vrH6FP15Upc+wQdT9fH1+VFud4p2cPe29PEu9i/XljVE8aBRfupkBaA9LM1HxGFf4NDHVVNyVwYCKl3qQ2YtXbzlcW+CqfjiS9BJc3StTMGU="
- secure: "WxyfobFKon0REJS7HSYdVJw1gmyEs+6c7sl/zT2mPkQ+uAcHX2mIBl6YDA9rpu5pt0WY6EX4pHYNydGquN59DqOCQpk1ny88h2kVB6CWi2MOjFloxXJmCRWdecx3UtvvoKROG+kReldQwQwL6VpO3l1+K3ISDnjQTqPkPjdukyQ="
notifications:
slack:
secure: H5nS+GX6TYTU27ur6YFG5OgrQeUbzXLok5ub6+xcmyYEeVPpnQ1Gg/wKqTAGsP9j6tAkqPpxgYT9i9Do6eyTEplK6bTvQVyhilsEDtxGJbUO8XOE9TSo6jAe/lD3EB5l46gxFID+Hg9IkPii4LwEabP7PVehrB1JfNZ6QDgSRRM=
72 changes: 68 additions & 4 deletions genie-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//plugins {
// id "com.palantir.docker" version "0.9.1"
//}

apply plugin: "spring-boot"

dependencies {
Expand Down Expand Up @@ -45,3 +41,71 @@ bootRun {
addResources = false
systemProperty "spring.profiles.active", env
}

def dockerDir = new File(project.buildDir, "/docker")

def isLatest() {
return (boolean) !project.version.toString().contains("SNAPSHOT") && !project.version.toString().contains("-rc.")
}

def getTags(String appName) {
def tags = ["netflixoss/${appName}:${project.version}"]
if (isLatest()) {
tags.add("netflixoss/${appName}:latest")
}
return tags
}

task dockerCreateInputDir(type: Copy, group: "Docker", description: "Stage all the necessary files docker image") {
dependsOn tasks.jar, tasks.bootRepackage
from tasks.jar
from new File(project.projectDir, "src/main/docker/Dockerfile")
into dockerDir
}

task dockerBuildImage(type: Exec, group: "Docker", description: "Build docker image based on the Dockerfile") {
dependsOn tasks.dockerCreateInputDir
workingDir dockerDir

def appName = jar.baseName.toString()

def commandArgs = new ArrayList<>()
commandArgs.add("docker")
commandArgs.add("build")
commandArgs.add("--force-rm")
commandArgs.add("--build-arg")
commandArgs.add("JAR_NAME=${appName}")
commandArgs.add("--build-arg")
commandArgs.add("VERSION=${project.version}")
for (String tag : getTags(appName)) {
commandArgs.add("-t")
commandArgs.add(tag)
}
commandArgs.add(".")

commandLine commandArgs
}

task dockerLogout(type: Exec, group: "Docker", description: "Logout of docker hub") {
commandLine "docker", "logout"
}

task dockerLogin(type: Exec, group: "Docker", description: "Login to docker hub using DOCKER_USER and DOCKER_PASSWORD environment variables") {
dependsOn tasks.dockerLogout
commandLine "docker", "login", "-u", System.getenv("DOCKER_USER"), "-p", System.getenv("DOCKER_PASSWORD")
}

task dockerPush(group: "Docker", description: "Push the built docker image to Docker Hub") {
dependsOn tasks.dockerLogin, tasks.dockerBuildImage
onlyIf {
System.env."CI"
}
doLast {
def appName = jar.baseName.toString()
for (String tag : getTags(appName)) {
exec {
commandLine "docker", "push", tag
}
}
}
}
9 changes: 9 additions & 0 deletions genie-app/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from openjdk:8
MAINTAINER NetflixOSS <netflixoss@netflix.com>
ARG JAR_NAME
ARG VERSION
EXPOSE 8080
VOLUME /tmp
ADD ${JAR_NAME}-${VERSION}.jar /usr/local/bin/genie.jar
RUN sh -c "touch /usr/local/bin/genie.jar"
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/usr/local/bin/genie.jar"]
6 changes: 3 additions & 3 deletions gradle/buildViaTravis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
./gradlew build coveralls
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build snapshot coveralls publishGhPages
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build snapshot coveralls publishGhPages dockerPush
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
case "$TRAVIS_TAG" in
*-rc\.*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" candidate coveralls publishGhPages
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" candidate coveralls publishGhPages dockerPush
;;
*)
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" final coveralls publishGhPages
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" final coveralls publishGhPages dockerPush
;;
esac
else
Expand Down

0 comments on commit dedbaaa

Please sign in to comment.