From d924da0d2deddff0ccbc3928991d0a6df07215ed Mon Sep 17 00:00:00 2001 From: James Allen Date: Tue, 12 Jan 2016 17:04:42 +0000 Subject: [PATCH] Allow optional image name to be passed --- services/clsi/app/coffee/CommandRunner.coffee | 2 +- services/clsi/app/coffee/CompileManager.coffee | 1 + services/clsi/app/coffee/LatexRunner.coffee | 4 ++-- services/clsi/app/coffee/RequestParser.coffee | 4 +++- services/clsi/test/unit/coffee/CompileManagerTests.coffee | 2 ++ services/clsi/test/unit/coffee/LatexRunnerTests.coffee | 7 +++++-- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/clsi/app/coffee/CommandRunner.coffee b/services/clsi/app/coffee/CommandRunner.coffee index 55dec333d6..41cbfaa8ef 100644 --- a/services/clsi/app/coffee/CommandRunner.coffee +++ b/services/clsi/app/coffee/CommandRunner.coffee @@ -2,7 +2,7 @@ spawn = require("child_process").spawn logger = require "logger-sharelatex" module.exports = CommandRunner = - run: (project_id, command, directory, timeout, callback = (error) ->) -> + run: (project_id, command, directory, image, timeout, callback = (error) ->) -> command = (arg.replace('$COMPILE_DIR', directory) for arg in command) logger.log project_id: project_id, command: command, directory: directory, "running command" logger.warn "timeouts and sandboxing are not enabled with CommandRunner" diff --git a/services/clsi/app/coffee/CompileManager.coffee b/services/clsi/app/coffee/CompileManager.coffee index 945da42e70..e7e884998e 100644 --- a/services/clsi/app/coffee/CompileManager.coffee +++ b/services/clsi/app/coffee/CompileManager.coffee @@ -28,6 +28,7 @@ module.exports = CompileManager = mainFile: request.rootResourcePath compiler: request.compiler timeout: request.timeout + image: request.imageName }, (error) -> return callback(error) if error? logger.log project_id: request.project_id, time_taken: Date.now() - timer.start, "done compile" diff --git a/services/clsi/app/coffee/LatexRunner.coffee b/services/clsi/app/coffee/LatexRunner.coffee index cd6e356195..169a216f90 100644 --- a/services/clsi/app/coffee/LatexRunner.coffee +++ b/services/clsi/app/coffee/LatexRunner.coffee @@ -6,7 +6,7 @@ CommandRunner = require(Settings.clsi?.commandRunner or "./CommandRunner") module.exports = LatexRunner = runLatex: (project_id, options, callback = (error) ->) -> - {directory, mainFile, compiler, timeout} = options + {directory, mainFile, compiler, timeout, image} = options compiler ||= "pdflatex" timeout ||= 60000 # milliseconds @@ -27,7 +27,7 @@ module.exports = LatexRunner = else return callback new Error("unknown compiler: #{compiler}") - CommandRunner.run project_id, command, directory, timeout, callback + CommandRunner.run project_id, command, directory, image, timeout, callback _latexmkBaseCommand: [ "latexmk", "-cd", "-f", "-jobname=output", "-auxdir=$COMPILE_DIR", "-outdir=$COMPILE_DIR"] diff --git a/services/clsi/app/coffee/RequestParser.coffee b/services/clsi/app/coffee/RequestParser.coffee index 53268103a2..1b4e06d9d8 100644 --- a/services/clsi/app/coffee/RequestParser.coffee +++ b/services/clsi/app/coffee/RequestParser.coffee @@ -21,6 +21,9 @@ module.exports = RequestParser = compile.options.timeout default: RequestParser.MAX_TIMEOUT type: "number" + response.imageName = @_parseAttribute "imageName", + compile.options.imageName, + type: "string" if response.timeout > RequestParser.MAX_TIMEOUT response.timeout = RequestParser.MAX_TIMEOUT @@ -71,7 +74,6 @@ module.exports = RequestParser = throw "#{name} attribute should be a #{options.type}" else return options.default if options.default? - throw "Default not implemented" return attribute _sanitizePath: (path) -> diff --git a/services/clsi/test/unit/coffee/CompileManagerTests.coffee b/services/clsi/test/unit/coffee/CompileManagerTests.coffee index 87f424b0f9..dff30524f1 100644 --- a/services/clsi/test/unit/coffee/CompileManagerTests.coffee +++ b/services/clsi/test/unit/coffee/CompileManagerTests.coffee @@ -44,6 +44,7 @@ describe "CompileManager", -> project_id: @project_id = "project-id-123" compiler: @compiler = "pdflatex" timeout: @timeout = 42000 + imageName: @image = "example.com/image" @Settings.compileDir = "compiles" @compileDir = "#{@Settings.path.compilesDir}/#{@project_id}" @ResourceWriter.syncResourcesToDisk = sinon.stub().callsArg(3) @@ -64,6 +65,7 @@ describe "CompileManager", -> mainFile: @rootResourcePath compiler: @compiler timeout: @timeout + image: @image }) .should.equal true diff --git a/services/clsi/test/unit/coffee/LatexRunnerTests.coffee b/services/clsi/test/unit/coffee/LatexRunnerTests.coffee index d3782a6f3c..ace3d18ab7 100644 --- a/services/clsi/test/unit/coffee/LatexRunnerTests.coffee +++ b/services/clsi/test/unit/coffee/LatexRunnerTests.coffee @@ -19,12 +19,13 @@ describe "LatexRunner", -> @directory = "/local/compile/directory" @mainFile = "main-file.tex" @compiler = "pdflatex" + @image = "example.com/image" @callback = sinon.stub() @project_id = "project-id-123" describe "runLatex", -> beforeEach -> - @CommandRunner.run = sinon.stub().callsArg(4) + @CommandRunner.run = sinon.stub().callsArg(5) describe "normally", -> beforeEach -> @@ -33,11 +34,12 @@ describe "LatexRunner", -> mainFile: @mainFile compiler: @compiler timeout: @timeout = 42000 + image: @image @callback it "should run the latex command", -> @CommandRunner.run - .calledWith(@project_id, sinon.match.any, @directory, @timeout) + .calledWith(@project_id, sinon.match.any, @directory, @image, @timeout) .should.equal true describe "with an .Rtex main file", -> @@ -46,6 +48,7 @@ describe "LatexRunner", -> directory: @directory mainFile: "main-file.Rtex" compiler: @compiler + image: @image timeout: @timeout = 42000 @callback