settings.defaults.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. path: {
  25. compilesDir: Path.resolve(__dirname, '../compiles'),
  26. outputDir: Path.resolve(__dirname, '../output'),
  27. clsiCacheDir: Path.resolve(__dirname, '../cache'),
  28. synctexBaseDir(projectId) {
  29. return Path.join(this.compilesDir, projectId)
  30. }
  31. },
  32. internal: {
  33. clsi: {
  34. port: 3013,
  35. host: process.env.LISTEN_ADDRESS || 'localhost'
  36. },
  37. load_balancer_agent: {
  38. report_load: true,
  39. load_port: 3048,
  40. local_port: 3049
  41. }
  42. },
  43. apis: {
  44. clsi: {
  45. url: `http://${process.env.CLSI_HOST || 'localhost'}:3013`
  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. parallelSqlQueryLimit: process.env.FILESTORE_PARALLEL_SQL_QUERY_LIMIT || 1,
  52. filestoreDomainOveride: process.env.FILESTORE_DOMAIN_OVERRIDE,
  53. texliveImageNameOveride: process.env.TEX_LIVE_IMAGE_NAME_OVERRIDE,
  54. texliveOpenoutAny: process.env.TEXLIVE_OPENOUT_ANY,
  55. sentry: {
  56. dsn: process.env.SENTRY_DSN
  57. }
  58. }
  59. if (process.env.ALLOWED_COMPILE_GROUPS) {
  60. try {
  61. module.exports.allowedCompileGroups = process.env.ALLOWED_COMPILE_GROUPS.split(
  62. ' '
  63. )
  64. } catch (error) {
  65. console.error(error, 'could not apply allowed compile group setting')
  66. process.exit(1)
  67. }
  68. }
  69. if (process.env.DOCKER_RUNNER) {
  70. let seccompProfilePath
  71. module.exports.clsi = {
  72. dockerRunner: process.env.DOCKER_RUNNER === 'true',
  73. docker: {
  74. runtime: process.env.DOCKER_RUNTIME,
  75. image:
  76. process.env.TEXLIVE_IMAGE || 'quay.io/sharelatex/texlive-full:2017.1',
  77. env: {
  78. HOME: '/tmp'
  79. },
  80. socketPath: '/var/run/docker.sock',
  81. user: process.env.TEXLIVE_IMAGE_USER || 'tex'
  82. },
  83. optimiseInDocker: true,
  84. expireProjectAfterIdleMs: 24 * 60 * 60 * 1000,
  85. checkProjectsIntervalMs: 10 * 60 * 1000
  86. }
  87. try {
  88. // Override individual docker settings using path-based keys, e.g.:
  89. // compileGroupDockerConfigs = {
  90. // priority: { 'HostConfig.CpuShares': 100 }
  91. // beta: { 'dotted.path.here', 'value'}
  92. // }
  93. const compileGroupConfig = JSON.parse(
  94. process.env.COMPILE_GROUP_DOCKER_CONFIGS || '{}'
  95. )
  96. // Automatically clean up wordcount and synctex containers
  97. const defaultCompileGroupConfig = {
  98. wordcount: { 'HostConfig.AutoRemove': true },
  99. synctex: { 'HostConfig.AutoRemove': true }
  100. }
  101. module.exports.clsi.docker.compileGroupConfig = Object.assign(
  102. defaultCompileGroupConfig,
  103. compileGroupConfig
  104. )
  105. } catch (error) {
  106. console.error(error, 'could not apply compile group docker configs')
  107. process.exit(1)
  108. }
  109. try {
  110. seccompProfilePath = Path.resolve(__dirname, '../seccomp/clsi-profile.json')
  111. module.exports.clsi.docker.seccomp_profile = JSON.stringify(
  112. JSON.parse(require('fs').readFileSync(seccompProfilePath))
  113. )
  114. } catch (error) {
  115. console.error(
  116. error,
  117. `could not load seccomp profile from ${seccompProfilePath}`
  118. )
  119. process.exit(1)
  120. }
  121. if (process.env.ALLOWED_IMAGES) {
  122. try {
  123. module.exports.clsi.docker.allowedImages = process.env.ALLOWED_IMAGES.split(
  124. ' '
  125. )
  126. } catch (error) {
  127. console.error(error, 'could not apply allowed images setting')
  128. process.exit(1)
  129. }
  130. }
  131. module.exports.path.synctexBaseDir = () => '/compile'
  132. module.exports.path.sandboxedCompilesHostDir = process.env.COMPILES_HOST_DIR
  133. module.exports.path.synctexBinHostPath = process.env.SYNCTEX_BIN_HOST_PATH
  134. }