backfill_project_image_name.js 1.3 KB

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