backfill_project_image_name.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @ts-check
  2. import minimist from 'minimist'
  3. import { batchedUpdateWithResultHandling } from '@overleaf/mongo-utils/batchedUpdate.js'
  4. import { db } from '../app/src/infrastructure/mongodb.mjs'
  5. const argv = minimist(process.argv.slice(2))
  6. const commit = argv.commit !== undefined
  7. let imageName = argv._[0]
  8. function usage() {
  9. console.log(
  10. 'Usage: node backfill_project_image_name.mjs --commit <texlive_docker_image>'
  11. )
  12. console.log(
  13. 'Argument <texlive_docker_image> is not required when TEX_LIVE_DOCKER_IMAGE is set.'
  14. )
  15. console.log(
  16. 'Environment variable ALL_TEX_LIVE_DOCKER_IMAGES must contain <texlive_docker_image>.'
  17. )
  18. }
  19. if (!imageName && process.env.TEX_LIVE_DOCKER_IMAGE) {
  20. imageName = process.env.TEX_LIVE_DOCKER_IMAGE
  21. }
  22. if (!imageName) {
  23. usage()
  24. process.exit(1)
  25. }
  26. if (!process.env.ALL_TEX_LIVE_DOCKER_IMAGES) {
  27. console.error(
  28. 'Error: environment variable ALL_TEX_LIVE_DOCKER_IMAGES is not defined.'
  29. )
  30. usage()
  31. process.exit(1)
  32. }
  33. if (!process.env.ALL_TEX_LIVE_DOCKER_IMAGES.split(',').includes(imageName)) {
  34. console.error(
  35. `Error: ALL_TEX_LIVE_DOCKER_IMAGES doesn't contain ${imageName}`
  36. )
  37. usage()
  38. process.exit(1)
  39. }
  40. if (!commit) {
  41. console.error('DOING DRY RUN. TO SAVE CHANGES PASS --commit')
  42. process.exit(1)
  43. }
  44. batchedUpdateWithResultHandling(
  45. db.projects,
  46. { imageName: null },
  47. { $set: { imageName } }
  48. )