github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/registryv1/builds_test.go (about) 1 package registryv1 2 3 import ( 4 "archive/tar" 5 "bufio" 6 "bytes" 7 "compress/gzip" 8 "encoding/json" 9 "io" 10 "io/ioutil" 11 "log" 12 "net/http" 13 "strings" 14 15 ibmcloud "github.com/IBM-Cloud/bluemix-go" 16 "github.com/IBM-Cloud/bluemix-go/client" 17 ibmcloudHttp "github.com/IBM-Cloud/bluemix-go/http" 18 "github.com/IBM-Cloud/bluemix-go/session" 19 20 "github.com/onsi/gomega/ghttp" 21 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 ) 25 26 const ( 27 dockerfileName = "Dockerfile" 28 dockerfile = `FROM golang:1.7-alpine3.6 29 30 ARG JQ_VERSION=jq-1.5 31 RUN apk update 32 RUN apk add build-base git bash 33 ADD https://github.com/stedolan/jq/releases/download/${JQ_VERSION}/jq-linux64 /tmp` 34 35 buildResult = `{"stream":"Step 1/5 : FROM golang:1.7-alpine3.6\n"} 36 {"stream":" ---\u003e 0cf3d3497ae9\n"} 37 {"stream":"Step 2/5 : ARG JQ_VERSION=jq-1.5\n"} 38 {"stream":" ---\u003e Running in 1423169fe389\n"} 39 {"stream":" ---\u003e 28032d919806\n"} 40 {"stream":"Removing intermediate container 1423169fe389\n"} 41 {"stream":"Step 3/5 : RUN apk update\n"} 42 {"stream":" ---\u003e Running in 3be23ccfacb4\n"} 43 {"stream":"fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz\n"} 44 {"stream":"fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz\n"} 45 {"stream":"v3.6.3-20-g059e2ef678 [http://dl-cdn.alpinelinux.org/alpine/v3.6/main]\nv3.6.3-21-g0a5db24a90 [http://dl-cdn.alpinelinux.org/alpine/v3.6/community]\nOK: 8445 distinct packages available\n"} 46 {"stream":" ---\u003e 1eb8d32cae96\n"} 47 {"stream":"Removing intermediate container 3be23ccfacb4\n"} 48 {"stream":"Step 4/5 : RUN apk add build-base git bash\n"} 49 {"stream":" ---\u003e Running in 723a2e9f277a\n"} 50 {"stream":"(1/30) Upgrading musl (1.1.16-r10 -\u003e 1.1.16-r14)\n"} 51 {"stream":"(2/30) Installing ncurses-terminfo-base (6.0_p20171125-r1)\n"} 52 {"stream":"(3/30) Installing ncurses-terminfo (6.0_p20171125-r1)\n"} 53 {"stream":"(4/30) Installing ncurses-libs (6.0_p20171125-r1)\n"} 54 {"stream":"(5/30) Installing readline (6.3.008-r5)\n"} 55 {"stream":"(6/30) Installing bash (4.3.48-r1)\n"} 56 {"stream":"Executing bash-4.3.48-r1.post-install\n"} 57 {"stream":"(7/30) Installing binutils-libs (2.30-r1)\n"} 58 {"stream":"(8/30) Installing binutils (2.30-r1)\n"} 59 {"stream":"(9/30) Installing gmp (6.1.2-r0)\n"} 60 {"stream":"(10/30) Installing isl (0.17.1-r0)\n"} 61 {"stream":"(11/30) Installing libgomp (6.3.0-r4)\n"} 62 {"stream":"(12/30) Installing libatomic (6.3.0-r4)\n"} 63 {"stream":"(13/30) Installing pkgconf (1.3.7-r0)\n"} 64 {"stream":"(14/30) Installing libgcc (6.3.0-r4)\n"} 65 {"stream":"(15/30) Installing mpfr3 (3.1.5-r0)\n"} 66 {"stream":"(16/30) Installing mpc1 (1.0.3-r0)\n"} 67 {"stream":"(17/30) Installing libstdc++ (6.3.0-r4)\n"} 68 {"stream":"(18/30) Installing gcc (6.3.0-r4)\n"} 69 {"stream":"(19/30) Installing musl-dev (1.1.16-r14)\n"} 70 {"stream":"(20/30) Installing libc-dev (0.7.1-r0)\n"} 71 {"stream":"(21/30) Installing g++ (6.3.0-r4)\n"} 72 {"stream":"(22/30) Installing make (4.2.1-r0)\n"} 73 {"stream":"(23/30) Installing fortify-headers (0.8-r0)\n"} 74 {"stream":"(24/30) Installing build-base (0.5-r0)\n"} 75 {"stream":"(25/30) Installing libssh2 (1.8.0-r1)\n"} 76 {"stream":"(26/30) Installing libcurl (7.61.1-r0)\n"} 77 {"stream":"(27/30) Installing expat (2.2.0-r1)\n"} 78 {"stream":"(28/30) Installing pcre (8.41-r0)\n"} 79 {"stream":"(29/30) Installing git (2.13.7-r0)\n"} 80 {"stream":"(30/30) Upgrading musl-utils (1.1.16-r10 -\u003e 1.1.16-r14)\n"} 81 {"stream":"Executing busybox-1.26.2-r5.trigger\n"} 82 {"stream":"OK: 190 MiB in 40 packages\n"} 83 {"stream":" ---\u003e 7a5a01b469dd\n"} 84 {"stream":"Removing intermediate container 723a2e9f277a\n"} 85 {"stream":"Step 5/5 : ADD https://github.com/stedolan/jq/releases/download/${JQ_VERSION}/jq-linux64 /tmp\n"} 86 {"status":"Downloading","progressDetail":{"current":33339,"total":3027945},"progress":"[\u003e ] 33.34kB/3.028MB"} 87 {"status":"Downloading","progressDetail":{"current":451131,"total":3027945},"progress":"[=======\u003e ] 451.1kB/3.028MB"} 88 {"status":"Downloading","progressDetail":{"current":3027945,"total":3027945},"progress":"[==================================================\u003e] 3.028MB/3.028MB"} 89 {"stream":"\n"} 90 {"stream":" ---\u003e c8763987f48f\n"} 91 {"aux":{"ID":"sha256:c8763987f48f13fb23ec84dded2b241b79149548ab10e051dc96b772b9c212a7"}} 92 {"stream":"Successfully built c8763987f48f\n"} 93 {"stream":"Successfully tagged registry.ng.bluemix.net/bkuschel/testimage:latest\n"} 94 {"status":"The push refers to a repository [registry.ng.bluemix.net/bkuschel/testimage]"} 95 {"status":"Preparing","progressDetail":{},"id":"54bdabef2225"} 96 {"status":"Preparing","progressDetail":{},"id":"360ebdf19ecf"} 97 {"status":"Preparing","progressDetail":{},"id":"8e69d607c320"} 98 {"status":"Preparing","progressDetail":{},"id":"e5b65e634c73"} 99 {"status":"Preparing","progressDetail":{},"id":"afc52f56690e"} 100 {"status":"Preparing","progressDetail":{},"id":"e454a04d0a3e"} 101 {"status":"Preparing","progressDetail":{},"id":"fc3d79f9e82c"} 102 {"status":"Preparing","progressDetail":{},"id":"069301b5b9f1"} 103 {"status":"Preparing","progressDetail":{},"id":"5bef08742407"} 104 {"status":"Waiting","progressDetail":{},"id":"e454a04d0a3e"} 105 {"status":"Waiting","progressDetail":{},"id":"fc3d79f9e82c"} 106 {"status":"Waiting","progressDetail":{},"id":"069301b5b9f1"} 107 {"status":"Waiting","progressDetail":{},"id":"5bef08742407"} 108 {"status":"Layer already exists","progressDetail":{},"id":"afc52f56690e"} 109 {"status":"Layer already exists","progressDetail":{},"id":"e5b65e634c73"} 110 {"status":"Pushing","progressDetail":{"current":33792,"total":3027945},"progress":"[\u003e ] 33.79kB/3.028MB","id":"54bdabef2225"} 111 {"status":"Pushing","progressDetail":{"current":36864,"total":1102904},"progress":"[=\u003e ] 36.86kB/1.103MB","id":"8e69d607c320"} 112 {"status":"Layer already exists","progressDetail":{},"id":"fc3d79f9e82c"} 113 {"status":"Pushing","progressDetail":{"current":525312,"total":173229523},"progress":"[\u003e ] 525.3kB/173.2MB","id":"360ebdf19ecf"} 114 {"status":"Layer already exists","progressDetail":{},"id":"e454a04d0a3e"} 115 {"status":"Pushing","progressDetail":{"current":1108992,"total":1102904},"progress":"[==================================================\u003e] 1.109MB","id":"8e69d607c320"} 116 {"status":"Pushing","progressDetail":{"current":1246208,"total":3027945},"progress":"[====================\u003e ] 1.246MB/3.028MB","id":"54bdabef2225"} 117 {"status":"Layer already exists","progressDetail":{},"id":"069301b5b9f1"} 118 {"status":"Layer already exists","progressDetail":{},"id":"5bef08742407"} 119 {"status":"Pushing","progressDetail":{"current":2589696,"total":3027945},"progress":"[==========================================\u003e ] 2.59MB/3.028MB","id":"54bdabef2225"} 120 {"status":"Pushing","progressDetail":{"current":2166272,"total":173229523},"progress":"[\u003e ] 2.166MB/173.2MB","id":"360ebdf19ecf"} 121 {"status":"Pushing","progressDetail":{"current":3030016,"total":3027945},"progress":"[==================================================\u003e] 3.03MB","id":"54bdabef2225"} 122 {"status":"Pushing","progressDetail":{"current":4338688,"total":173229523},"progress":"[=\u003e ] 4.339MB/173.2MB","id":"360ebdf19ecf"} 123 {"status":"Pushing","progressDetail":{"current":5999616,"total":173229523},"progress":"[=\u003e ] 6MB/173.2MB","id":"360ebdf19ecf"} 124 {"status":"Pushing","progressDetail":{"current":7622656,"total":173229523},"progress":"[==\u003e ] 7.623MB/173.2MB","id":"360ebdf19ecf"} 125 {"status":"Pushing","progressDetail":{"current":9250816,"total":173229523},"progress":"[==\u003e ] 9.251MB/173.2MB","id":"360ebdf19ecf"} 126 {"status":"Pushed","progressDetail":{},"id":"8e69d607c320"} 127 {"status":"Pushing","progressDetail":{"current":10364928,"total":173229523},"progress":"[==\u003e ] 10.36MB/173.2MB","id":"360ebdf19ecf"} 128 {"status":"Pushed","progressDetail":{},"id":"54bdabef2225"} 129 {"status":"Pushing","progressDetail":{"current":11465728,"total":173229523},"progress":"[===\u003e ] 11.47MB/173.2MB","id":"360ebdf19ecf"} 130 {"status":"Pushing","progressDetail":{"current":13095424,"total":173229523},"progress":"[===\u003e ] 13.1MB/173.2MB","id":"360ebdf19ecf"} 131 {"status":"Pushing","progressDetail":{"current":15811072,"total":173229523},"progress":"[====\u003e ] 15.81MB/173.2MB","id":"360ebdf19ecf"} 132 {"status":"Pushing","progressDetail":{"current":17427291,"total":173229523},"progress":"[=====\u003e ] 17.43MB/173.2MB","id":"360ebdf19ecf"} 133 {"status":"Pushing","progressDetail":{"current":19612160,"total":173229523},"progress":"[=====\u003e ] 19.61MB/173.2MB","id":"360ebdf19ecf"} 134 {"status":"Pushing","progressDetail":{"current":21743658,"total":173229523},"progress":"[======\u003e ] 21.74MB/173.2MB","id":"360ebdf19ecf"} 135 {"status":"Pushing","progressDetail":{"current":23860185,"total":173229523},"progress":"[======\u003e ] 23.86MB/173.2MB","id":"360ebdf19ecf"} 136 {"status":"Pushing","progressDetail":{"current":25434293,"total":173229523},"progress":"[=======\u003e ] 25.43MB/173.2MB","id":"360ebdf19ecf"} 137 {"status":"Pushing","progressDetail":{"current":26485290,"total":173229523},"progress":"[=======\u003e ] 26.49MB/173.2MB","id":"360ebdf19ecf"} 138 {"status":"Pushing","progressDetail":{"current":28063323,"total":173229523},"progress":"[========\u003e ] 28.06MB/173.2MB","id":"360ebdf19ecf"} 139 {"status":"Pushing","progressDetail":{"current":29112723,"total":173229523},"progress":"[========\u003e ] 29.11MB/173.2MB","id":"360ebdf19ecf"} 140 {"status":"Pushing","progressDetail":{"current":30162944,"total":173229523},"progress":"[========\u003e ] 30.16MB/173.2MB","id":"360ebdf19ecf"} 141 {"status":"Pushing","progressDetail":{"current":31212257,"total":173229523},"progress":"[=========\u003e ] 31.21MB/173.2MB","id":"360ebdf19ecf"} 142 {"status":"Pushing","progressDetail":{"current":32786627,"total":173229523},"progress":"[=========\u003e ] 32.79MB/173.2MB","id":"360ebdf19ecf"} 143 {"status":"Pushing","progressDetail":{"current":34936132,"total":173229523},"progress":"[==========\u003e ] 34.94MB/173.2MB","id":"360ebdf19ecf"} 144 {"status":"Pushing","progressDetail":{"current":36571136,"total":173229523},"progress":"[==========\u003e ] 36.57MB/173.2MB","id":"360ebdf19ecf"} 145 {"status":"Pushing","progressDetail":{"current":39271936,"total":173229523},"progress":"[===========\u003e ] 39.27MB/173.2MB","id":"360ebdf19ecf"} 146 {"status":"Pushing","progressDetail":{"current":40943104,"total":173229523},"progress":"[===========\u003e ] 40.94MB/173.2MB","id":"360ebdf19ecf"} 147 {"status":"Pushing","progressDetail":{"current":43131480,"total":173229523},"progress":"[============\u003e ] 43.13MB/173.2MB","id":"360ebdf19ecf"} 148 {"status":"Pushing","progressDetail":{"current":44725320,"total":173229523},"progress":"[============\u003e ] 44.73MB/173.2MB","id":"360ebdf19ecf"} 149 {"status":"Pushing","progressDetail":{"current":46927360,"total":173229523},"progress":"[=============\u003e ] 46.93MB/173.2MB","id":"360ebdf19ecf"} 150 {"status":"Pushing","progressDetail":{"current":48524496,"total":173229523},"progress":"[==============\u003e ] 48.52MB/173.2MB","id":"360ebdf19ecf"} 151 {"status":"Pushing","progressDetail":{"current":50132480,"total":173229523},"progress":"[==============\u003e ] 50.13MB/173.2MB","id":"360ebdf19ecf"} 152 {"status":"Pushing","progressDetail":{"current":51774976,"total":173229523},"progress":"[==============\u003e ] 51.77MB/173.2MB","id":"360ebdf19ecf"} 153 {"status":"Pushing","progressDetail":{"current":53446144,"total":173229523},"progress":"[===============\u003e ] 53.45MB/173.2MB","id":"360ebdf19ecf"} 154 {"status":"Pushing","progressDetail":{"current":55117312,"total":173229523},"progress":"[===============\u003e ] 55.12MB/173.2MB","id":"360ebdf19ecf"} 155 {"status":"Pushing","progressDetail":{"current":56788480,"total":173229523},"progress":"[================\u003e ] 56.79MB/173.2MB","id":"360ebdf19ecf"} 156 {"status":"Pushing","progressDetail":{"current":58459648,"total":173229523},"progress":"[================\u003e ] 58.46MB/173.2MB","id":"360ebdf19ecf"} 157 {"status":"Pushing","progressDetail":{"current":60130816,"total":173229523},"progress":"[=================\u003e ] 60.13MB/173.2MB","id":"360ebdf19ecf"} 158 {"status":"Pushing","progressDetail":{"current":61772288,"total":173229523},"progress":"[=================\u003e ] 61.77MB/173.2MB","id":"360ebdf19ecf"} 159 {"status":"Pushing","progressDetail":{"current":63387648,"total":173229523},"progress":"[==================\u003e ] 63.39MB/173.2MB","id":"360ebdf19ecf"} 160 {"status":"Pushing","progressDetail":{"current":64472064,"total":173229523},"progress":"[==================\u003e ] 64.47MB/173.2MB","id":"360ebdf19ecf"} 161 {"status":"Pushing","progressDetail":{"current":66118656,"total":173229523},"progress":"[===================\u003e ] 66.12MB/173.2MB","id":"360ebdf19ecf"} 162 {"status":"Pushing","progressDetail":{"current":68294144,"total":173229523},"progress":"[===================\u003e ] 68.29MB/173.2MB","id":"360ebdf19ecf"} 163 {"status":"Pushing","progressDetail":{"current":69965312,"total":173229523},"progress":"[====================\u003e ] 69.97MB/173.2MB","id":"360ebdf19ecf"} 164 {"status":"Pushing","progressDetail":{"current":71636480,"total":173229523},"progress":"[====================\u003e ] 71.64MB/173.2MB","id":"360ebdf19ecf"} 165 {"status":"Pushing","progressDetail":{"current":73307648,"total":173229523},"progress":"[=====================\u003e ] 73.31MB/173.2MB","id":"360ebdf19ecf"} 166 {"status":"Pushing","progressDetail":{"current":74978816,"total":173229523},"progress":"[=====================\u003e ] 74.98MB/173.2MB","id":"360ebdf19ecf"} 167 {"status":"Pushing","progressDetail":{"current":76649984,"total":173229523},"progress":"[======================\u003e ] 76.65MB/173.2MB","id":"360ebdf19ecf"} 168 {"status":"Pushing","progressDetail":{"current":78321152,"total":173229523},"progress":"[======================\u003e ] 78.32MB/173.2MB","id":"360ebdf19ecf"} 169 {"status":"Pushing","progressDetail":{"current":79992320,"total":173229523},"progress":"[=======================\u003e ] 79.99MB/173.2MB","id":"360ebdf19ecf"} 170 {"status":"Pushing","progressDetail":{"current":81645056,"total":173229523},"progress":"[=======================\u003e ] 81.65MB/173.2MB","id":"360ebdf19ecf"} 171 {"status":"Pushing","progressDetail":{"current":83311104,"total":173229523},"progress":"[========================\u003e ] 83.31MB/173.2MB","id":"360ebdf19ecf"} 172 {"status":"Pushing","progressDetail":{"current":84982272,"total":173229523},"progress":"[========================\u003e ] 84.98MB/173.2MB","id":"360ebdf19ecf"} 173 {"status":"Pushing","progressDetail":{"current":86639616,"total":173229523},"progress":"[=========================\u003e ] 86.64MB/173.2MB","id":"360ebdf19ecf"} 174 {"status":"Pushing","progressDetail":{"current":87745536,"total":173229523},"progress":"[=========================\u003e ] 87.75MB/173.2MB","id":"360ebdf19ecf"} 175 {"status":"Pushing","progressDetail":{"current":89416704,"total":173229523},"progress":"[=========================\u003e ] 89.42MB/173.2MB","id":"360ebdf19ecf"} 176 {"status":"Pushing","progressDetail":{"current":91087872,"total":173229523},"progress":"[==========================\u003e ] 91.09MB/173.2MB","id":"360ebdf19ecf"} 177 {"status":"Pushing","progressDetail":{"current":92759040,"total":173229523},"progress":"[==========================\u003e ] 92.76MB/173.2MB","id":"360ebdf19ecf"} 178 {"status":"Pushing","progressDetail":{"current":94430208,"total":173229523},"progress":"[===========================\u003e ] 94.43MB/173.2MB","id":"360ebdf19ecf"} 179 {"status":"Pushing","progressDetail":{"current":96101376,"total":173229523},"progress":"[===========================\u003e ] 96.1MB/173.2MB","id":"360ebdf19ecf"} 180 {"status":"Pushing","progressDetail":{"current":97215488,"total":173229523},"progress":"[============================\u003e ] 97.22MB/173.2MB","id":"360ebdf19ecf"} 181 {"status":"Pushing","progressDetail":{"current":98886656,"total":173229523},"progress":"[============================\u003e ] 98.89MB/173.2MB","id":"360ebdf19ecf"} 182 {"status":"Pushing","progressDetail":{"current":100557824,"total":173229523},"progress":"[=============================\u003e ] 100.6MB/173.2MB","id":"360ebdf19ecf"} 183 {"status":"Pushing","progressDetail":{"current":102228992,"total":173229523},"progress":"[=============================\u003e ] 102.2MB/173.2MB","id":"360ebdf19ecf"} 184 {"status":"Pushing","progressDetail":{"current":104438272,"total":173229523},"progress":"[==============================\u003e ] 104.4MB/173.2MB","id":"360ebdf19ecf"} 185 {"status":"Pushing","progressDetail":{"current":105552384,"total":173229523},"progress":"[==============================\u003e ] 105.6MB/173.2MB","id":"360ebdf19ecf"} 186 {"status":"Pushing","progressDetail":{"current":107223552,"total":173229523},"progress":"[==============================\u003e ] 107.2MB/173.2MB","id":"360ebdf19ecf"} 187 {"status":"Pushing","progressDetail":{"current":108894720,"total":173229523},"progress":"[===============================\u003e ] 108.9MB/173.2MB","id":"360ebdf19ecf"} 188 {"status":"Pushing","progressDetail":{"current":110565888,"total":173229523},"progress":"[===============================\u003e ] 110.6MB/173.2MB","id":"360ebdf19ecf"} 189 {"status":"Pushing","progressDetail":{"current":112237056,"total":173229523},"progress":"[================================\u003e ] 112.2MB/173.2MB","id":"360ebdf19ecf"} 190 {"status":"Pushing","progressDetail":{"current":113908224,"total":173229523},"progress":"[================================\u003e ] 113.9MB/173.2MB","id":"360ebdf19ecf"} 191 {"status":"Pushing","progressDetail":{"current":115022336,"total":173229523},"progress":"[=================================\u003e ] 115MB/173.2MB","id":"360ebdf19ecf"} 192 {"status":"Pushing","progressDetail":{"current":116693504,"total":173229523},"progress":"[=================================\u003e ] 116.7MB/173.2MB","id":"360ebdf19ecf"} 193 {"status":"Pushing","progressDetail":{"current":118364672,"total":173229523},"progress":"[==================================\u003e ] 118.4MB/173.2MB","id":"360ebdf19ecf"} 194 {"status":"Pushing","progressDetail":{"current":120035840,"total":173229523},"progress":"[==================================\u003e ] 120MB/173.2MB","id":"360ebdf19ecf"} 195 {"status":"Pushing","progressDetail":{"current":121707008,"total":173229523},"progress":"[===================================\u003e ] 121.7MB/173.2MB","id":"360ebdf19ecf"} 196 {"status":"Pushing","progressDetail":{"current":122793984,"total":173229523},"progress":"[===================================\u003e ] 122.8MB/173.2MB","id":"360ebdf19ecf"} 197 {"status":"Pushing","progressDetail":{"current":124465152,"total":173229523},"progress":"[===================================\u003e ] 124.5MB/173.2MB","id":"360ebdf19ecf"} 198 {"status":"Pushing","progressDetail":{"current":125579264,"total":173229523},"progress":"[====================================\u003e ] 125.6MB/173.2MB","id":"360ebdf19ecf"} 199 {"status":"Pushing","progressDetail":{"current":126693376,"total":173229523},"progress":"[====================================\u003e ] 126.7MB/173.2MB","id":"360ebdf19ecf"} 200 {"status":"Pushing","progressDetail":{"current":127807488,"total":173229523},"progress":"[====================================\u003e ] 127.8MB/173.2MB","id":"360ebdf19ecf"} 201 {"status":"Pushing","progressDetail":{"current":128921600,"total":173229523},"progress":"[=====================================\u003e ] 128.9MB/173.2MB","id":"360ebdf19ecf"} 202 {"status":"Pushing","progressDetail":{"current":130592768,"total":173229523},"progress":"[=====================================\u003e ] 130.6MB/173.2MB","id":"360ebdf19ecf"} 203 {"status":"Pushing","progressDetail":{"current":132263936,"total":173229523},"progress":"[======================================\u003e ] 132.3MB/173.2MB","id":"360ebdf19ecf"} 204 {"status":"Pushing","progressDetail":{"current":133378048,"total":173229523},"progress":"[======================================\u003e ] 133.4MB/173.2MB","id":"360ebdf19ecf"} 205 {"status":"Pushing","progressDetail":{"current":135049216,"total":173229523},"progress":"[======================================\u003e ] 135MB/173.2MB","id":"360ebdf19ecf"} 206 {"status":"Pushing","progressDetail":{"current":136720384,"total":173229523},"progress":"[=======================================\u003e ] 136.7MB/173.2MB","id":"360ebdf19ecf"} 207 {"status":"Pushing","progressDetail":{"current":138391552,"total":173229523},"progress":"[=======================================\u003e ] 138.4MB/173.2MB","id":"360ebdf19ecf"} 208 {"status":"Pushing","progressDetail":{"current":140062720,"total":173229523},"progress":"[========================================\u003e ] 140.1MB/173.2MB","id":"360ebdf19ecf"} 209 {"status":"Pushing","progressDetail":{"current":141689344,"total":173229523},"progress":"[========================================\u003e ] 141.7MB/173.2MB","id":"360ebdf19ecf"} 210 {"status":"Pushing","progressDetail":{"current":142794240,"total":173229523},"progress":"[=========================================\u003e ] 142.8MB/173.2MB","id":"360ebdf19ecf"} 211 {"status":"Pushing","progressDetail":{"current":144465408,"total":173229523},"progress":"[=========================================\u003e ] 144.5MB/173.2MB","id":"360ebdf19ecf"} 212 {"status":"Pushing","progressDetail":{"current":146136576,"total":173229523},"progress":"[==========================================\u003e ] 146.1MB/173.2MB","id":"360ebdf19ecf"} 213 {"status":"Pushing","progressDetail":{"current":147807744,"total":173229523},"progress":"[==========================================\u003e ] 147.8MB/173.2MB","id":"360ebdf19ecf"} 214 {"status":"Pushing","progressDetail":{"current":149478912,"total":173229523},"progress":"[===========================================\u003e ] 149.5MB/173.2MB","id":"360ebdf19ecf"} 215 {"status":"Pushing","progressDetail":{"current":151150080,"total":173229523},"progress":"[===========================================\u003e ] 151.2MB/173.2MB","id":"360ebdf19ecf"} 216 {"status":"Pushing","progressDetail":{"current":152264192,"total":173229523},"progress":"[===========================================\u003e ] 152.3MB/173.2MB","id":"360ebdf19ecf"} 217 {"status":"Pushing","progressDetail":{"current":153935360,"total":173229523},"progress":"[============================================\u003e ] 153.9MB/173.2MB","id":"360ebdf19ecf"} 218 {"status":"Pushing","progressDetail":{"current":155606528,"total":173229523},"progress":"[============================================\u003e ] 155.6MB/173.2MB","id":"360ebdf19ecf"} 219 {"status":"Pushing","progressDetail":{"current":157834752,"total":173229523},"progress":"[=============================================\u003e ] 157.8MB/173.2MB","id":"360ebdf19ecf"} 220 {"status":"Pushing","progressDetail":{"current":159503360,"total":173229523},"progress":"[==============================================\u003e ] 159.5MB/173.2MB","id":"360ebdf19ecf"} 221 {"status":"Pushing","progressDetail":{"current":161146880,"total":173229523},"progress":"[==============================================\u003e ] 161.1MB/173.2MB","id":"360ebdf19ecf"} 222 {"status":"Pushing","progressDetail":{"current":162766336,"total":173229523},"progress":"[==============================================\u003e ] 162.8MB/173.2MB","id":"360ebdf19ecf"} 223 {"status":"Pushing","progressDetail":{"current":163867648,"total":173229523},"progress":"[===============================================\u003e ] 163.9MB/173.2MB","id":"360ebdf19ecf"} 224 {"status":"Pushing","progressDetail":{"current":165516800,"total":173229523},"progress":"[===============================================\u003e ] 165.5MB/173.2MB","id":"360ebdf19ecf"} 225 {"status":"Pushing","progressDetail":{"current":167149056,"total":173229523},"progress":"[================================================\u003e ] 167.1MB/173.2MB","id":"360ebdf19ecf"} 226 {"status":"Pushing","progressDetail":{"current":168793600,"total":173229523},"progress":"[================================================\u003e ] 168.8MB/173.2MB","id":"360ebdf19ecf"} 227 {"status":"Pushing","progressDetail":{"current":170412544,"total":173229523},"progress":"[=================================================\u003e ] 170.4MB/173.2MB","id":"360ebdf19ecf"} 228 {"status":"Pushing","progressDetail":{"current":172031488,"total":173229523},"progress":"[=================================================\u003e ] 172MB/173.2MB","id":"360ebdf19ecf"} 229 {"status":"Pushing","progressDetail":{"current":173113232,"total":173229523},"progress":"[=================================================\u003e ] 173.1MB/173.2MB","id":"360ebdf19ecf"} 230 {"status":"Pushing","progressDetail":{"current":174732532,"total":173229523},"progress":"[==================================================\u003e] 174.7MB","id":"360ebdf19ecf"} 231 {"status":"Pushing","progressDetail":{"current":175783582,"total":173229523},"progress":"[==================================================\u003e] 175.8MB","id":"360ebdf19ecf"} 232 {"status":"Pushing","progressDetail":{"current":176833526,"total":173229523},"progress":"[==================================================\u003e] 176.8MB","id":"360ebdf19ecf"} 233 {"status":"Pushing","progressDetail":{"current":177884111,"total":173229523},"progress":"[==================================================\u003e] 177.9MB","id":"360ebdf19ecf"} 234 {"status":"Pushing","progressDetail":{"current":179670528,"total":173229523},"progress":"[==================================================\u003e] 179.7MB","id":"360ebdf19ecf"} 235 {"status":"Pushed","progressDetail":{},"id":"360ebdf19ecf"} 236 {"status":"latest: digest: sha256:a93d0334db5fd9769e1d09adcd13eafb690b170fe294cf0aa806273db5e2bcaf size: 2207"} 237 {"progressDetail":{},"aux":{"Tag":"latest","Digest":"sha256:a93d0334db5fd9769e1d09adcd13eafb690b170fe294cf0aa806273db5e2bcaf","Size":"2207"}}` 238 239 autoErrorResult = `{ 240 "code": "CRG0009E", 241 "message": "You are not authorized to access the specified account.", 242 "request-id": "1044-1540315282.640-825591" 243 }` 244 245 buildErrorResult = `{"errorDetail":{"message":"Error response from daemon: Cannot locate specified Dockerfile: Dockerfiles"},"error":"Error response from daemon: Cannot locate specified Dockerfile: Dockerfiles"}` 246 ) 247 248 var _ = Describe("Builds", func() { 249 var server *ghttp.Server 250 AfterEach(func() { 251 server.Close() 252 }) 253 Describe("ImageBuildCallback", func() { 254 Context("When build with callback is completed", func() { 255 tarBuffer := createTestTar() 256 var requestBuffer bytes.Buffer 257 buffer := io.TeeReader(tarBuffer, &requestBuffer) 258 bodyBytes, _ := ioutil.ReadAll(buffer) 259 BeforeEach(func() { 260 server = ghttp.NewServer() 261 server.AppendHandlers( 262 ghttp.CombineHandlers( 263 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 264 ghttp.VerifyBody(bodyBytes), 265 ghttp.RespondWith(http.StatusOK, buildResult), 266 ), 267 ) 268 }) 269 270 It("should return build with callback results", func() { 271 params := ImageBuildRequest{ 272 T: "registry.ng.bluemix.net/bkuschel/testimage", 273 Dockerfile: "", 274 Buildargs: "", 275 Nocache: false, 276 Pull: false, 277 Quiet: false, 278 Squash: false, 279 } 280 target := BuildTargetHeader{ 281 AccountID: "abc", 282 } 283 i := 0 284 respArr := make([]ImageBuildResponse, i, 203) 285 err := newBuild(server.URL()).ImageBuildCallback(params, &requestBuffer, target, func(respV ImageBuildResponse) bool { 286 respArr = append(respArr, respV) 287 i++ 288 return true 289 }) 290 Expect(err).NotTo(HaveOccurred()) 291 Expect(respArr).To(HaveLen(203)) 292 for i, v := range strings.Split(buildResult, "\n") { 293 var resp ImageBuildResponse 294 err = json.Unmarshal([]byte(v), &resp) 295 Expect(err).To(BeNil()) 296 Expect(respArr[i]).Should(Equal(resp)) 297 } 298 }) 299 }) 300 Context("When build with callback auth is unsuccessful", func() { 301 tarBuffer := createTestTar() 302 var requestBuffer bytes.Buffer 303 buffer := io.TeeReader(tarBuffer, &requestBuffer) 304 bodyBytes, _ := ioutil.ReadAll(buffer) 305 BeforeEach(func() { 306 server = ghttp.NewServer() 307 server.AppendHandlers( 308 ghttp.CombineHandlers( 309 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 310 ghttp.VerifyBody(bodyBytes), 311 ghttp.RespondWith(http.StatusUnauthorized, autoErrorResult), 312 ), 313 ) 314 }) 315 316 It("should return error during build with callback ", func() { 317 params := ImageBuildRequest{ 318 T: "registry.ng.bluemix.net/bkuschel/testimage", 319 Dockerfile: "", 320 Buildargs: "", 321 Nocache: false, 322 Pull: false, 323 Quiet: false, 324 Squash: false, 325 } 326 target := BuildTargetHeader{ 327 AccountID: "abc", 328 } 329 i := 0 330 respArr := make([]ImageBuildResponse, i, 203) 331 err := newBuild(server.URL()).ImageBuildCallback(params, &requestBuffer, target, func(respV ImageBuildResponse) bool { 332 respArr = append(respArr, respV) 333 i++ 334 return true 335 }) 336 Expect(err).To(HaveOccurred()) 337 Expect(respArr).To(HaveLen(i)) 338 }) 339 }) 340 Context("When build with callback is unsuccessful", func() { 341 tarBuffer := createTestTar() 342 var requestBuffer bytes.Buffer 343 buffer := io.TeeReader(tarBuffer, &requestBuffer) 344 bodyBytes, _ := ioutil.ReadAll(buffer) 345 BeforeEach(func() { 346 server = ghttp.NewServer() 347 server.AppendHandlers( 348 ghttp.CombineHandlers( 349 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 350 ghttp.VerifyBody(bodyBytes), 351 ghttp.RespondWith(http.StatusOK, buildErrorResult), 352 ), 353 ) 354 }) 355 356 It("should return error during build with callback", func() { 357 params := ImageBuildRequest{ 358 T: "registry.ng.bluemix.net/bkuschel/testimage", 359 Dockerfile: "Dockerfiles", 360 Buildargs: "", 361 Nocache: false, 362 Pull: false, 363 Quiet: false, 364 Squash: false, 365 } 366 target := BuildTargetHeader{ 367 AccountID: "abc", 368 } 369 i := 0 370 respArr := make([]ImageBuildResponse, i, 203) 371 err := newBuild(server.URL()).ImageBuildCallback(params, &requestBuffer, target, func(respV ImageBuildResponse) bool { 372 respArr = append(respArr, respV) 373 i++ 374 return true 375 }) 376 Expect(err).NotTo(HaveOccurred()) 377 Expect(respArr).To(HaveLen(1)) 378 var resp ImageBuildResponse 379 err = json.Unmarshal([]byte(buildErrorResult), &resp) 380 Expect(err).To(BeNil()) 381 Expect(respArr[0]).Should(Equal(resp)) 382 }) 383 }) 384 }) 385 Describe("ImageBuild", func() { 386 Context("When Build is completed", func() { 387 tarBuffer := createTestTar() 388 var requestBuffer bytes.Buffer 389 buffer := io.TeeReader(tarBuffer, &requestBuffer) 390 bodyBytes, _ := ioutil.ReadAll(buffer) 391 BeforeEach(func() { 392 server = ghttp.NewServer() 393 server.AppendHandlers( 394 ghttp.CombineHandlers( 395 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 396 ghttp.VerifyBody(bodyBytes), 397 ghttp.RespondWith(http.StatusOK, buildResult), 398 ), 399 ) 400 }) 401 402 It("should return build results", func() { 403 params := ImageBuildRequest{ 404 T: "registry.ng.bluemix.net/bkuschel/testimage", 405 Dockerfile: "", 406 Buildargs: "", 407 Nocache: false, 408 Pull: false, 409 Quiet: false, 410 Squash: false, 411 } 412 target := BuildTargetHeader{ 413 AccountID: "abc", 414 } 415 var b bytes.Buffer 416 out := bufio.NewWriter(&b) 417 err := newBuild(server.URL()).ImageBuild(params, &requestBuffer, target, out) 418 Expect(err).NotTo(HaveOccurred()) 419 Expect(out).NotTo(BeNil()) 420 Expect(b.Bytes()).Should(Equal([]byte(buildResult))) 421 }) 422 }) 423 Context("When build auth is unsuccessful", func() { 424 tarBuffer := createTestTar() 425 var requestBuffer bytes.Buffer 426 buffer := io.TeeReader(tarBuffer, &requestBuffer) 427 bodyBytes, _ := ioutil.ReadAll(buffer) 428 BeforeEach(func() { 429 server = ghttp.NewServer() 430 server.AppendHandlers( 431 ghttp.CombineHandlers( 432 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 433 ghttp.VerifyBody(bodyBytes), 434 ghttp.RespondWith(http.StatusUnauthorized, autoErrorResult), 435 ), 436 ) 437 }) 438 439 It("should return error during build", func() { 440 params := ImageBuildRequest{ 441 T: "registry.ng.bluemix.net/bkuschel/testimage", 442 Dockerfile: "", 443 Buildargs: "", 444 Nocache: false, 445 Pull: false, 446 Quiet: false, 447 Squash: false, 448 } 449 target := BuildTargetHeader{ 450 AccountID: "abc", 451 } 452 var b bytes.Buffer 453 out := bufio.NewWriter(&b) 454 err := newBuild(server.URL()).ImageBuild(params, &requestBuffer, target, out) 455 Expect(err).To(HaveOccurred()) 456 Expect(out).NotTo(BeNil()) 457 }) 458 }) 459 Context("When build is unsuccessful", func() { 460 tarBuffer := createTestTar() 461 var requestBuffer bytes.Buffer 462 buffer := io.TeeReader(tarBuffer, &requestBuffer) 463 bodyBytes, _ := ioutil.ReadAll(buffer) 464 BeforeEach(func() { 465 server = ghttp.NewServer() 466 server.AppendHandlers( 467 ghttp.CombineHandlers( 468 ghttp.VerifyRequest(http.MethodPost, "/api/v1/builds"), 469 ghttp.VerifyBody(bodyBytes), 470 ghttp.RespondWith(http.StatusOK, buildErrorResult), 471 ), 472 ) 473 }) 474 475 It("should return error during build", func() { 476 params := ImageBuildRequest{ 477 T: "registry.ng.bluemix.net/bkuschel/testimage", 478 Dockerfile: "Dockerfiles", 479 Buildargs: "", 480 Nocache: false, 481 Pull: false, 482 Quiet: false, 483 Squash: false, 484 } 485 target := BuildTargetHeader{ 486 AccountID: "abc", 487 } 488 var b bytes.Buffer 489 out := bufio.NewWriter(&b) 490 err := newBuild(server.URL()).ImageBuild(params, &requestBuffer, target, out) 491 Expect(err).NotTo(HaveOccurred()) 492 Expect(out).NotTo(BeNil()) 493 Expect(b.Bytes()).Should(Equal([]byte(buildErrorResult))) 494 }) 495 }) 496 }) 497 }) 498 499 func newBuild(url string) Builds { 500 501 sess, err := session.New() 502 if err != nil { 503 log.Fatal(err) 504 } 505 conf := sess.Config.Copy() 506 conf.HTTPClient = ibmcloudHttp.NewHTTPClient(conf) 507 conf.Endpoint = &url 508 509 client := client.Client{ 510 Config: conf, 511 ServiceName: ibmcloud.ContainerRegistryService, 512 } 513 return newBuildAPI(&client) 514 } 515 516 func createTestTar() *bytes.Buffer { 517 // Create and add some files to the archive. 518 var buf bytes.Buffer 519 gw := gzip.NewWriter(&buf) 520 defer gw.Close() 521 tw := tar.NewWriter(gw) 522 defer tw.Close() 523 hdr := &tar.Header{ 524 Name: dockerfileName, 525 Mode: 0600, 526 Size: int64(len(dockerfile)), 527 } 528 if err := tw.WriteHeader(hdr); err != nil { 529 log.Fatal(err) 530 } 531 if _, err := tw.Write([]byte(dockerfile)); err != nil { 532 log.Fatal(err) 533 } 534 return &buf 535 }