Release.Jenkinsfile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #!groovy
  2. def dockerVersions = ['19.03.5', '18.09.9']
  3. def baseImages = ['alpine', 'debian']
  4. def pythonVersions = ['py27', 'py37']
  5. pipeline {
  6. agent none
  7. options {
  8. skipDefaultCheckout(true)
  9. buildDiscarder(logRotator(daysToKeepStr: '30'))
  10. timeout(time: 2, unit: 'HOURS')
  11. timestamps()
  12. }
  13. stages {
  14. stage('Build test images') {
  15. // TODO use declarative 1.5.0 `matrix` once available on CI
  16. parallel {
  17. stage('alpine') {
  18. agent {
  19. label 'linux'
  20. }
  21. steps {
  22. buildImage('alpine')
  23. }
  24. }
  25. stage('debian') {
  26. agent {
  27. label 'linux'
  28. }
  29. steps {
  30. buildImage('debian')
  31. }
  32. }
  33. }
  34. }
  35. stage('Test') {
  36. steps {
  37. // TODO use declarative 1.5.0 `matrix` once available on CI
  38. script {
  39. def testMatrix = [:]
  40. baseImages.each { baseImage ->
  41. dockerVersions.each { dockerVersion ->
  42. pythonVersions.each { pythonVersion ->
  43. testMatrix["${baseImage}_${dockerVersion}_${pythonVersion}"] = runTests(dockerVersion, pythonVersion, baseImage)
  44. }
  45. }
  46. }
  47. parallel testMatrix
  48. }
  49. }
  50. }
  51. stage('Generate Changelog') {
  52. agent {
  53. label 'linux'
  54. }
  55. steps {
  56. checkout scm
  57. withCredentials([string(credentialsId: 'github-compose-release-test-token', variable: 'GITHUB_TOKEN')]) {
  58. sh "./script/release/generate_changelog.sh"
  59. }
  60. archiveArtifacts artifacts: 'CHANGELOG.md'
  61. stash( name: "changelog", includes: 'CHANGELOG.md' )
  62. }
  63. }
  64. stage('Package') {
  65. parallel {
  66. stage('macosx binary') {
  67. agent {
  68. label 'mac-python'
  69. }
  70. steps {
  71. checkout scm
  72. sh './script/setup/osx'
  73. sh 'tox -e py27,py37 -- tests/unit'
  74. sh './script/build/osx'
  75. dir ('dist') {
  76. checksum('docker-compose-Darwin-x86_64')
  77. checksum('docker-compose-Darwin-x86_64.tgz')
  78. }
  79. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  80. dir("dist") {
  81. stash name: "bin-darwin"
  82. }
  83. }
  84. }
  85. stage('linux binary') {
  86. agent {
  87. label 'linux'
  88. }
  89. steps {
  90. checkout scm
  91. sh ' ./script/build/linux'
  92. dir ('dist') {
  93. checksum('docker-compose-Linux-x86_64')
  94. }
  95. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  96. dir("dist") {
  97. stash name: "bin-linux"
  98. }
  99. }
  100. }
  101. stage('windows binary') {
  102. agent {
  103. label 'windows-python'
  104. }
  105. environment {
  106. PATH = "$PATH;C:\\Python37;C:\\Python37\\Scripts"
  107. }
  108. steps {
  109. checkout scm
  110. bat 'tox.exe -e py27,py37 -- tests/unit'
  111. powershell '.\\script\\build\\windows.ps1'
  112. dir ('dist') {
  113. checksum('docker-compose-Windows-x86_64.exe')
  114. }
  115. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  116. dir("dist") {
  117. stash name: "bin-win"
  118. }
  119. }
  120. }
  121. stage('alpine image') {
  122. agent {
  123. label 'linux'
  124. }
  125. steps {
  126. buildRuntimeImage('alpine')
  127. }
  128. }
  129. stage('debian image') {
  130. agent {
  131. label 'linux'
  132. }
  133. steps {
  134. buildRuntimeImage('debian')
  135. }
  136. }
  137. }
  138. }
  139. stage('Release') {
  140. when {
  141. buildingTag()
  142. }
  143. parallel {
  144. stage('Pushing images') {
  145. agent {
  146. label 'linux'
  147. }
  148. steps {
  149. pushRuntimeImage('alpine')
  150. pushRuntimeImage('debian')
  151. }
  152. }
  153. stage('Creating Github Release') {
  154. agent {
  155. label 'linux'
  156. }
  157. steps {
  158. checkout scm
  159. sh 'mkdir -p dist'
  160. dir("dist") {
  161. unstash "bin-darwin"
  162. unstash "bin-linux"
  163. unstash "bin-win"
  164. unstash "changelog"
  165. githubRelease()
  166. }
  167. }
  168. }
  169. stage('Publishing Python packages') {
  170. agent {
  171. label 'linux'
  172. }
  173. steps {
  174. checkout scm
  175. withCredentials([[$class: "FileBinding", credentialsId: 'pypirc-docker-dsg-cibot', variable: 'PYPIRC']]) {
  176. sh """
  177. virtualenv venv-publish
  178. source venv-publish/bin/activate
  179. python setup.py sdist bdist_wheel
  180. pip install twine
  181. twine upload --config-file ${PYPIRC} ./dist/docker-compose-${env.TAG_NAME}.tar.gz ./dist/docker_compose-${env.TAG_NAME}-py2.py3-none-any.whl
  182. """
  183. }
  184. }
  185. post {
  186. sh 'deactivate; rm -rf venv-publish'
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. def buildImage(baseImage) {
  194. def scmvar = checkout(scm)
  195. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  196. image = docker.image(imageName)
  197. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  198. try {
  199. image.pull()
  200. } catch (Exception exc) {
  201. ansiColor('xterm') {
  202. sh """docker build -t ${imageName} \\
  203. --target build \\
  204. --build-arg BUILD_PLATFORM="${baseImage}" \\
  205. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT}" \\
  206. .\\
  207. """
  208. sh "docker push ${imageName}"
  209. }
  210. echo "${imageName}"
  211. return imageName
  212. }
  213. }
  214. }
  215. def runTests(dockerVersion, pythonVersion, baseImage) {
  216. return {
  217. stage("python=${pythonVersion} docker=${dockerVersion} ${baseImage}") {
  218. node("linux") {
  219. def scmvar = checkout(scm)
  220. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  221. def storageDriver = sh(script: "docker info -f \'{{.Driver}}\'", returnStdout: true).trim()
  222. echo "Using local system's storage driver: ${storageDriver}"
  223. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  224. sh """docker run \\
  225. -t \\
  226. --rm \\
  227. --privileged \\
  228. --volume="\$(pwd)/.git:/code/.git" \\
  229. --volume="/var/run/docker.sock:/var/run/docker.sock" \\
  230. -e "TAG=${imageName}" \\
  231. -e "STORAGE_DRIVER=${storageDriver}" \\
  232. -e "DOCKER_VERSIONS=${dockerVersion}" \\
  233. -e "BUILD_NUMBER=${env.BUILD_NUMBER}" \\
  234. -e "PY_TEST_VERSIONS=${pythonVersion}" \\
  235. --entrypoint="script/test/ci" \\
  236. ${imageName} \\
  237. --verbose
  238. """
  239. }
  240. }
  241. }
  242. }
  243. }
  244. def buildRuntimeImage(baseImage) {
  245. scmvar = checkout scm
  246. def imageName = "docker/compose:${baseImage}-${env.BRANCH_NAME}"
  247. ansiColor('xterm') {
  248. sh """docker build -t ${imageName} \\
  249. --build-arg BUILD_PLATFORM="${baseImage}" \\
  250. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT.take(7)}" \\
  251. .
  252. """
  253. }
  254. sh "mkdir -p dist"
  255. sh "docker save ${imageName} -o dist/docker-compose-${baseImage}.tar"
  256. stash name: "compose-${baseImage}", includes: "dist/docker-compose-${baseImage}.tar"
  257. }
  258. def pushRuntimeImage(baseImage) {
  259. unstash "compose-${baseImage}"
  260. sh 'echo -n "${DOCKERHUB_CREDS_PSW}" | docker login --username "${DOCKERHUB_CREDS_USR}" --password-stdin'
  261. sh "docker load -i dist/docker-compose-${baseImage}.tar"
  262. withDockerRegistry(credentialsId: 'dockerbuildbot-hub.docker.com') {
  263. sh "docker push docker/compose:${baseImage}-${env.TAG_NAME}"
  264. if (baseImage == "alpine" && env.TAG_NAME != null) {
  265. sh "docker tag docker/compose:alpine-${env.TAG_NAME} docker/compose:${env.TAG_NAME}"
  266. sh "docker push docker/compose:${env.TAG_NAME}"
  267. }
  268. }
  269. }
  270. def githubRelease() {
  271. withCredentials([string(credentialsId: 'github-compose-release-test-token', variable: 'GITHUB_TOKEN')]) {
  272. def prerelease = !( env.TAG_NAME ==~ /v[0-9\.]+/ )
  273. changelog = readFile "CHANGELOG.md"
  274. def data = """{
  275. \"tag_name\": \"${env.TAG_NAME}\",
  276. \"name\": \"${env.TAG_NAME}\",
  277. \"draft\": true,
  278. \"prerelease\": ${prerelease},
  279. \"body\" : \"${changelog}\"
  280. """
  281. echo $data
  282. def url = "https://api.github.com/repos/docker/compose/releases"
  283. def upload_url = sh(returnStdout: true, script: """
  284. curl -sSf -H 'Authorization: token ${GITHUB_TOKEN}' -H 'Accept: application/json' -H 'Content-type: application/json' -X POST -d '$data' $url") \\
  285. | jq '.upload_url | .[:rindex("{")]'
  286. """)
  287. sh("""
  288. for f in * ; do
  289. curl -sf -H 'Authorization: token ${GITHUB_TOKEN}' -H 'Accept: application/json' -H 'Content-type: application/octet-stream' \\
  290. -X POST --data-binary @\$f ${upload_url}?name=\$f;
  291. done
  292. """)
  293. }
  294. }
  295. def checksum(filepath) {
  296. if (isUnix()) {
  297. sh "openssl sha256 -r -out ${filepath}.sha256 ${filepath}"
  298. } else {
  299. powershell "(Get-FileHash -Path ${filepath} -Algorithm SHA256 | % hash) + ' *${filepath}' > ${filepath}.sha256"
  300. }
  301. }