Jenkinsfile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. // Initialize variables to signal that a given stage finished.
  2. // We use them to build a graph of interconnected steps/dependencies.
  3. // - Incoming edges use "waitUntil" and reference the given variables of dependencies.
  4. // - Outgoing edges set the given variable to true.
  5. def action_test_frontend_ct_build = false
  6. def action_build_deps = false
  7. def action_copy_external_pages = false
  8. def action_build_dev = false
  9. def action_test_acceptance_app_server_pro = false
  10. def action_build_webpack = false
  11. def action_test_acceptance_app_saas = false
  12. def action_build_pug = false
  13. def action_build_production= false
  14. pipeline {
  15. agent {
  16. node {
  17. // Select a VM with the given tabel.
  18. label 'jenkins-agent-web'
  19. // Use the monorepo checkout in /workspace.
  20. customWorkspace '/workspace'
  21. }
  22. }
  23. options {
  24. // Print timestamp next to each log line.
  25. timestamps()
  26. // Abort build after hitting first failure.
  27. parallelsAlwaysFailFast()
  28. retry(3)
  29. timeout(time: 15, unit: 'MINUTES')
  30. }
  31. environment {
  32. IMAGE_NAME = 'web'
  33. PROJECT_NAME = 'web'
  34. IMAGE_REPO = 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/web'
  35. AR_REPO_LOCATION = 'us-east1'
  36. AR_URL = 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker'
  37. DOCKER_COMPOSE_FLAGS = '-f docker-compose.ci.yml'
  38. BRANCH_NAME = "${env.CHANGE_BRANCH ? env.CHANGE_BRANCH : env.BRANCH_NAME}"
  39. JENKINS_BUILD_NUMBER = "${BUILD_NUMBER}" // preserve original BUILD_NUMBER
  40. BUILD_NUMBER = "${SHORT_SHA}_${BUILD_NUMBER}" // mimic the format used for Cloud Build
  41. COMMIT_SHA = "${GIT_COMMIT}"
  42. SHORT_SHA = "${GIT_COMMIT.take(7)}"
  43. CDN_STAG = "gs://ol-stag-web-assets-1"
  44. CDN_PROD = "gs://mgcp-1117973-ol-prod-web-assets-1"
  45. }
  46. stages {
  47. // Retries will use the same pipeline instance. Reset the vars.
  48. stage('Reset vars') {
  49. steps {
  50. script {
  51. action_test_frontend_ct_build = false
  52. action_build_deps = false
  53. action_copy_external_pages = false
  54. action_build_dev = false
  55. action_test_acceptance_app_server_pro = false
  56. action_build_webpack = false
  57. action_test_acceptance_app_saas = false
  58. action_build_pug = false
  59. action_build_production = false
  60. }
  61. }
  62. }
  63. stage ('Build, Test and Push') {
  64. parallel {
  65. stage('Copy external pages') {
  66. steps {
  67. dir('services/web') {
  68. sh 'bin/copy_external_pages'
  69. script {
  70. action_copy_external_pages = true
  71. }
  72. }
  73. }
  74. }
  75. stage('Prefetch Tests Images') {
  76. steps {
  77. dir('services/web') {
  78. sh 'docker compose -f docker-compose.ci.yml pull --quiet test_frontend_ct mongo redis_test ldap saml'
  79. }
  80. }
  81. }
  82. stage('Build Deps') {
  83. steps {
  84. dir('services/web') {
  85. sh 'make build_deps'
  86. }
  87. script {
  88. action_build_deps = true
  89. }
  90. }
  91. }
  92. stage('Push Deps') {
  93. steps {
  94. script {
  95. waitUntil {
  96. return action_build_deps
  97. }
  98. }
  99. dir('services/web') {
  100. sh 'docker push ${AR_URL}/${IMAGE_NAME}:${BRANCH_NAME}-deps'
  101. }
  102. }
  103. }
  104. stage('Build Dev') {
  105. steps {
  106. script {
  107. waitUntil {
  108. return action_build_deps && action_copy_external_pages
  109. }
  110. }
  111. dir('services/web') {
  112. sh 'make build_dev'
  113. }
  114. script {
  115. action_build_dev = true
  116. }
  117. }
  118. }
  119. stage ('Format') {
  120. steps {
  121. script {
  122. waitUntil {
  123. return action_build_dev
  124. }
  125. }
  126. dir('services/web') {
  127. sh 'make format_in_docker'
  128. }
  129. }
  130. }
  131. stage('Lint') {
  132. steps {
  133. script {
  134. waitUntil {
  135. return action_build_dev
  136. }
  137. }
  138. dir('services/web') {
  139. sh 'make lint_in_docker'
  140. }
  141. }
  142. }
  143. stage('Shellcheck') {
  144. steps {
  145. dir('services/web') {
  146. sh 'make shellcheck'
  147. }
  148. }
  149. }
  150. stage('Acceptance SaaS') {
  151. steps {
  152. script {
  153. waitUntil {
  154. return action_build_dev
  155. }
  156. }
  157. dir('services/web') {
  158. sh 'make test_acceptance_app_saas'
  159. }
  160. script {
  161. action_test_acceptance_app_saas = true
  162. }
  163. }
  164. }
  165. stage('Acceptance Server CE') {
  166. steps {
  167. script {
  168. waitUntil {
  169. return action_build_dev
  170. }
  171. }
  172. dir('services/web') {
  173. sh "make test_acceptance_app_server_ce"
  174. }
  175. }
  176. }
  177. stage('Acceptance Server Pro') {
  178. steps {
  179. script {
  180. waitUntil {
  181. return action_build_dev
  182. }
  183. }
  184. dir('services/web') {
  185. sh "make test_acceptance_app_server_pro"
  186. }
  187. script {
  188. action_test_acceptance_app_server_pro = true
  189. }
  190. }
  191. }
  192. stage('test_acceptance_modules_merged_saas_1') {
  193. steps {
  194. script {
  195. waitUntil {
  196. return action_build_dev
  197. }
  198. }
  199. dir('services/web') {
  200. sh "make test_acceptance_modules_merged_saas_1"
  201. }
  202. }
  203. }
  204. stage('test_acceptance_modules_merged_saas_2') {
  205. steps {
  206. script {
  207. waitUntil {
  208. return action_build_dev
  209. }
  210. }
  211. dir('services/web') {
  212. sh "make test_acceptance_modules_merged_saas_2"
  213. }
  214. }
  215. }
  216. stage('test_acceptance_modules_merged_saas_3') {
  217. steps {
  218. script {
  219. waitUntil {
  220. return action_build_dev
  221. }
  222. }
  223. dir('services/web') {
  224. sh "make test_acceptance_modules_merged_saas_3"
  225. }
  226. }
  227. }
  228. stage('test_acceptance_modules_merged_saas_4') {
  229. steps {
  230. script {
  231. waitUntil {
  232. return action_build_dev
  233. }
  234. }
  235. dir('services/web') {
  236. sh "make test_acceptance_modules_merged_saas_4"
  237. }
  238. }
  239. }
  240. stage('test_acceptance_modules_merged_server_ce') {
  241. steps {
  242. script {
  243. waitUntil {
  244. return action_build_dev
  245. }
  246. }
  247. dir('services/web') {
  248. sh "make test_acceptance_modules_merged_server_ce"
  249. }
  250. }
  251. }
  252. stage('test_acceptance_modules_merged_server_pro') {
  253. steps {
  254. script {
  255. waitUntil {
  256. return action_build_dev
  257. }
  258. }
  259. dir('services/web') {
  260. sh "make test_acceptance_modules_merged_server_pro"
  261. }
  262. }
  263. }
  264. stage('test_frontend') {
  265. steps {
  266. script {
  267. waitUntil {
  268. return action_build_dev
  269. }
  270. }
  271. dir('services/web') {
  272. sh "make test_frontend"
  273. }
  274. }
  275. }
  276. stage('test_writefull') {
  277. steps {
  278. script {
  279. waitUntil {
  280. return action_build_dev
  281. }
  282. }
  283. dir('services/web') {
  284. sh "make test_writefull"
  285. }
  286. }
  287. }
  288. stage('test_frontend_ct_build') {
  289. steps {
  290. script {
  291. waitUntil {
  292. return action_build_dev
  293. }
  294. }
  295. dir('services/web') {
  296. sh "make build_test_frontend_ct"
  297. }
  298. script {
  299. action_test_frontend_ct_build = true
  300. }
  301. }
  302. }
  303. stage('test_frontend_ct_core_other') {
  304. environment {
  305. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  306. }
  307. steps {
  308. script {
  309. waitUntil {
  310. return action_test_frontend_ct_build
  311. }
  312. }
  313. dir('services/web') {
  314. sh "make test_frontend_ct_core_other"
  315. }
  316. }
  317. }
  318. stage('test_frontend_ct_core_features') {
  319. environment {
  320. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  321. }
  322. steps {
  323. script {
  324. waitUntil {
  325. return action_test_frontend_ct_build
  326. }
  327. }
  328. dir('services/web') {
  329. sh "make test_frontend_ct_core_features"
  330. }
  331. }
  332. }
  333. stage('test_frontend_ct_modules') {
  334. environment {
  335. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  336. }
  337. steps {
  338. script {
  339. waitUntil {
  340. return action_test_frontend_ct_build
  341. }
  342. }
  343. dir('services/web') {
  344. sh "make test_frontend_ct_modules"
  345. }
  346. }
  347. }
  348. stage('test_frontend_ct_editor_visual') {
  349. steps {
  350. script {
  351. waitUntil {
  352. return action_test_frontend_ct_build
  353. }
  354. }
  355. dir('services/web') {
  356. sh "make test_frontend_ct_editor_visual"
  357. }
  358. }
  359. }
  360. stage('test_frontend_ct_editor_other') {
  361. steps {
  362. script {
  363. waitUntil {
  364. return action_test_frontend_ct_build
  365. }
  366. }
  367. dir('services/web') {
  368. sh "make test_frontend_ct_editor_other"
  369. }
  370. }
  371. }
  372. stage('Test Unit ESM') {
  373. steps {
  374. script {
  375. waitUntil {
  376. return action_build_dev
  377. }
  378. }
  379. dir('services/web') {
  380. sh "make test_unit_esm"
  381. }
  382. }
  383. }
  384. stage('Test Unit Mocha') {
  385. steps {
  386. script {
  387. waitUntil {
  388. return action_build_dev
  389. }
  390. }
  391. dir('services/web') {
  392. sh "make test_unit_mocha"
  393. }
  394. }
  395. }
  396. stage('Build Webpack'){
  397. steps {
  398. script {
  399. waitUntil {
  400. return action_build_dev && action_test_acceptance_app_server_pro
  401. }
  402. }
  403. dir('services/web') {
  404. sh 'make build_webpack'
  405. }
  406. script {
  407. action_build_webpack = true
  408. }
  409. }
  410. }
  411. stage('Build Pug') {
  412. steps {
  413. script {
  414. waitUntil {
  415. return action_build_dev && action_test_acceptance_app_server_pro
  416. }
  417. }
  418. dir('services/web') {
  419. sh 'make build_pug'
  420. }
  421. script {
  422. action_build_pug = true
  423. }
  424. }
  425. }
  426. stage('CDN Upload Image') {
  427. steps {
  428. script {
  429. waitUntil {
  430. return action_build_webpack
  431. }
  432. }
  433. dir('services/web') {
  434. sh 'make tar'
  435. sh 'bin/cdn_upload'
  436. }
  437. }
  438. }
  439. stage('Build Production'){
  440. steps {
  441. script {
  442. waitUntil {
  443. return action_build_webpack && action_build_pug
  444. }
  445. }
  446. dir('services/web') {
  447. sh 'make build'
  448. }
  449. script {
  450. action_build_production = true
  451. }
  452. }
  453. }
  454. stage('Sentry Upload') {
  455. steps {
  456. script {
  457. waitUntil {
  458. return action_build_webpack && action_build_production
  459. }
  460. }
  461. dir('services/web') {
  462. sh 'gcloud secrets versions access latest --secret=web-sentryclirc > .sentryclirc'
  463. sh 'make sentry_upload'
  464. }
  465. }
  466. post {
  467. cleanup {
  468. dir('services/web') {
  469. sh 'rm -f .sentryclirc'
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. stage('Push Production') {
  477. steps {
  478. dir('services/web') {
  479. sh 'make publish'
  480. }
  481. }
  482. }
  483. }
  484. post {
  485. // Ensure tear down of test containers, then run general Jenkins VM cleanup.
  486. cleanup {
  487. dir('services/web') {
  488. sh 'make clean'
  489. }
  490. sh 'make clean_jenkins'
  491. }
  492. }
  493. }
  494. // vim: set ft=groovy :