settings.defaults.js 5.3 KB

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