Skip to content

Instantly share code, notes, and snippets.

@kolov
Last active February 17, 2017 10:25
Show Gist options
  • Save kolov/454596c5497caf8e400805020e8de6fa to your computer and use it in GitHub Desktop.
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
// 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