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 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 27 | task buildBootstrapImage(type: Exec) { |
| 28 | commandLine '/usr/bin/docker', 'build', '-t', 'cord-maas-bootstrap', './bootstrap' |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 29 | } |
| 30 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 31 | task tagBootstrapImage(type: Exec) { |
| 32 | dependsOn buildBootstrapImage |
| 33 | commandLine '/usr/bin/docker', 'tag', 'cord-maas-bootstrap', "$targetReg/cord-maas-bootstrap:$targetTag" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 34 | } |
| 35 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 36 | task publishBootstrapImage(type: Exec) { |
| 37 | dependsOn tagBootstrapImage |
| 38 | commandLine '/usr/bin/docker', 'push', "$targetReg/cord-maas-bootstrap:$targetTag" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 39 | } |
| 40 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 41 | task buildAutomationImage(type: Exec) { |
| 42 | commandLine '/usr/bin/docker', 'build', '-t', "cord-maas-automation", "./automation" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 43 | } |
| 44 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 45 | task tagAutomationImage(type: Exec) { |
| 46 | dependsOn buildAutomationImage |
| 47 | commandLine '/usr/bin/docker', 'tag', 'cord-maas-automation', "$targetReg/cord-maas-automation:$targetTag" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 48 | } |
| 49 | |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 50 | task publishAutomationImage(type: Exec) { |
| 51 | dependsOn tagAutomationImage |
| 52 | commandLine '/usr/bin/docker', 'push', "$targetReg/cord-maas-automation:$targetTag" |
| 53 | } |
| 54 | |
| 55 | task buildHarvesterImage(type: Exec) { |
| 56 | commandLine '/usr/bin/docker', 'build', '-t', "cord-maas-dhcp-harvester", "./harvester" |
| 57 | } |
| 58 | |
| 59 | task tagHarvesterImage(type: Exec) { |
| 60 | dependsOn buildHarvesterImage |
| 61 | commandLine '/usr/bin/docker', 'tag', 'cord-maas-dhcp-harvester', "$targetReg/cord-maas-dhcp-harvester:$targetTag" |
| 62 | } |
| 63 | |
| 64 | task publishHarvesterImage(type: Exec) { |
| 65 | dependsOn tagHarvesterImage |
| 66 | commandLine '/usr/bin/docker', 'push', "$targetReg/cord-maas-dhcp-harvester:$targetTag" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // ~~~~~~~~~~~~~~~~~~~ Global tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 | |
| 71 | // To be used to fetch upstream binaries, clone repos, etc. |
| 72 | task fetch(type: Exec) { |
| 73 | // this is where we fetch upstream artifacts that we do not need internet for the build phase" |
| 74 | // Placeholdr example: |
| 75 | commandLine "/usr/bin/docker", "pull", "golang:alpine" |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 76 | commandLine "/usr/bin/docker", "pull", "python:2.7-alpine" |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // To be used to generate all needed binaries that need to be present on the target |
| 80 | // as docker images in the local docker runner. |
| 81 | task buildImages { |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 82 | dependsOn buildBootstrapImage |
| 83 | dependsOn buildHarvesterImage |
| 84 | dependsOn buildAutomationImage |
| 85 | } |
| 86 | |
| 87 | task tagImages { |
| 88 | dependsOn tagBootstrapImage |
| 89 | dependsOn tagHarvesterImage |
| 90 | dependsOn tagAutomationImage |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | task publish { |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 94 | dependsOn publishBootstrapImage |
| 95 | dependsOn publishHarvesterImage |
| 96 | dependsOn publishAutomationImage |
Zsolt Haraszti | 2a792f6 | 2016-05-12 17:49:02 -0700 | [diff] [blame] | 97 | } |
David K. Bainbridge | b541504 | 2016-05-13 17:06:10 -0700 | [diff] [blame] | 98 | |
| 99 | // ~~~~~~~~~~~~~~~~~~~ Deployment / Test Tasks ~~~~~~~~~~~~~~~~~~~~~~~ |
| 100 | |
| 101 | // This task will invoke the ansible configuration on the vagrant head node. The ansible deployment is |
| 102 | // executed remotely to the head node as this is a more realistic scenario for a production deployment. |
| 103 | // The assumption is that this task is executed from the maasdev virtual machine as it access the head |
| 104 | // node virtual box over a private network. |
| 105 | // |
| 106 | // TODO: Currently the deployment of the head node does not use the locally built docker containers, it |
| 107 | // should be modified to do so. This likely means that we need to configure docker on the head node |
| 108 | // to access the docker registry on the maasdev virtual box. |
| 109 | task deployMaas(type: Exec) { |
| 110 | commandLine '/usr/bin/ansible-playbook', '-i', '10.100.198.202,', '--skip-tags=switch_support,interface_config', 'dev-head-node.yml' |
| 111 | } |
| 112 | |