Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 the original author or authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | ext { |
| 18 | |
| 19 | // Target registry to be used to publish docker images needed for deployment |
| 20 | targetReg = project.hasProperty('targetReg') ? project.getProperty('targetReg') : 'localhost:5000' |
| 21 | |
| 22 | // The tag used to tag the docker images push to the target registry |
| 23 | targetTag = project.hasProperty('targetTag') ? project.getProperty('targetTag') : 'candidate' |
| 24 | |
| 25 | } |
| 26 | |
| 27 | // ~~~~~~~~~~~~~~~~~ Example helper tasks ~~~~~~~~~~~~~~~~~~~~ |
| 28 | |
| 29 | task buildFooImage(type: Exec) { |
| 30 | commandLine '/usr/bin/docker', 'build', '-t', "foo", "./foo" |
| 31 | } |
| 32 | |
| 33 | task tagFooImage(type: Exec) { |
| 34 | commandLine '/usr/bin/docker', 'tag', 'foo', "$targetReg/foo:$targetTag" |
| 35 | } |
| 36 | |
| 37 | task publishFooImage(type: Exec) { |
| 38 | dependsOn tagFooImage |
| 39 | commandLine '/usr/bin/docker', 'push', "$targetReg/foo:$targetTag" |
| 40 | } |
| 41 | |
| 42 | task buildBarImage(type: Exec) { |
| 43 | commandLine '/usr/bin/docker', 'build', '-t', "bar", "./bar" |
| 44 | } |
| 45 | |
| 46 | task tagBarImage(type: Exec) { |
| 47 | commandLine '/usr/bin/docker', 'tag', 'bar', "$targetReg/bar:$targetTag" |
| 48 | } |
| 49 | |
| 50 | task publishBarImage(type: Exec) { |
| 51 | dependsOn tagBarImage |
Zsolt Haraszti | c73976c | 2016-05-12 18:26:26 -0700 | [diff] [blame] | 52 | commandLine '/usr/bin/docker', 'push', "$targetReg/bar:$targetTag" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 56 | |
| 57 | // To be used to fetch upstream binaries, clone repos, etc. |
| 58 | task fetch(type: Exec) { |
| 59 | // this is where we fetch upstream artifacts that we do not need internet for the build phase" |
| 60 | // Placeholdr example: |
| 61 | commandLine "/usr/bin/docker", "pull", "golang:alpine" |
| 62 | } |
| 63 | |
| 64 | // To be used to generate all needed binaries that need to be present on the target |
| 65 | // as docker images in the local docker runner. |
| 66 | task buildImages { |
| 67 | dependsOn buildFooImage |
| 68 | dependsOn buildBarImage |
| 69 | println "This is where we build the docker images for MAAS" |
| 70 | } |
| 71 | |
| 72 | task publish { |
| 73 | // this is where we publish the properly tagged image into the target registry |
| 74 | dependsOn publishFooImage |
| 75 | dependsOn publishBarImage |
| 76 | } |