backfill_project_image_name.mjs 1.3 KB

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