settings.defaults.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const Path = require('path')
  2. module.exports = {
  3. // Options are passed to Sequelize.
  4. // See http://sequelizejs.com/documentation#usage-options for details
  5. mysql: {
  6. clsi: {
  7. database: 'clsi',
  8. username: 'clsi',
  9. dialect: 'sqlite',
  10. storage:
  11. process.env.SQLITE_PATH || Path.resolve(__dirname, '../db/db.sqlite'),
  12. pool: {
  13. max: 1,
  14. min: 1
  15. },
  16. retry: {
  17. max: 10
  18. }
  19. }
  20. },
  21. compileSizeLimit: process.env.COMPILE_SIZE_LIMIT || '7mb',
  22. processLifespanLimitMs:
  23. parseInt(process.env.PROCESS_LIFE_SPAN_LIMIT_MS) || 60 * 60 * 24 * 1000 * 2,
  24. catchErrors: process.env.CATCH_ERRORS === 'true',
  25. path: {
  26. compilesDir: Path.resolve(__dirname, '../compiles'),
  27. outputDir: Path.resolve(__dirname, '../output'),
  28. clsiCacheDir: Path.resolve(__dirname, '../cache'),
  29. synctexBaseDir(projectId) {
  30. return Path.join(this.compilesDir, projectId)
  31. }
  32. },
  33. internal: {
  34. clsi: {
  35. port: 3013,
  36. host: process.env.LISTEN_ADDRESS || 'localhost'
  37. },
  38. load_balancer_agent: {
  39. report_load: true,
  40. load_port: 3048,
  41. local_port: 3049
  42. }
  43. },
  44. apis: {
  45. clsi: {
  46. url: `http://${process.env.CLSI_HOST || 'localhost'}:3013`
  47. }
  48. },
  49. smokeTest: process.env.SMOKE_TEST || false,
  50. project_cache_length_ms: 1000 * 60 * 60 * 24,
  51. parallelFileDownloads: process.env.FILESTORE_PARALLEL_FILE_DOWNLOADS || 1,
  52. parallelSqlQueryLimit: process.env.FILESTORE_PARALLEL_SQL_QUERY_LIMIT || 1,
  53. filestoreDomainOveride: process.env.FILESTORE_DOMAIN_OVERRIDE,
  54. texliveImageNameOveride: process.env.TEX_LIVE_IMAGE_NAME_OVERRIDE,
  55. texliveOpenoutAny: process.env.TEXLIVE_OPENOUT_ANY,
  56. sentry: {
  57. dsn: process.env.SENTRY_DSN
  58. }
  59. }
  60. if (process.env.ALLOWED_COMPILE_GROUPS) {
  61. try {
  62. module.exports.allowedCompileGroups = process.env.ALLOWED_COMPILE_GROUPS.split(
  63. ' '
  64. )
  65. } catch (error) {
  66. console.error(error, 'could not apply allowed compile group setting')
  67. process.exit(1)
  68. }
  69. }
  70. if (process.env.DOCKER_RUNNER) {
  71. let seccompProfilePath
  72. module.exports.clsi = {
  73. dockerRunner: process.env.DOCKER_RUNNER === 'true',
  74. docker: {
  75. runtime: process.env.DOCKER_RUNTIME,
  76. image:
  77. process.env.TEXLIVE_IMAGE || 'quay.io/sharelatex/texlive-full:2017.1',
  78. env: {
  79. HOME: '/tmp'
  80. },
  81. socketPath: '/var/run/docker.sock',
  82. user: process.env.TEXLIVE_IMAGE_USER || 'tex'
  83. },
  84. optimiseInDocker: true,
  85. expireProjectAfterIdleMs: 24 * 60 * 60 * 1000,
  86. checkProjectsIntervalMs: 10 * 60 * 1000
  87. }
  88. try {
  89. // Override individual docker settings using path-based keys, e.g.:
  90. // compileGroupDockerConfigs = {
  91. // priority: { 'HostConfig.CpuShares': 100 }
  92. // beta: { 'dotted.path.here', 'value'}
  93. // }
  94. const compileGroupConfig = JSON.parse(
  95. process.env.COMPILE_GROUP_DOCKER_CONFIGS || '{}'
  96. )
  97. // Automatically clean up wordcount and synctex containers
  98. const defaultCompileGroupConfig = {
  99. wordcount: { 'HostConfig.AutoRemove': true },
  100. synctex: { 'HostConfig.AutoRemove': true }
  101. }
  102. module.exports.clsi.docker.compileGroupConfig = Object.assign(
  103. defaultCompileGroupConfig,
  104. compileGroupConfig
  105. )
  106. } catch (error) {
  107. console.error(error, 'could not apply compile group docker configs')
  108. process.exit(1)
  109. }
  110. try {
  111. seccompProfilePath = Path.resolve(__dirname, '../seccomp/clsi-profile.json')
  112. module.exports.clsi.docker.seccomp_profile = JSON.stringify(
  113. JSON.parse(require('fs').readFileSync(seccompProfilePath))
  114. )
  115. } catch (error) {
  116. console.error(
  117. error,
  118. `could not load seccomp profile from ${seccompProfilePath}`
  119. )
  120. process.exit(1)
  121. }
  122. if (process.env.ALLOWED_IMAGES) {
  123. try {
  124. module.exports.clsi.docker.allowedImages = process.env.ALLOWED_IMAGES.split(
  125. ' '
  126. )
  127. } catch (error) {
  128. console.error(error, 'could not apply allowed images setting')
  129. process.exit(1)
  130. }
  131. }
  132. module.exports.path.synctexBaseDir = () => '/compile'
  133. module.exports.path.sandboxedCompilesHostDir = process.env.COMPILES_HOST_DIR
  134. module.exports.path.synctexBinHostPath = process.env.SYNCTEX_BIN_HOST_PATH
  135. }