settings.defaults.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. const Path = require('node:path')
  2. const os = require('node:os')
  3. const http = require('node:http')
  4. const https = require('node:https')
  5. http.globalAgent.keepAlive = false
  6. https.globalAgent.keepAlive = false
  7. const isPreEmptible = os.hostname().includes('pre-emp')
  8. module.exports = {
  9. compileSizeLimit: process.env.COMPILE_SIZE_LIMIT || '7mb',
  10. processLifespanLimitMs:
  11. parseInt(process.env.PROCESS_LIFE_SPAN_LIMIT_MS) || 60 * 60 * 24 * 1000 * 2,
  12. catchErrors: process.env.CATCH_ERRORS === 'true',
  13. path: {
  14. compilesDir:
  15. process.env.CLSI_COMPILES_PATH || Path.resolve(__dirname, '../compiles'),
  16. outputDir:
  17. process.env.CLSI_OUTPUT_PATH || Path.resolve(__dirname, '../output'),
  18. clsiCacheDir:
  19. process.env.CLSI_CACHE_PATH || Path.resolve(__dirname, '../cache'),
  20. synctexBaseDir(projectId) {
  21. return Path.join(this.compilesDir, projectId)
  22. },
  23. },
  24. internal: {
  25. clsi: {
  26. port: 3013,
  27. host: process.env.LISTEN_ADDRESS || '127.0.0.1',
  28. },
  29. load_balancer_agent: {
  30. report_load: process.env.LOAD_BALANCER_AGENT_REPORT_LOAD !== 'false',
  31. load_port: 3048,
  32. local_port: 3049,
  33. allow_maintenance:
  34. (
  35. process.env.LOAD_BALANCER_AGENT_ALLOW_MAINTENANCE ?? ''
  36. ).toLowerCase() !== 'false',
  37. },
  38. },
  39. apis: {
  40. clsi: {
  41. // Internal requests (used by tests only at the time of writing).
  42. url: `http://${process.env.CLSI_HOST || '127.0.0.1'}:3013`,
  43. // External url prefix for output files, e.g. for requests via load-balancers.
  44. outputUrlPrefix: `${process.env.ZONE ? `/zone/${process.env.ZONE}` : ''}`,
  45. },
  46. clsiPerf: {
  47. host: `${process.env.CLSI_PERF_HOST || '127.0.0.1'}:${
  48. process.env.CLSI_PERF_PORT || '3043'
  49. }`,
  50. },
  51. },
  52. smokeTest: process.env.SMOKE_TEST || false,
  53. project_cache_length_ms: 1000 * 60 * 60 * 24,
  54. parallelFileDownloads: process.env.FILESTORE_PARALLEL_FILE_DOWNLOADS || 1,
  55. filestoreDomainOveride: process.env.FILESTORE_DOMAIN_OVERRIDE,
  56. texliveImageNameOveride: process.env.TEX_LIVE_IMAGE_NAME_OVERRIDE,
  57. texliveOpenoutAny: process.env.TEXLIVE_OPENOUT_ANY,
  58. texliveMaxPrintLine: process.env.TEXLIVE_MAX_PRINT_LINE,
  59. enablePdfCaching: process.env.ENABLE_PDF_CACHING === 'true',
  60. enablePdfCachingDark: process.env.ENABLE_PDF_CACHING_DARK === 'true',
  61. pdfCachingMinChunkSize:
  62. parseInt(process.env.PDF_CACHING_MIN_CHUNK_SIZE, 10) || 1024,
  63. pdfCachingMaxProcessingTime:
  64. parseInt(process.env.PDF_CACHING_MAX_PROCESSING_TIME, 10) || 10 * 1000,
  65. pdfCachingEnableWorkerPool:
  66. process.env.PDF_CACHING_ENABLE_WORKER_POOL === 'true',
  67. pdfCachingWorkerPoolSize:
  68. parseInt(process.env.PDF_CACHING_WORKER_POOL_SIZE, 10) || 4,
  69. pdfCachingWorkerPoolBackLogLimit:
  70. parseInt(process.env.PDF_CACHING_WORKER_POOL_BACK_LOG_LIMIT, 10) || 40,
  71. compileConcurrencyLimit: isPreEmptible ? 32 : 64,
  72. }
  73. if (process.env.ALLOWED_COMPILE_GROUPS) {
  74. try {
  75. module.exports.allowedCompileGroups =
  76. process.env.ALLOWED_COMPILE_GROUPS.split(' ')
  77. } catch (error) {
  78. console.error(error, 'could not apply allowed compile group setting')
  79. process.exit(1)
  80. }
  81. }
  82. if (process.env.DOCKER_RUNNER) {
  83. let seccompProfilePath
  84. module.exports.clsi = {
  85. dockerRunner: process.env.DOCKER_RUNNER === 'true',
  86. docker: {
  87. runtime: process.env.DOCKER_RUNTIME,
  88. image:
  89. process.env.TEXLIVE_IMAGE || 'quay.io/sharelatex/texlive-full:2017.1',
  90. env: {
  91. HOME: '/tmp',
  92. CLSI: 1,
  93. },
  94. socketPath: '/var/run/docker.sock',
  95. user: process.env.TEXLIVE_IMAGE_USER || 'tex',
  96. },
  97. optimiseInDocker: true,
  98. expireProjectAfterIdleMs: 24 * 60 * 60 * 1000,
  99. checkProjectsIntervalMs: 10 * 60 * 1000,
  100. }
  101. try {
  102. // Override individual docker settings using path-based keys, e.g.:
  103. // compileGroupDockerConfigs = {
  104. // priority: { 'HostConfig.CpuShares': 100 }
  105. // beta: { 'dotted.path.here', 'value'}
  106. // }
  107. const compileGroupConfig = JSON.parse(
  108. process.env.COMPILE_GROUP_DOCKER_CONFIGS || '{}'
  109. )
  110. // Automatically clean up wordcount and synctex containers
  111. const defaultCompileGroupConfig = {
  112. wordcount: { 'HostConfig.AutoRemove': true },
  113. synctex: { 'HostConfig.AutoRemove': true },
  114. }
  115. module.exports.clsi.docker.compileGroupConfig = Object.assign(
  116. defaultCompileGroupConfig,
  117. compileGroupConfig
  118. )
  119. } catch (error) {
  120. console.error(error, 'could not apply compile group docker configs')
  121. process.exit(1)
  122. }
  123. try {
  124. seccompProfilePath = Path.resolve(__dirname, '../seccomp/clsi-profile.json')
  125. module.exports.clsi.docker.seccomp_profile = JSON.stringify(
  126. JSON.parse(require('node:fs').readFileSync(seccompProfilePath))
  127. )
  128. } catch (error) {
  129. console.error(
  130. error,
  131. `could not load seccomp profile from ${seccompProfilePath}`
  132. )
  133. process.exit(1)
  134. }
  135. if (process.env.APPARMOR_PROFILE) {
  136. try {
  137. module.exports.clsi.docker.apparmor_profile = process.env.APPARMOR_PROFILE
  138. } catch (error) {
  139. console.error(error, 'could not apply apparmor profile setting')
  140. process.exit(1)
  141. }
  142. }
  143. if (process.env.ALLOWED_IMAGES) {
  144. try {
  145. module.exports.clsi.docker.allowedImages =
  146. process.env.ALLOWED_IMAGES.split(' ')
  147. } catch (error) {
  148. console.error(error, 'could not apply allowed images setting')
  149. process.exit(1)
  150. }
  151. }
  152. module.exports.path.synctexBaseDir = () => '/compile'
  153. module.exports.path.sandboxedCompilesHostDir = process.env.COMPILES_HOST_DIR
  154. }