Decaf cleanup: simplify variable declarations

This commit is contained in:
Eric Mc Sween
2020-09-03 15:50:12 -04:00
parent c8371a8ea7
commit faad50ff4c

View File

@@ -1,4 +1,3 @@
let DockerRunner
const Settings = require('settings-sharelatex') const Settings = require('settings-sharelatex')
const logger = require('logger-sharelatex') const logger = require('logger-sharelatex')
const Docker = require('dockerode') const Docker = require('dockerode')
@@ -21,7 +20,7 @@ const usingSiblingContainers = () =>
let containerMonitorTimeout let containerMonitorTimeout
let containerMonitorInterval let containerMonitorInterval
module.exports = DockerRunner = { const DockerRunner = {
run( run(
projectId, projectId,
command, command,
@@ -32,7 +31,6 @@ module.exports = DockerRunner = {
compileGroup, compileGroup,
callback callback
) { ) {
let name
if (usingSiblingContainers()) { if (usingSiblingContainers()) {
const _newPath = Settings.path.sandboxedCompilesHostDir const _newPath = Settings.path.sandboxedCompilesHostDir
logger.log( logger.log(
@@ -49,14 +47,13 @@ module.exports = DockerRunner = {
) )
} }
const volumes = {} const volumes = { [directory]: '/compile' }
volumes[directory] = '/compile'
command = command.map((arg) => command = command.map((arg) =>
arg.toString().replace('$COMPILE_DIR', '/compile') arg.toString().replace('$COMPILE_DIR', '/compile')
) )
if (image == null) { if (image == null) {
;({ image } = Settings.clsi.docker) image = Settings.clsi.docker.image
} }
if ( if (
@@ -80,7 +77,8 @@ module.exports = DockerRunner = {
compileGroup compileGroup
) )
const fingerprint = DockerRunner._fingerprintContainer(options) const fingerprint = DockerRunner._fingerprintContainer(options)
options.name = name = `project-${projectId}-${fingerprint}` const name = `project-${projectId}-${fingerprint}`
options.name = name
// logOptions = _.clone(options) // logOptions = _.clone(options)
// logOptions?.HostConfig?.SecurityOpt = "secomp used, removed in logging" // logOptions?.HostConfig?.SecurityOpt = "secomp used, removed in logging"
@@ -179,19 +177,18 @@ module.exports = DockerRunner = {
error, error,
exitCode exitCode
) { ) {
let err
if (error != null) { if (error != null) {
return callback(error) return callback(error)
} }
if (exitCode === 137) { if (exitCode === 137) {
// exit status from kill -9 // exit status from kill -9
err = new Error('terminated') const err = new Error('terminated')
err.terminated = true err.terminated = true
return callback(err) return callback(err)
} }
if (exitCode === 1) { if (exitCode === 1) {
// exit status from chktex // exit status from chktex
err = new Error('exited') const err = new Error('exited')
err.code = exitCode err.code = exitCode
return callback(err) return callback(err)
} }
@@ -199,7 +196,7 @@ module.exports = DockerRunner = {
if (options != null && options.HostConfig != null) { if (options != null && options.HostConfig != null) {
options.HostConfig.SecurityOpt = null options.HostConfig.SecurityOpt = null
} }
logger.log({ err, exitCode, options }, 'docker container has exited') logger.log({ exitCode, options }, 'docker container has exited')
callbackIfFinished() callbackIfFinished()
}) })
} }
@@ -214,13 +211,11 @@ module.exports = DockerRunner = {
environment, environment,
compileGroup compileGroup
) { ) {
let m, year
let key, value, hostVol, dockerVol
const timeoutInSeconds = timeout / 1000 const timeoutInSeconds = timeout / 1000
const dockerVolumes = {} const dockerVolumes = {}
for (hostVol in volumes) { for (const hostVol in volumes) {
dockerVol = volumes[hostVol] const dockerVol = volumes[hostVol]
dockerVolumes[dockerVol] = {} dockerVolumes[dockerVol] = {}
if (volumes[hostVol].slice(-3).indexOf(':r') === -1) { if (volumes[hostVol].slice(-3).indexOf(':r') === -1) {
@@ -231,17 +226,14 @@ module.exports = DockerRunner = {
// merge settings and environment parameter // merge settings and environment parameter
const env = {} const env = {}
for (const src of [Settings.clsi.docker.env, environment || {}]) { for (const src of [Settings.clsi.docker.env, environment || {}]) {
for (key in src) { for (const key in src) {
value = src[key] const value = src[key]
env[key] = value env[key] = value
} }
} }
// set the path based on the image year // set the path based on the image year
if ((m = image.match(/:([0-9]+)\.[0-9]+/))) { const match = image.match(/:([0-9]+)\.[0-9]+/)
year = m[1] const year = match ? match[1] : '2014'
} else {
year = '2014'
}
env.PATH = `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/${year}/bin/x86_64-linux/` env.PATH = `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/${year}/bin/x86_64-linux/`
const options = { const options = {
Cmd: command, Cmd: command,
@@ -296,8 +288,7 @@ module.exports = DockerRunner = {
Settings.clsi.docker.compileGroupConfig[compileGroup] Settings.clsi.docker.compileGroupConfig[compileGroup]
) { ) {
const override = Settings.clsi.docker.compileGroupConfig[compileGroup] const override = Settings.clsi.docker.compileGroupConfig[compileGroup]
let key for (const key in override) {
for (key in override) {
_.set(options, key, override[key]) _.set(options, key, override[key])
} }
} }
@@ -627,3 +618,5 @@ module.exports = DockerRunner = {
} }
DockerRunner.startContainerMonitor() DockerRunner.startContainerMonitor()
module.exports = DockerRunner