Richard Felkl | 2c60d9b | 2018-02-12 12:25:03 +0100 | [diff] [blame] | 1 | /** |
| 2 | * |
| 3 | * Create Aptly patch |
| 4 | * |
| 5 | * Expected parameters: |
| 6 | * REPO_LIST - YAML with structure of repositories. |
| 7 | * Example: mcp-updates-2018.1-xenial: |
| 8 | * url: http://apt.mirantis.com/xenial |
| 9 | * keyurl: http://apt.mirantis.com/public.gpg |
| 10 | * distribution: nightly |
| 11 | * component: salt |
| 12 | * packages: all |
| 13 | * mcp-updates-2017.12-xenial: |
| 14 | * url: http://apt.mirantis.com/xenial |
| 15 | * distribution: "2017.12" |
| 16 | * component: salt |
| 17 | * insecure: true |
| 18 | * packages: |
| 19 | * - salt-formula-salt |
| 20 | * - salt-formula-nginx |
| 21 | * UPLOAD_URL - URL of an WebDAV used to upload the image after creating. |
| 22 | * PATCH_NAME - Name of file which will be uploaded to UPLOAD_URL. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | common = new com.mirantis.mk.Common() |
| 27 | img = null |
| 28 | timeout(time: 12, unit: 'HOURS') { |
| 29 | node(){ |
| 30 | try { |
| 31 | def reposYaml = readYaml text:"${REPO_LIST}" |
| 32 | def repos = reposYaml.values() |
| 33 | def insecure = "" |
| 34 | img = docker.image("ubuntu:xenial") |
| 35 | img.pull() |
| 36 | |
| 37 | img.inside("-u root:root --hostname=apt-mirror --ulimit nofile=4096:8192") { |
| 38 | stage("Create patch"){ |
| 39 | sh("apt-get update;apt-get install -y curl") |
| 40 | sh("mkdir -p ${PATCH_NAME}") |
| 41 | for(i = 0; i < reposYaml.size(); i++){ |
| 42 | repo = repos[i] |
| 43 | repoName = reposYaml.keySet()[i] |
| 44 | |
| 45 | sh("mkdir -p ${PATCH_NAME}/${repoName}") |
| 46 | sh("echo 'deb ${repo.url} ${repo.distribution} ${repo.component}' > /etc/apt/sources.list") |
| 47 | if(repo.keyurl != null){ |
| 48 | sh("curl -L ${repo.keyurl} | apt-key add -") |
| 49 | }else if(repo.insecure == true){ |
| 50 | insecure = "--allow-unauthenticated" |
| 51 | } |
| 52 | sh("apt-get clean") |
| 53 | sh("apt-get ${insecure} update") |
| 54 | if(repo.packages == "all"){ |
| 55 | sh("cd ${PATCH_NAME}/${repoName};curl -s -H 'User-Agent: Debian APT-HTTP/1.3' ${repo.url}/dists/${repo.distribution}/${repo.component}/binary-amd64/Packages | grep Package: | uniq | sed 's/^\\(Package: \\)*//' | grep -E '*' | xargs -n 1 apt-get -y ${insecure} download") |
| 56 | }else{ |
| 57 | for(pkg in repo.packages){ |
| 58 | sh("cd ${PATCH_NAME}/${repoName};apt-get -y ${insecure} download ${pkg}") |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | stage("Upload patch"){ |
| 64 | sh("tar -czvf ${PATCH_NAME}.tar.gz -C ${PATCH_NAME} .") |
| 65 | sh("curl ${SCRIPT_URL} --output aptly-add-packages.sh") |
| 66 | sh("cat aptly-add-packages.sh ${PATCH_NAME}.tar.gz > ${PATCH_NAME}.sh") |
| 67 | sh("curl -f -T ${PATCH_NAME}.sh ${UPLOAD_URL}") |
| 68 | sh("rm -rf ./*") |
| 69 | } |
| 70 | } |
| 71 | } catch (Throwable e) { |
| 72 | // If there was an error or exception thrown, the build failed |
| 73 | currentBuild.result = "FAILURE" |
| 74 | throw e |
| 75 | }finally{ |
| 76 | stage("Cleanup"){ |
| 77 | img.inside("-u root:root --hostname=apt-mirror --ulimit nofile=4096:8192") { |
| 78 | sh("rm -rf ./*") |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |