| /* |
| * Copyright 2012 the original author or authors. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| ext { |
| |
| // Target registry to be used to publish docker images needed for deployment |
| targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000' |
| |
| // The tag used to tag the docker images push to the target registry |
| targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate' |
| |
| } |
| |
| // ~~~~~~~~~~~~~~~~~ Example helper tasks ~~~~~~~~~~~~~~~~~~~~ |
| |
| task buildFooImage(type: Exec) { |
| commandLine '/usr/bin/docker', 'build', '-t', "foo", "./foo" |
| } |
| |
| task tagFooImage(type: Exec) { |
| commandLine '/usr/bin/docker', 'tag', 'foo', "$targetReg/foo:$targetTag" |
| } |
| |
| task publishFooImage(type: Exec) { |
| dependsOn tagFooImage |
| commandLine '/usr/bin/docker', 'push', "$targetReg/foo:$targetTag" |
| } |
| |
| task buildBarImage(type: Exec) { |
| commandLine '/usr/bin/docker', 'build', '-t', "bar", "./bar" |
| } |
| |
| task tagBarImage(type: Exec) { |
| commandLine '/usr/bin/docker', 'tag', 'bar', "$targetReg/bar:$targetTag" |
| } |
| |
| task publishBarImage(type: Exec) { |
| dependsOn tagBarImage |
| commandLine '/usr/bin/docker', 'push', "$targetReg/bar:$targetTag" |
| } |
| |
| // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| |
| // To be used to fetch upstream binaries, clone repos, etc. |
| task fetch(type: Exec) { |
| // this is where we fetch upstream artifacts that we do not need internet for the build phase" |
| // Placeholdr example: |
| commandLine "/usr/bin/docker", "pull", "golang:alpine" |
| } |
| |
| // To be used to generate all needed binaries that need to be present on the target |
| // as docker images in the local docker runner. |
| task buildImages { |
| dependsOn buildFooImage |
| dependsOn buildBarImage |
| println "This is where we build the docker images for MAAS" |
| } |
| |
| task publish { |
| // this is where we publish the properly tagged image into the target registry |
| dependsOn publishFooImage |
| dependsOn publishBarImage |
| } |