Release.Jenkinsfile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #!groovy
  2. def dockerVersions = ['19.03.5', '18.09.9']
  3. def baseImages = ['alpine', 'debian']
  4. def pythonVersions = ['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 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 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. environment {
  158. GITHUB_TOKEN = credentials('github-release-token')
  159. }
  160. steps {
  161. checkout scm
  162. sh 'mkdir -p dist'
  163. dir("dist") {
  164. unstash "bin-darwin"
  165. unstash "bin-linux"
  166. unstash "bin-win"
  167. unstash "changelog"
  168. sh("""
  169. curl -SfL https://github.com/github/hub/releases/download/v2.13.0/hub-linux-amd64-2.13.0.tgz | tar xzv --wildcards 'hub-*/bin/hub' --strip=2
  170. ./hub release create --draft --prerelease=${env.TAG_NAME !=~ /v[0-9\.]+/} \\
  171. -a docker-compose-Darwin-x86_64 \\
  172. -a docker-compose-Darwin-x86_64.sha256 \\
  173. -a docker-compose-Darwin-x86_64.tgz \\
  174. -a docker-compose-Darwin-x86_64.tgz.sha256 \\
  175. -a docker-compose-Linux-x86_64 \\
  176. -a docker-compose-Linux-x86_64.sha256 \\
  177. -a docker-compose-Windows-x86_64.exe \\
  178. -a docker-compose-Windows-x86_64.exe.sha256 \\
  179. -a ../script/run/run.sh \\
  180. -F CHANGELOG.md \${TAG_NAME}
  181. """)
  182. }
  183. }
  184. }
  185. stage('Publishing Python packages') {
  186. agent {
  187. label 'linux'
  188. }
  189. environment {
  190. PYPIRC = credentials('pypirc-docker-dsg-cibot')
  191. }
  192. steps {
  193. checkout scm
  194. sh """
  195. rm -rf build/ dist/
  196. pip install wheel
  197. python setup.py sdist bdist_wheel
  198. pip install twine
  199. ~/.local/bin/twine upload --config-file ${PYPIRC} ./dist/docker-compose-*.tar.gz ./dist/docker_compose-*-py2.py3-none-any.whl
  200. """
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. def buildImage(baseImage) {
  208. def scmvar = checkout(scm)
  209. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  210. image = docker.image(imageName)
  211. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  212. try {
  213. image.pull()
  214. } catch (Exception exc) {
  215. ansiColor('xterm') {
  216. sh """docker build -t ${imageName} \\
  217. --target build \\
  218. --build-arg BUILD_PLATFORM="${baseImage}" \\
  219. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT}" \\
  220. .\\
  221. """
  222. sh "docker push ${imageName}"
  223. }
  224. echo "${imageName}"
  225. return imageName
  226. }
  227. }
  228. }
  229. def runTests(dockerVersion, pythonVersion, baseImage) {
  230. return {
  231. stage("python=${pythonVersion} docker=${dockerVersion} ${baseImage}") {
  232. node("linux") {
  233. def scmvar = checkout(scm)
  234. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  235. def storageDriver = sh(script: "docker info -f \'{{.Driver}}\'", returnStdout: true).trim()
  236. echo "Using local system's storage driver: ${storageDriver}"
  237. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  238. sh """docker run \\
  239. -t \\
  240. --rm \\
  241. --privileged \\
  242. --volume="\$(pwd)/.git:/code/.git" \\
  243. --volume="/var/run/docker.sock:/var/run/docker.sock" \\
  244. -e "TAG=${imageName}" \\
  245. -e "STORAGE_DRIVER=${storageDriver}" \\
  246. -e "DOCKER_VERSIONS=${dockerVersion}" \\
  247. -e "BUILD_NUMBER=${env.BUILD_NUMBER}" \\
  248. -e "PY_TEST_VERSIONS=${pythonVersion}" \\
  249. --entrypoint="script/test/ci" \\
  250. ${imageName} \\
  251. --verbose
  252. """
  253. }
  254. }
  255. }
  256. }
  257. }
  258. def buildRuntimeImage(baseImage) {
  259. scmvar = checkout scm
  260. def imageName = "docker/compose:${baseImage}-${env.BRANCH_NAME}"
  261. ansiColor('xterm') {
  262. sh """docker build -t ${imageName} \\
  263. --build-arg BUILD_PLATFORM="${baseImage}" \\
  264. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT.take(7)}" \\
  265. .
  266. """
  267. }
  268. sh "mkdir -p dist"
  269. sh "docker save ${imageName} -o dist/docker-compose-${baseImage}.tar"
  270. stash name: "compose-${baseImage}", includes: "dist/docker-compose-${baseImage}.tar"
  271. }
  272. def pushRuntimeImage(baseImage) {
  273. unstash "compose-${baseImage}"
  274. sh "docker load -i dist/docker-compose-${baseImage}.tar"
  275. withDockerRegistry(credentialsId: 'dockerhub-dockerdsgcibot') {
  276. sh "docker push docker/compose:${baseImage}-${env.TAG_NAME}"
  277. if (baseImage == "alpine" && env.TAG_NAME != null) {
  278. sh "docker tag docker/compose:alpine-${env.TAG_NAME} docker/compose:${env.TAG_NAME}"
  279. sh "docker push docker/compose:${env.TAG_NAME}"
  280. }
  281. }
  282. }
  283. def checksum(filepath) {
  284. if (isUnix()) {
  285. sh "openssl sha256 -r -out ${filepath}.sha256 ${filepath}"
  286. } else {
  287. powershell "(Get-FileHash -Path ${filepath} -Algorithm SHA256 | % hash).ToLower() + ' *${filepath}' | Out-File -encoding ascii ${filepath}.sha256"
  288. }
  289. }