blob: 7786ec3e0f2a3c47ec6297474c0547f0e4b4f11a [file] [log] [blame]
Zsolt Haraszti2a792f62016-05-12 17:49:02 -07001/*
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
17ext {
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
29task buildFooImage(type: Exec) {
30 commandLine '/usr/bin/docker', 'build', '-t', "foo", "./foo"
31}
32
33task tagFooImage(type: Exec) {
34 commandLine '/usr/bin/docker', 'tag', 'foo', "$targetReg/foo:$targetTag"
35}
36
37task publishFooImage(type: Exec) {
38 dependsOn tagFooImage
39 commandLine '/usr/bin/docker', 'push', "$targetReg/foo:$targetTag"
40}
41
42task buildBarImage(type: Exec) {
43 commandLine '/usr/bin/docker', 'build', '-t', "bar", "./bar"
44}
45
46task tagBarImage(type: Exec) {
47 commandLine '/usr/bin/docker', 'tag', 'bar', "$targetReg/bar:$targetTag"
48}
49
50task publishBarImage(type: Exec) {
51 dependsOn tagBarImage
Zsolt Harasztic73976c2016-05-12 18:26:26 -070052 commandLine '/usr/bin/docker', 'push', "$targetReg/bar:$targetTag"
Zsolt Haraszti2a792f62016-05-12 17:49:02 -070053}
54
55// ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~
56
57// To be used to fetch upstream binaries, clone repos, etc.
58task 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.
66task buildImages {
67 dependsOn buildFooImage
68 dependsOn buildBarImage
69 println "This is where we build the docker images for MAAS"
70}
71
72task publish {
73 // this is where we publish the properly tagged image into the target registry
74 dependsOn publishFooImage
75 dependsOn publishBarImage
76}