add support for passing additional environment parameters to command runner
includes an example of passing environment variables to chktex
This commit is contained in:
@@ -4,13 +4,18 @@ logger = require "logger-sharelatex"
|
|||||||
logger.info "using standard command runner"
|
logger.info "using standard command runner"
|
||||||
|
|
||||||
module.exports = CommandRunner =
|
module.exports = CommandRunner =
|
||||||
run: (project_id, command, directory, image, timeout, callback = (error) ->) ->
|
run: (project_id, command, directory, image, timeout, environment, callback = (error) ->) ->
|
||||||
command = (arg.replace('$COMPILE_DIR', directory) for arg in command)
|
command = (arg.replace('$COMPILE_DIR', directory) for arg in command)
|
||||||
logger.log project_id: project_id, command: command, directory: directory, "running command"
|
logger.log project_id: project_id, command: command, directory: directory, "running command"
|
||||||
logger.warn "timeouts and sandboxing are not enabled with CommandRunner"
|
logger.warn "timeouts and sandboxing are not enabled with CommandRunner"
|
||||||
|
|
||||||
|
# merge environment settings
|
||||||
|
env = {}
|
||||||
|
env[key] = value for key, value of process.env
|
||||||
|
env[key] = value for key, value of environment
|
||||||
|
|
||||||
# run command as detached process so it has its own process group (which can be killed if needed)
|
# run command as detached process so it has its own process group (which can be killed if needed)
|
||||||
proc = spawn command[0], command.slice(1), stdio: "inherit", cwd: directory, detached: true
|
proc = spawn command[0], command.slice(1), stdio: "inherit", cwd: directory, detached: true, env: env
|
||||||
|
|
||||||
proc.on "error", (err)->
|
proc.on "error", (err)->
|
||||||
logger.err err:err, project_id:project_id, command: command, directory: directory, "error running command"
|
logger.err err:err, project_id:project_id, command: command, directory: directory, "error running command"
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ module.exports = CompileManager =
|
|||||||
else
|
else
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
# set up environment variables for chktex
|
||||||
|
env = {}
|
||||||
|
if request.chktex?
|
||||||
|
env['CHKTEX_OPTIONS'] = '-nall -e9 -e10 -e15 -e16 -e27'
|
||||||
|
if request.chktex is 'error'
|
||||||
|
env['CHKTEX_EXIT_ON_ERROR'] = 1
|
||||||
|
|
||||||
injectDraftModeIfRequired (error) ->
|
injectDraftModeIfRequired (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
timer = new Metrics.Timer("run-compile")
|
timer = new Metrics.Timer("run-compile")
|
||||||
@@ -57,6 +64,7 @@ module.exports = CompileManager =
|
|||||||
compiler: request.compiler
|
compiler: request.compiler
|
||||||
timeout: request.timeout
|
timeout: request.timeout
|
||||||
image: request.imageName
|
image: request.imageName
|
||||||
|
environment: env
|
||||||
}, (error, output, stats, timings) ->
|
}, (error, output, stats, timings) ->
|
||||||
# compile was killed by user
|
# compile was killed by user
|
||||||
if error?.terminated
|
if error?.terminated
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ ProcessTable = {} # table of currently running jobs (pids or docker container n
|
|||||||
|
|
||||||
module.exports = LatexRunner =
|
module.exports = LatexRunner =
|
||||||
runLatex: (project_id, options, callback = (error) ->) ->
|
runLatex: (project_id, options, callback = (error) ->) ->
|
||||||
{directory, mainFile, compiler, timeout, image} = options
|
{directory, mainFile, compiler, timeout, image, environment} = options
|
||||||
compiler ||= "pdflatex"
|
compiler ||= "pdflatex"
|
||||||
timeout ||= 60000 # milliseconds
|
timeout ||= 60000 # milliseconds
|
||||||
|
|
||||||
logger.log directory: directory, compiler: compiler, timeout: timeout, mainFile: mainFile, "starting compile"
|
logger.log directory: directory, compiler: compiler, timeout: timeout, mainFile: mainFile, environment: environment, "starting compile"
|
||||||
|
|
||||||
# We want to run latexmk on the tex file which we will automatically
|
# We want to run latexmk on the tex file which we will automatically
|
||||||
# generate from the Rtex/Rmd/md file.
|
# generate from the Rtex/Rmd/md file.
|
||||||
@@ -34,7 +34,7 @@ module.exports = LatexRunner =
|
|||||||
|
|
||||||
id = "#{project_id}" # record running project under this id
|
id = "#{project_id}" # record running project under this id
|
||||||
|
|
||||||
ProcessTable[id] = CommandRunner.run project_id, command, directory, image, timeout, (error, output) ->
|
ProcessTable[id] = CommandRunner.run project_id, command, directory, image, timeout, environment, (error, output) ->
|
||||||
delete ProcessTable[id]
|
delete ProcessTable[id]
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
runs = output?.stderr?.match(/^Run number \d+ of .*latex/mg)?.length or 0
|
runs = output?.stderr?.match(/^Run number \d+ of .*latex/mg)?.length or 0
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler = "pdflatex"
|
compiler: @compiler = "pdflatex"
|
||||||
timeout: @timeout = 42000
|
timeout: @timeout = 42000
|
||||||
imageName: @image = "example.com/image"
|
imageName: @image = "example.com/image"
|
||||||
|
@env = {}
|
||||||
@Settings.compileDir = "compiles"
|
@Settings.compileDir = "compiles"
|
||||||
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
@compileDir = "#{@Settings.path.compilesDir}/#{@project_id}-#{@user_id}"
|
||||||
@ResourceWriter.syncResourcesToDisk = sinon.stub().callsArg(3)
|
@ResourceWriter.syncResourcesToDisk = sinon.stub().callsArg(3)
|
||||||
@@ -72,6 +73,7 @@ describe "CompileManager", ->
|
|||||||
compiler: @compiler
|
compiler: @compiler
|
||||||
timeout: @timeout
|
timeout: @timeout
|
||||||
image: @image
|
image: @image
|
||||||
|
environment: @env
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ describe "LatexRunner", ->
|
|||||||
@image = "example.com/image"
|
@image = "example.com/image"
|
||||||
@callback = sinon.stub()
|
@callback = sinon.stub()
|
||||||
@project_id = "project-id-123"
|
@project_id = "project-id-123"
|
||||||
|
@env = {'foo': '123'}
|
||||||
|
|
||||||
describe "runLatex", ->
|
describe "runLatex", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@CommandRunner.run = sinon.stub().callsArg(5)
|
@CommandRunner.run = sinon.stub().callsArg(6)
|
||||||
|
|
||||||
describe "normally", ->
|
describe "normally", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@@ -35,11 +36,12 @@ describe "LatexRunner", ->
|
|||||||
compiler: @compiler
|
compiler: @compiler
|
||||||
timeout: @timeout = 42000
|
timeout: @timeout = 42000
|
||||||
image: @image
|
image: @image
|
||||||
|
environment: @env
|
||||||
@callback
|
@callback
|
||||||
|
|
||||||
it "should run the latex command", ->
|
it "should run the latex command", ->
|
||||||
@CommandRunner.run
|
@CommandRunner.run
|
||||||
.calledWith(@project_id, sinon.match.any, @directory, @image, @timeout)
|
.calledWith(@project_id, sinon.match.any, @directory, @image, @timeout, @env)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with an .Rtex main file", ->
|
describe "with an .Rtex main file", ->
|
||||||
|
|||||||
Reference in New Issue
Block a user