Jenkinsfile 12 KB

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