Jenkinsfile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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: 'test/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: 'test/results') {
  163. archiveArtifacts(allowEmptyArchive: true, artifacts: '**/*', excludes: '**/*.xml')
  164. }
  165. }
  166. }
  167. }
  168. stage('Test Postgres') {
  169. environment {
  170. COMPOSE_PROJECT_NAME = "npm_${BRANCH_LOWER}_${BUILD_NUMBER}_postgres"
  171. COMPOSE_FILE = 'docker/docker-compose.ci.yml:docker/docker-compose.ci.postgres.yml'
  172. }
  173. when {
  174. not {
  175. equals expected: 'UNSTABLE', actual: currentBuild.result
  176. }
  177. }
  178. steps {
  179. sh 'rm -rf ./test/results/junit/*'
  180. sh './scripts/ci/fulltest-cypress'
  181. }
  182. post {
  183. always {
  184. // Dumps to analyze later
  185. sh 'mkdir -p debug/postgres'
  186. sh 'docker logs $(docker-compose ps --all -q fullstack) > debug/postgres/docker_fullstack.log 2>&1'
  187. sh 'docker logs $(docker-compose ps --all -q stepca) > debug/postgres/docker_stepca.log 2>&1'
  188. sh 'docker logs $(docker-compose ps --all -q pdns) > debug/postgres/docker_pdns.log 2>&1'
  189. sh 'docker logs $(docker-compose ps --all -q pdns-db) > debug/postgres/docker_pdns-db.log 2>&1'
  190. sh 'docker logs $(docker-compose ps --all -q dnsrouter) > debug/postgres/docker_dnsrouter.log 2>&1'
  191. sh 'docker logs $(docker-compose ps --all -q db-postgres) > debug/postgres/docker_db-postgres.log 2>&1'
  192. sh 'docker logs $(docker-compose ps --all -q authentik) > debug/postgres/docker_authentik.log 2>&1'
  193. sh 'docker logs $(docker-compose ps --all -q authentik-redis) > debug/postgres/docker_authentik-redis.log 2>&1'
  194. sh 'docker logs $(docker-compose ps --all -q authentik-ldap) > debug/postgres/docker_authentik-ldap.log 2>&1'
  195. junit 'test/results/junit/*'
  196. sh 'docker-compose down --remove-orphans --volumes -t 30 || true'
  197. }
  198. unstable {
  199. dir(path: 'test/results') {
  200. archiveArtifacts(allowEmptyArchive: true, artifacts: '**/*', excludes: '**/*.xml')
  201. }
  202. }
  203. }
  204. }
  205. stage('MultiArch Build') {
  206. when {
  207. not {
  208. equals expected: 'UNSTABLE', actual: currentBuild.result
  209. }
  210. }
  211. steps {
  212. sh "./scripts/buildx --push ${buildxPushTags}"
  213. }
  214. }
  215. stage('Docs / Comment') {
  216. parallel {
  217. stage('Docs Job') {
  218. when {
  219. allOf {
  220. branch pattern: "^(develop|master)\$", comparator: "REGEXP"
  221. not {
  222. equals expected: 'UNSTABLE', actual: currentBuild.result
  223. }
  224. }
  225. }
  226. steps {
  227. build wait: false, job: 'nginx-proxy-manager-docs', parameters: [string(name: 'docs_branch', value: "$BRANCH_NAME")]
  228. }
  229. }
  230. stage('PR Comment') {
  231. when {
  232. allOf {
  233. changeRequest()
  234. not {
  235. equals expected: 'UNSTABLE', actual: currentBuild.result
  236. }
  237. }
  238. }
  239. steps {
  240. script {
  241. npmGithubPrComment("""Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/nginxproxymanager/${IMAGE}-dev):
  242. ```
  243. nginxproxymanager/${IMAGE}-dev:${BRANCH_LOWER}
  244. ```
  245. > [!NOTE]
  246. > Ensure you backup your NPM instance before testing this image! Especially if there are database changes.
  247. > This is a different docker image namespace than the official image.
  248. > [!WARNING]
  249. > Changes and additions to DNS Providers require verification by at least 2 members of the community!
  250. """, true)
  251. }
  252. }
  253. }
  254. }
  255. }
  256. }
  257. post {
  258. always {
  259. sh 'echo Reverting ownership'
  260. sh 'docker run --rm -v "$(pwd):/data" jc21/ci-tools chown -R "$(id -u):$(id -g)" /data'
  261. printResult(true)
  262. }
  263. failure {
  264. archiveArtifacts(artifacts: 'debug/**/*.*', allowEmptyArchive: true)
  265. }
  266. unstable {
  267. archiveArtifacts(artifacts: 'debug/**/*.*', allowEmptyArchive: true)
  268. }
  269. }
  270. }
  271. def getVersion() {
  272. ver = sh(script: 'cat .version', returnStdout: true)
  273. return ver.trim()
  274. }
  275. def getCommit() {
  276. ver = sh(script: 'git log -n 1 --format=%h', returnStdout: true)
  277. return ver.trim()
  278. }