Jenkinsfile 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import groovy.transform.Field
  2. @Field
  3. def shOutput = ""
  4. def buildxPushTags = ""
  5. pipeline {
  6. agent {
  7. label 'docker-multiarch'
  8. }
  9. options {
  10. buildDiscarder(logRotator(numToKeepStr: '5'))
  11. disableConcurrentBuilds()
  12. ansiColor('xterm')
  13. }
  14. environment {
  15. IMAGE = 'nginx-proxy-manager'
  16. BUILD_VERSION = getVersion()
  17. MAJOR_VERSION = '2'
  18. BRANCH_LOWER = "${BRANCH_NAME.toLowerCase().replaceAll('\\\\', '-').replaceAll('/', '-').replaceAll('\\.', '-')}"
  19. BUILDX_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}"
  20. COMPOSE_INTERACTIVE_NO_CLI = 1
  21. }
  22. stages {
  23. stage('Environment') {
  24. parallel {
  25. stage('Master') {
  26. when {
  27. branch 'master'
  28. }
  29. steps {
  30. script {
  31. buildxPushTags = "-t docker.io/jc21/${IMAGE}:${BUILD_VERSION} -t docker.io/jc21/${IMAGE}:${MAJOR_VERSION} -t docker.io/jc21/${IMAGE}:latest"
  32. }
  33. }
  34. }
  35. stage('Other') {
  36. when {
  37. not {
  38. branch 'master'
  39. }
  40. }
  41. steps {
  42. script {
  43. // Defaults to the Branch name, which is applies to all branches AND pr's
  44. buildxPushTags = "-t docker.io/nginxproxymanager/${IMAGE}-dev:${BRANCH_LOWER}"
  45. }
  46. }
  47. }
  48. stage('Versions') {
  49. steps {
  50. sh 'cat frontend/package.json | jq --arg BUILD_VERSION "${BUILD_VERSION}" \'.version = $BUILD_VERSION\' | sponge frontend/package.json'
  51. sh 'echo -e "\\E[1;36mFrontend Version is:\\E[1;33m $(cat frontend/package.json | jq -r .version)\\E[0m"'
  52. sh 'cat backend/package.json | jq --arg BUILD_VERSION "${BUILD_VERSION}" \'.version = $BUILD_VERSION\' | sponge backend/package.json'
  53. sh 'echo -e "\\E[1;36mBackend Version is:\\E[1;33m $(cat backend/package.json | jq -r .version)\\E[0m"'
  54. sh 'sed -i -E "s/(version-)[0-9]+\\.[0-9]+\\.[0-9]+(-green)/\\1${BUILD_VERSION}\\2/" README.md'
  55. }
  56. }
  57. stage('Docker Login') {
  58. steps {
  59. withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
  60. sh 'docker login -u "${duser}" -p "${dpass}"'
  61. }
  62. }
  63. }
  64. }
  65. }
  66. stage('Builds') {
  67. parallel {
  68. stage('Project') {
  69. steps {
  70. script {
  71. // Frontend and Backend
  72. def shStatusCode = sh(label: 'Checking and Building', returnStatus: true, script: '''
  73. set -e
  74. ./scripts/ci/frontend-build > ${WORKSPACE}/tmp-sh-build 2>&1
  75. ./scripts/ci/test-and-build > ${WORKSPACE}/tmp-sh-build 2>&1
  76. ''')
  77. shOutput = readFile "${env.WORKSPACE}/tmp-sh-build"
  78. if (shStatusCode != 0) {
  79. error "${shOutput}"
  80. }
  81. }
  82. }
  83. post {
  84. always {
  85. sh 'rm -f ${WORKSPACE}/tmp-sh-build'
  86. }
  87. failure {
  88. npmGithubPrComment("CI Error:\n\n```\n${shOutput}\n```", true)
  89. }
  90. }
  91. }
  92. stage('Docs') {
  93. steps {
  94. dir(path: 'docs') {
  95. sh 'yarn install'
  96. sh 'yarn build'
  97. }
  98. }
  99. }
  100. }
  101. }
  102. stage('Test Sqlite') {
  103. environment {
  104. COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_sqlite"
  105. COMPOSE_FILE = 'docker/docker-compose.ci.yml:docker/docker-compose.ci.sqlite.yml'
  106. }
  107. when {
  108. not {
  109. equals expected: 'UNSTABLE', actual: currentBuild.result
  110. }
  111. }
  112. steps {
  113. sh 'rm -rf ./test/results/junit/*'
  114. sh './scripts/ci/fulltest-cypress'
  115. }
  116. post {
  117. always {
  118. // Dumps to analyze later
  119. sh 'mkdir -p debug/sqlite'
  120. sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/sqlite/docker_fullstack.log 2>&1'
  121. sh 'docker logs $(docker-compose ps --all -q stepca) > debug/sqlite/docker_stepca.log 2>&1'
  122. sh 'docker logs $(docker-compose ps --all -q pdns) > debug/sqlite/docker_pdns.log 2>&1'
  123. sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/sqlite/docker_pdns-db.log 2>&1'
  124. sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/sqlite/docker_dnsrouter.log 2>&1'
  125. junit 'test/results/junit/*'
  126. sh 'docker-compose down --remove-orphans --volumes -t 30 || true'
  127. }
  128. unstable {
  129. dir(path: 'testing/results') {
  130. archiveArtifacts(allowEmptyArchive: true, artifacts: '**/*', excludes: '**/*.xml')
  131. }
  132. }
  133. }
  134. }
  135. stage('Test Mysql') {
  136. environment {
  137. COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_mysql"
  138. COMPOSE_FILE = 'docker/docker-compose.ci.yml:docker/docker-compose.ci.mysql.yml'
  139. }
  140. when {
  141. not {
  142. equals expected: 'UNSTABLE', actual: currentBuild.result
  143. }
  144. }
  145. steps {
  146. sh 'rm -rf ./test/results/junit/*'
  147. sh './scripts/ci/fulltest-cypress'
  148. }
  149. post {
  150. always {
  151. // Dumps to analyze later
  152. sh 'mkdir -p debug/mysql'
  153. sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/mysql/docker_fullstack.log 2>&1'
  154. sh 'docker logs $(docker-compose ps --all -q stepca) > debug/mysql/docker_stepca.log 2>&1'
  155. sh 'docker logs $(docker-compose ps --all -q pdns) > debug/mysql/docker_pdns.log 2>&1'
  156. sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/mysql/docker_pdns-db.log 2>&1'
  157. sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/mysql/docker_dnsrouter.log 2>&1'
  158. junit 'test/results/junit/*'
  159. sh 'docker-compose down --remove-orphans --volumes -t 30 || true'
  160. }
  161. unstable {
  162. dir(path: 'testing/results') {
  163. archiveArtifacts(allowEmptyArchive: true, artifacts: '**/*', excludes: '**/*.xml')
  164. }
  165. }
  166. }
  167. }
  168. stage('MultiArch Build') {
  169. when {
  170. not {
  171. equals expected: 'UNSTABLE', actual: currentBuild.result
  172. }
  173. }
  174. steps {
  175. sh "./scripts/buildx --push ${buildxPushTags}"
  176. }
  177. }
  178. stage('Docs / Comment') {
  179. parallel {
  180. stage('Docs Job') {
  181. when {
  182. allOf {
  183. branch pattern: "^(develop|master)\$", comparator: "REGEXP"
  184. not {
  185. equals expected: 'UNSTABLE', actual: currentBuild.result
  186. }
  187. }
  188. }
  189. steps {
  190. build wait: false, job: 'nginx-proxy-manager-docs', parameters: [string(name: 'docs_branch', value: "$BRANCH_NAME")]
  191. }
  192. }
  193. stage('PR Comment') {
  194. when {
  195. allOf {
  196. changeRequest()
  197. not {
  198. equals expected: 'UNSTABLE', actual: currentBuild.result
  199. }
  200. }
  201. }
  202. steps {
  203. script {
  204. npmGithubPrComment("""Docker Image for build ${BUILD_NUMBER} is available on
  205. [DockerHub](https://cloud.docker.com/repository/docker/nginxproxymanager/${IMAGE}-dev)
  206. as `nginxproxymanager/${IMAGE}-dev:${BRANCH_LOWER}`
  207. **Note:** ensure you backup your NPM instance before testing this image! Especially if there are database changes
  208. **Note:** this is a different docker image namespace than the official image
  209. """, true)
  210. }
  211. }
  212. }
  213. }
  214. }
  215. }
  216. post {
  217. always {
  218. sh 'echo Reverting ownership'
  219. sh 'docker run --rm -v "$(pwd):/data" jc21/ci-tools chown -R "$(id -u):$(id -g)" /data'
  220. printResult(true)
  221. }
  222. failure {
  223. archiveArtifacts(artifacts: 'debug/**/*.*', allowEmptyArchive: true)
  224. }
  225. unstable {
  226. archiveArtifacts(artifacts: 'debug/**/*.*', allowEmptyArchive: true)
  227. }
  228. }
  229. }
  230. def getVersion() {
  231. ver = sh(script: 'cat .version', returnStdout: true)
  232. return ver.trim()
  233. }
  234. def getCommit() {
  235. ver = sh(script: 'git log -n 1 --format=%h', returnStdout: true)
  236. return ver.trim()
  237. }