Last active
February 17, 2017 10:25
-
-
Save kolov/454596c5497caf8e400805020e8de6fa to your computer and use it in GitHub Desktop.
Tag and push an image created by gradle-docker to an alternative repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Will tag an push if the property 'dockerRepository' is defined | |
task buildDocker(type: Docker) { | |
push = false | |
applicationName = 'curriculi-service-users' | |
dockerfile = file('src/main/docker/Dockerfile') | |
doFirst { | |
copy { | |
from jar | |
into stageDir | |
} | |
} | |
doLast { | |
tagTask(project.group, applicationName, version, true).execute() | |
} | |
} | |
def tagTask(group, applicationName, version, push) { | |
if (project.hasProperty('dockerRepository')) { | |
def dockerRepository = project.dockerRepository | |
def existingTag = "$group/$applicationName:$version" | |
def toCreateTag = "$dockerRepository/$group/$applicationName:latest" | |
return tasks.create("tag${applicationName}Image", Exec) { | |
println("Creating tag $toCreateTag from $existingTag") | |
commandLine 'docker', 'tag', | |
"$existingTag", | |
"$toCreateTag" | |
if (push) { | |
println("Pushing $toCreateTag ") | |
commandLine 'docker', 'push', "$toCreateTag" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment