Jenkinsfile 12 KB

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