Jenkinsfile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. stage ('Build, Test and Push') {
  48. parallel {
  49. stage('Copy external pages') {
  50. steps {
  51. dir('services/web') {
  52. sh 'bin/copy_external_pages'
  53. script {
  54. action_copy_external_pages = true
  55. }
  56. }
  57. }
  58. }
  59. stage('Prefetch Tests Images') {
  60. steps {
  61. dir('services/web') {
  62. sh 'docker compose -f docker-compose.ci.yml pull --quiet test_frontend_ct mongo redis_test ldap saml'
  63. }
  64. }
  65. }
  66. stage('Build Deps') {
  67. steps {
  68. dir('services/web') {
  69. sh 'make build_deps'
  70. }
  71. script {
  72. action_build_deps = true
  73. }
  74. }
  75. }
  76. stage('Push Deps') {
  77. steps {
  78. script {
  79. waitUntil {
  80. return action_build_deps
  81. }
  82. }
  83. dir('services/web') {
  84. sh 'docker push ${AR_URL}/${IMAGE_NAME}:${BRANCH_NAME}-deps'
  85. }
  86. }
  87. }
  88. stage('Build Dev') {
  89. steps {
  90. script {
  91. waitUntil {
  92. return action_build_deps && action_copy_external_pages
  93. }
  94. }
  95. dir('services/web') {
  96. sh 'make build_dev'
  97. }
  98. script {
  99. action_build_dev = true
  100. }
  101. }
  102. }
  103. stage ('Format') {
  104. steps {
  105. script {
  106. waitUntil {
  107. return action_build_dev
  108. }
  109. }
  110. dir('services/web') {
  111. sh 'make format_in_docker'
  112. }
  113. }
  114. }
  115. stage('Lint') {
  116. steps {
  117. script {
  118. waitUntil {
  119. return action_build_dev
  120. }
  121. }
  122. dir('services/web') {
  123. sh 'make lint_in_docker'
  124. }
  125. }
  126. }
  127. stage('Shellcheck') {
  128. steps {
  129. dir('services/web') {
  130. sh 'make shellcheck'
  131. }
  132. }
  133. }
  134. stage('Acceptance SaaS') {
  135. steps {
  136. script {
  137. waitUntil {
  138. return action_build_dev
  139. }
  140. }
  141. dir('services/web') {
  142. sh 'make test_acceptance_app_saas'
  143. }
  144. script {
  145. action_test_acceptance_app_saas = true
  146. }
  147. }
  148. }
  149. stage('Acceptance Server CE') {
  150. steps {
  151. script {
  152. waitUntil {
  153. return action_build_dev
  154. }
  155. }
  156. dir('services/web') {
  157. sh "make test_acceptance_app_server_ce"
  158. }
  159. }
  160. }
  161. stage('Acceptance Server Pro') {
  162. steps {
  163. script {
  164. waitUntil {
  165. return action_build_dev
  166. }
  167. }
  168. dir('services/web') {
  169. sh "make test_acceptance_app_server_pro"
  170. }
  171. script {
  172. action_test_acceptance_app_server_pro = true
  173. }
  174. }
  175. }
  176. stage('test_acceptance_modules_merged_saas_1') {
  177. steps {
  178. script {
  179. waitUntil {
  180. return action_build_dev
  181. }
  182. }
  183. dir('services/web') {
  184. sh "make test_acceptance_modules_merged_saas_1"
  185. }
  186. }
  187. }
  188. stage('test_acceptance_modules_merged_saas_2') {
  189. steps {
  190. script {
  191. waitUntil {
  192. return action_build_dev
  193. }
  194. }
  195. dir('services/web') {
  196. sh "make test_acceptance_modules_merged_saas_2"
  197. }
  198. }
  199. }
  200. stage('test_acceptance_modules_merged_saas_3') {
  201. steps {
  202. script {
  203. waitUntil {
  204. return action_build_dev
  205. }
  206. }
  207. dir('services/web') {
  208. sh "make test_acceptance_modules_merged_saas_3"
  209. }
  210. }
  211. }
  212. stage('test_acceptance_modules_merged_saas_4') {
  213. steps {
  214. script {
  215. waitUntil {
  216. return action_build_dev
  217. }
  218. }
  219. dir('services/web') {
  220. sh "make test_acceptance_modules_merged_saas_4"
  221. }
  222. }
  223. }
  224. stage('test_acceptance_modules_merged_server_ce') {
  225. steps {
  226. script {
  227. waitUntil {
  228. return action_build_dev
  229. }
  230. }
  231. dir('services/web') {
  232. sh "make test_acceptance_modules_merged_server_ce"
  233. }
  234. }
  235. }
  236. stage('test_acceptance_modules_merged_server_pro') {
  237. steps {
  238. script {
  239. waitUntil {
  240. return action_build_dev
  241. }
  242. }
  243. dir('services/web') {
  244. sh "make test_acceptance_modules_merged_server_pro"
  245. }
  246. }
  247. }
  248. stage('test_frontend') {
  249. steps {
  250. script {
  251. waitUntil {
  252. return action_build_dev
  253. }
  254. }
  255. dir('services/web') {
  256. sh "make test_frontend"
  257. }
  258. }
  259. }
  260. stage('test_writefull') {
  261. steps {
  262. script {
  263. waitUntil {
  264. return action_build_dev
  265. }
  266. }
  267. dir('services/web') {
  268. sh "make test_writefull"
  269. }
  270. }
  271. }
  272. stage('test_frontend_ct_build') {
  273. steps {
  274. script {
  275. waitUntil {
  276. return action_build_dev
  277. }
  278. }
  279. dir('services/web') {
  280. sh "make build_test_frontend_ct"
  281. }
  282. script {
  283. action_test_frontend_ct_build = true
  284. }
  285. }
  286. }
  287. stage('test_frontend_ct_core_other') {
  288. environment {
  289. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  290. }
  291. steps {
  292. script {
  293. waitUntil {
  294. return action_test_frontend_ct_build
  295. }
  296. }
  297. dir('services/web') {
  298. sh "make test_frontend_ct_core_other"
  299. }
  300. }
  301. }
  302. stage('test_frontend_ct_core_features') {
  303. environment {
  304. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  305. }
  306. steps {
  307. script {
  308. waitUntil {
  309. return action_test_frontend_ct_build
  310. }
  311. }
  312. dir('services/web') {
  313. sh "make test_frontend_ct_core_features"
  314. }
  315. }
  316. }
  317. stage('test_frontend_ct_modules') {
  318. environment {
  319. CYPRESS_INTERNAL_BROWSER_CONNECT_TIMEOUT = '120000'
  320. }
  321. steps {
  322. script {
  323. waitUntil {
  324. return action_test_frontend_ct_build
  325. }
  326. }
  327. dir('services/web') {
  328. sh "make test_frontend_ct_modules"
  329. }
  330. }
  331. }
  332. stage('test_frontend_ct_editor_visual') {
  333. steps {
  334. script {
  335. waitUntil {
  336. return action_test_frontend_ct_build
  337. }
  338. }
  339. dir('services/web') {
  340. sh "make test_frontend_ct_editor_visual"
  341. }
  342. }
  343. }
  344. stage('test_frontend_ct_editor_other') {
  345. steps {
  346. script {
  347. waitUntil {
  348. return action_test_frontend_ct_build
  349. }
  350. }
  351. dir('services/web') {
  352. sh "make test_frontend_ct_editor_other"
  353. }
  354. }
  355. }
  356. stage('Test Unit ESM') {
  357. steps {
  358. script {
  359. waitUntil {
  360. return action_build_dev
  361. }
  362. }
  363. dir('services/web') {
  364. sh "make test_unit_esm"
  365. }
  366. }
  367. }
  368. stage('Test Unit Mocha') {
  369. steps {
  370. script {
  371. waitUntil {
  372. return action_build_dev
  373. }
  374. }
  375. dir('services/web') {
  376. sh "make test_unit_mocha"
  377. }
  378. }
  379. }
  380. stage('Build Webpack'){
  381. steps {
  382. script {
  383. waitUntil {
  384. return action_build_dev && action_test_acceptance_app_server_pro
  385. }
  386. }
  387. dir('services/web') {
  388. sh 'make build_webpack'
  389. }
  390. script {
  391. action_build_webpack = true
  392. }
  393. }
  394. }
  395. stage('Build Pug') {
  396. steps {
  397. script {
  398. waitUntil {
  399. return action_build_dev && action_test_acceptance_app_server_pro
  400. }
  401. }
  402. dir('services/web') {
  403. sh 'make build_pug'
  404. }
  405. script {
  406. action_build_pug = true
  407. }
  408. }
  409. }
  410. stage('CDN Upload Image') {
  411. steps {
  412. script {
  413. waitUntil {
  414. return action_build_webpack
  415. }
  416. }
  417. dir('services/web') {
  418. sh 'make tar'
  419. sh 'bin/cdn_upload'
  420. }
  421. }
  422. }
  423. stage('Build Production'){
  424. steps {
  425. script {
  426. waitUntil {
  427. return action_build_webpack && action_build_pug
  428. }
  429. }
  430. dir('services/web') {
  431. sh 'make build'
  432. }
  433. script {
  434. action_build_production = true
  435. }
  436. }
  437. }
  438. stage('Sentry Upload') {
  439. steps {
  440. script {
  441. waitUntil {
  442. return action_build_webpack && action_build_production
  443. }
  444. }
  445. dir('services/web') {
  446. sh 'gcloud secrets versions access latest --secret=web-sentryclirc > .sentryclirc'
  447. sh 'make sentry_upload'
  448. }
  449. }
  450. post {
  451. cleanup {
  452. dir('services/web') {
  453. sh 'rm -f .sentryclirc'
  454. }
  455. }
  456. }
  457. }
  458. }
  459. }
  460. stage('Push Production') {
  461. steps {
  462. dir('services/web') {
  463. sh 'make publish'
  464. }
  465. }
  466. }
  467. }
  468. post {
  469. // Ensure tear down of test containers, then run general Jenkins VM cleanup.
  470. cleanup {
  471. dir('services/web') {
  472. sh 'make clean'
  473. }
  474. sh 'make clean_jenkins'
  475. }
  476. }
  477. }
  478. // vim: set ft=groovy :