Denis Egorenko | 8c60655 | 2016-12-07 14:22:50 +0400 | [diff] [blame] | 1 | package com.mirantis.mcp |
| 2 | |
| 3 | /** |
| 4 | * Build Calico containers |
| 5 | * |
| 6 | * @param body Closure |
| 7 | * body includes next parameters: |
| 8 | * - dockerRepo String, repo with docker images |
| 9 | * - artifactoryUrl String, URL to repo with calico-binaries |
| 10 | * - imageTag String, tag of images |
| 11 | * - nodeImage String, Calico Node image name |
| 12 | * - ctlImage String, Calico CTL image name |
| 13 | * - buildImage String, Calico Build image name |
| 14 | * - felixImage String, Calico Felix image name |
| 15 | * - confdBuildId String, Version of Calico Confd |
| 16 | * - confdUrl String, URL to Calico Confd |
| 17 | * - birdUrl, URL to Calico Bird |
| 18 | * - birdBuildId, Version of Calico Bird |
| 19 | * - bird6Url, URL to Calico Bird6 |
| 20 | * - birdclUrl, URL to Calico BirdCL |
| 21 | * |
| 22 | * Usage example: |
| 23 | * |
| 24 | * def calicoFunc = new com.mirantis.mcp.Calico() |
| 25 | * calicoFunc.buildCalicoContainers { |
| 26 | * dockerRepo = 'mcp-k8s-ci.docker.mirantis.net' |
| 27 | * artifactoryURL = 'https://artifactory.mcp.mirantis.net/artifactory/sandbox' |
| 28 | * nodeImage = 'mcp-k8s-ci.docker.mirantis.net/calico/node' |
| 29 | * ctlImage = 'mcp-k8s-ci.docker.mirantis.net/calico/ctl' |
| 30 | * } |
| 31 | * |
| 32 | */ |
| 33 | def buildCalicoContainers = { body -> |
| 34 | // evaluate the body block, and collect configuration into the object |
| 35 | def config = [:] |
| 36 | body.resolveStrategy = Closure.DELEGATE_FIRST |
| 37 | body.delegate = config |
| 38 | body() |
| 39 | |
| 40 | |
| 41 | def dockerRepo = config.dockerRepo |
| 42 | def projectNamespace = "mirantis/projectcalico" |
| 43 | def artifactoryUrl = config.artifactoryURL |
| 44 | |
| 45 | if (! dockerRepo ) { |
| 46 | error('dockerRepo parameter have to be set.') |
| 47 | } |
| 48 | |
| 49 | if (! artifactoryUrl ) { |
| 50 | error('artifactoryUrl parameter have to be set.') |
| 51 | } |
| 52 | |
| 53 | def imgTag = config.imageTag ?: getGitDescribe(true) + "-" + getDatetime() |
| 54 | |
| 55 | def nodeImage = config.nodeImage ?: "${dockerRepo}/${projectNamespace}/calico/node" |
| 56 | def nodeName = "${nodeImage}:${imgTag}" |
| 57 | |
| 58 | def ctlImage = config.ctlImage ?: "${dockerRepo}/${projectNamespace}/calico/ctl" |
| 59 | def ctlName = "${ctlImage}:${imgTag}" |
| 60 | |
| 61 | // calico/build goes from libcalico |
| 62 | def buildImage = config.buildImage ?: "${dockerRepo}/${projectNamespace}/calico/build:latest" |
| 63 | // calico/felix goes from felix |
| 64 | def felixImage = config.felixImage ?: "${dockerRepo}/${projectNamespace}/calico/felix:latest" |
| 65 | |
| 66 | def confdBuildId = config.confdBuildId ?: "${artifactoryUrl}/${projectNamespace}/confd/latest".toURL().text.trim() |
| 67 | def confdUrl = config.confdUrl ?: "${artifactoryUrl}/${projectNamespace}/confd/confd-${confdBuildId}" |
| 68 | |
| 69 | def birdBuildId = config.birdBuildId ?: "${artifactoryUrl}/${projectNamespace}/bird/latest".toURL().text.trim() |
| 70 | def birdUrl = config.birdUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/bird-${birdBuildId}" |
| 71 | def bird6Url = config.bird6Url ?: "${artifactoryUrl}/${projectNamespace}/bird/bird6-${birdBuildId}" |
| 72 | def birdclUrl = config.birdclUrl ?: "${artifactoryUrl}/${projectNamespace}/bird/birdcl-${birdBuildId}" |
| 73 | |
| 74 | // add LABELs to dockerfiles |
Denis Egorenko | 2bc8917 | 2016-12-21 17:31:19 +0400 | [diff] [blame] | 75 | def docker = new com.mirantis.mcp.Docker() |
| 76 | docker.setDockerfileLabels("./calicoctl/Dockerfile.calicoctl", |
| 77 | ["docker.imgTag=${imgTag}", |
| 78 | "calico.buildImage=${buildImage}", |
| 79 | "calico.birdclUrl=${birdclUrl}"]) |
Denis Egorenko | 8c60655 | 2016-12-07 14:22:50 +0400 | [diff] [blame] | 80 | |
Denis Egorenko | 2bc8917 | 2016-12-21 17:31:19 +0400 | [diff] [blame] | 81 | docker.setDockerfileLabels("./calico_node/Dockerfile", |
| 82 | ["docker.imgTag=${imgTag}", |
| 83 | "calico.buildImage=${buildImage}", |
| 84 | "calico.felixImage=${felixImage}", |
| 85 | "calico.confdUrl=${confdUrl}", |
| 86 | "calico.birdUrl=${birdUrl}", |
| 87 | "calico.bird6Url=${bird6Url}", |
| 88 | "calico.birdclUrl=${birdclUrl}"]) |
Denis Egorenko | 8c60655 | 2016-12-07 14:22:50 +0400 | [diff] [blame] | 89 | |
| 90 | // Start build section |
| 91 | stage ('Build calico/ctl image'){ |
| 92 | sh """ |
| 93 | make calico/ctl \ |
| 94 | CTL_CONTAINER_NAME=${ctlName} \ |
| 95 | PYTHON_BUILD_CONTAINER_NAME=${buildImage} \ |
| 96 | BIRDCL_URL=${birdclUrl} |
| 97 | """ |
| 98 | } |
| 99 | |
| 100 | |
| 101 | stage('Build calico/node'){ |
| 102 | sh """ |
| 103 | make calico/node \ |
| 104 | NODE_CONTAINER_NAME=${nodeName} \ |
| 105 | PYTHON_BUILD_CONTAINER_NAME=${buildImage} \ |
| 106 | FELIX_CONTAINER_NAME=${felixImage} \ |
| 107 | CONFD_URL=${confdUrl} \ |
| 108 | BIRD_URL=${birdUrl} \ |
| 109 | BIRD6_URL=${bird6Url} \ |
| 110 | BIRDCL_URL=${birdclUrl} |
| 111 | """ |
| 112 | } |
| 113 | |
| 114 | |
| 115 | return [ |
| 116 | CTL_CONTAINER_NAME:"${ctlName}", |
| 117 | NODE_CONTAINER_NAME:"${nodeName}", |
| 118 | CALICO_NODE_IMAGE_REPO:"${nodeImage}", |
| 119 | CALICOCTL_IMAGE_REPO:"${ctlImage}", |
| 120 | CALICO_VERSION: "${imgTag}" |
| 121 | ] |
| 122 | |
| 123 | } |