Release.Jenkinsfile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #!groovy
  2. def dockerVersions = ['19.03.8', '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 && docker && ubuntu-2004'
  20. }
  21. steps {
  22. buildImage('alpine')
  23. }
  24. }
  25. stage('debian') {
  26. agent {
  27. label 'linux && docker && ubuntu-2004'
  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 && docker && ubuntu-2004'
  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. environment {
  71. DEPLOYMENT_TARGET="10.11"
  72. }
  73. steps {
  74. checkout scm
  75. sh './script/setup/osx'
  76. sh 'tox -e py37 -- tests/unit'
  77. sh './script/build/osx'
  78. dir ('dist') {
  79. checksum('docker-compose-Darwin-x86_64')
  80. checksum('docker-compose-Darwin-x86_64.tgz')
  81. }
  82. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  83. dir("dist") {
  84. stash name: "bin-darwin"
  85. }
  86. }
  87. }
  88. stage('linux binary') {
  89. agent {
  90. label 'linux && docker && ubuntu-2004'
  91. }
  92. steps {
  93. checkout scm
  94. sh ' ./script/build/linux'
  95. dir ('dist') {
  96. checksum('docker-compose-Linux-x86_64')
  97. }
  98. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  99. dir("dist") {
  100. stash name: "bin-linux"
  101. }
  102. }
  103. }
  104. stage('windows binary') {
  105. agent {
  106. label 'windows-python'
  107. }
  108. environment {
  109. PATH = "$PATH;C:\\Python37;C:\\Python37\\Scripts"
  110. }
  111. steps {
  112. checkout scm
  113. bat 'tox.exe -e py37 -- tests/unit'
  114. powershell '.\\script\\build\\windows.ps1'
  115. dir ('dist') {
  116. checksum('docker-compose-Windows-x86_64.exe')
  117. }
  118. archiveArtifacts artifacts: 'dist/*', fingerprint: true
  119. dir("dist") {
  120. stash name: "bin-win"
  121. }
  122. }
  123. }
  124. stage('alpine image') {
  125. agent {
  126. label 'linux && docker && ubuntu-2004'
  127. }
  128. steps {
  129. buildRuntimeImage('alpine')
  130. }
  131. }
  132. stage('debian image') {
  133. agent {
  134. label 'linux && docker && ubuntu-2004'
  135. }
  136. steps {
  137. buildRuntimeImage('debian')
  138. }
  139. }
  140. }
  141. }
  142. stage('Release') {
  143. when {
  144. buildingTag()
  145. }
  146. parallel {
  147. stage('Pushing images') {
  148. agent {
  149. label 'linux && docker && ubuntu-2004'
  150. }
  151. steps {
  152. pushRuntimeImage('alpine')
  153. pushRuntimeImage('debian')
  154. }
  155. }
  156. stage('Creating Github Release') {
  157. agent {
  158. label 'linux && docker && ubuntu-2004'
  159. }
  160. environment {
  161. GITHUB_TOKEN = credentials('github-release-token')
  162. }
  163. steps {
  164. checkout scm
  165. sh 'mkdir -p dist'
  166. dir("dist") {
  167. unstash "bin-darwin"
  168. unstash "bin-linux"
  169. unstash "bin-win"
  170. unstash "changelog"
  171. sh("""
  172. 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
  173. ./hub release create --draft --prerelease=${env.TAG_NAME !=~ /v[0-9\.]+/} \\
  174. -a docker-compose-Darwin-x86_64 \\
  175. -a docker-compose-Darwin-x86_64.sha256 \\
  176. -a docker-compose-Darwin-x86_64.tgz \\
  177. -a docker-compose-Darwin-x86_64.tgz.sha256 \\
  178. -a docker-compose-Linux-x86_64 \\
  179. -a docker-compose-Linux-x86_64.sha256 \\
  180. -a docker-compose-Windows-x86_64.exe \\
  181. -a docker-compose-Windows-x86_64.exe.sha256 \\
  182. -a ../script/run/run.sh \\
  183. -F CHANGELOG.md \${TAG_NAME}
  184. """)
  185. }
  186. }
  187. }
  188. stage('Publishing Python packages') {
  189. agent {
  190. label 'linux && docker && ubuntu-2004'
  191. }
  192. environment {
  193. PYPIRC = credentials('pypirc-docker-dsg-cibot')
  194. }
  195. steps {
  196. checkout scm
  197. sh """
  198. rm -rf build/ dist/
  199. pip3 install wheel
  200. python3 setup.py sdist bdist_wheel
  201. pip3 install twine
  202. ~/.local/bin/twine upload --config-file ${PYPIRC} ./dist/docker-compose-*.tar.gz ./dist/docker_compose-*-py2.py3-none-any.whl
  203. """
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. def buildImage(baseImage) {
  211. def scmvar = checkout(scm)
  212. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  213. image = docker.image(imageName)
  214. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  215. try {
  216. image.pull()
  217. } catch (Exception exc) {
  218. ansiColor('xterm') {
  219. sh """docker build -t ${imageName} \\
  220. --target build \\
  221. --build-arg BUILD_PLATFORM="${baseImage}" \\
  222. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT}" \\
  223. .\\
  224. """
  225. sh "docker push ${imageName}"
  226. }
  227. echo "${imageName}"
  228. return imageName
  229. }
  230. }
  231. }
  232. def runTests(dockerVersion, pythonVersion, baseImage) {
  233. return {
  234. stage("python=${pythonVersion} docker=${dockerVersion} ${baseImage}") {
  235. node("linux") {
  236. def scmvar = checkout(scm)
  237. def imageName = "dockerbuildbot/compose:${baseImage}-${scmvar.GIT_COMMIT}"
  238. def storageDriver = sh(script: "docker info -f \'{{.Driver}}\'", returnStdout: true).trim()
  239. echo "Using local system's storage driver: ${storageDriver}"
  240. withDockerRegistry(credentialsId:'dockerbuildbot-index.docker.io') {
  241. sh """docker run \\
  242. -t \\
  243. --rm \\
  244. --privileged \\
  245. --volume="\$(pwd)/.git:/code/.git" \\
  246. --volume="/var/run/docker.sock:/var/run/docker.sock" \\
  247. -e "TAG=${imageName}" \\
  248. -e "STORAGE_DRIVER=${storageDriver}" \\
  249. -e "DOCKER_VERSIONS=${dockerVersion}" \\
  250. -e "BUILD_NUMBER=${env.BUILD_NUMBER}" \\
  251. -e "PY_TEST_VERSIONS=${pythonVersion}" \\
  252. --entrypoint="script/test/ci" \\
  253. ${imageName} \\
  254. --verbose
  255. """
  256. }
  257. }
  258. }
  259. }
  260. }
  261. def buildRuntimeImage(baseImage) {
  262. scmvar = checkout scm
  263. def imageName = "docker/compose:${baseImage}-${env.BRANCH_NAME}"
  264. ansiColor('xterm') {
  265. sh """docker build -t ${imageName} \\
  266. --build-arg BUILD_PLATFORM="${baseImage}" \\
  267. --build-arg GIT_COMMIT="${scmvar.GIT_COMMIT.take(7)}" \\
  268. .
  269. """
  270. }
  271. sh "mkdir -p dist"
  272. sh "docker save ${imageName} -o dist/docker-compose-${baseImage}.tar"
  273. stash name: "compose-${baseImage}", includes: "dist/docker-compose-${baseImage}.tar"
  274. }
  275. def pushRuntimeImage(baseImage) {
  276. unstash "compose-${baseImage}"
  277. sh "docker load -i dist/docker-compose-${baseImage}.tar"
  278. withDockerRegistry(credentialsId: 'dockerhub-dockerdsgcibot') {
  279. sh "docker push docker/compose:${baseImage}-${env.TAG_NAME}"
  280. if (baseImage == "alpine" && env.TAG_NAME != null) {
  281. sh "docker tag docker/compose:alpine-${env.TAG_NAME} docker/compose:${env.TAG_NAME}"
  282. sh "docker push docker/compose:${env.TAG_NAME}"
  283. }
  284. }
  285. }
  286. def checksum(filepath) {
  287. if (isUnix()) {
  288. sh "openssl sha256 -r -out ${filepath}.sha256 ${filepath}"
  289. } else {
  290. powershell "(Get-FileHash -Path ${filepath} -Algorithm SHA256 | % hash).ToLower() + ' *${filepath}' | Out-File -encoding ascii ${filepath}.sha256"
  291. }
  292. }