I'm using gradle to automate docker publishing and tagging. I currently have the following set of tasks:
task dockerTagLatest(type: Exec) {
description "Build a Docker image of the current version and tag it as 'latest'"
dependsOn 'docker'
group 'Publishing'
commandLine(['docker', 'tag', dockerImageName, dockerImageLatest])
}
task dockerPush(type: Exec, overwrite: true) {
description 'Push the Docker image of the current version to the internal Docker hub'
group 'Publishing'
mustRunAfter 'dockerTagLatest'
commandLine 'docker', 'push', dockerImageName
}
task dockerPushLatestTag(type: Exec) {
description "Push the 'latest' tag to the internal Docker hub"
group 'Publishing'
mustRunAfter 'dockerTagLatest'
commandLine 'docker', 'push', dockerImageLatest
}
task dockerPublish() {
description "Push the Docker image of the current version and the 'latest' tag to the internal Docker hub"
dependsOn 'dockerTagLatest'
dependsOn 'dockerPush'
dependsOn 'dockerPushLatestTag'
group 'Publishing'
}
Would it be better to have something like this?
task dockerPublish(type: Exec) {
commandLine 'bash', '-e', '-c', """
docker tag ...
docker push ...
docker push ...
"""
}
Obviously the second approach is not Windows friendly, but disregarding that for the moment, is it better to have a set of dependent Exec tasks, or to lump all of the command line commands into a single task? I've gotten feedback that the latter is more readable, but I think the first approach is more Gradle-like. Thoughts?