Fix bug around spawning worker processes.
We were expecting to find the path to the `strawboss` binary implicitly from the environment, which meant that configuration was also implicit, and required more setup. Now the path to the binary is explicit in the StrawBoss runtime configuration, and the path to the configuration file can also be explicitly given.
This commit is contained in:
@ -41,6 +41,7 @@ Options
|
||||
else: "strawboss.config.json"
|
||||
|
||||
var cfg = loadStrawBossConfig(cfgFile)
|
||||
cfg.pathToExe = paramStr(0)
|
||||
if not existsDir(cfg.artifactsRepo):
|
||||
echo "Artifacts repo (" & cfg.artifactsRepo & ") does not exist. Creating..."
|
||||
createDir(cfg.artifactsRepo)
|
||||
|
@ -37,7 +37,9 @@ type
|
||||
StrawBossConfig* = object
|
||||
artifactsRepo*: string
|
||||
authSecret*: string
|
||||
filePath*: string
|
||||
debug*: bool
|
||||
pathToExe*: string
|
||||
projects*: seq[ProjectDef]
|
||||
pwdCost*: int8
|
||||
users*: seq[UserRef]
|
||||
@ -131,6 +133,7 @@ proc loadStrawBossConfig*(cfgFile: string): StrawBossConfig =
|
||||
raiseEx "strawboss config file not found: " & cfgFile
|
||||
|
||||
result = parseStrawBossConfig(parseFile(cfgFile))
|
||||
result.filePath = cfgFile
|
||||
|
||||
proc loadProjectConfig*(cfgFile: string): ProjectConfig =
|
||||
if not existsFile(cfgFile):
|
||||
|
@ -77,12 +77,16 @@ proc extractSession(cfg: StrawBossConfig, request: Request): Session =
|
||||
|
||||
result = fromJWT(cfg, headerVal[7..^1])
|
||||
|
||||
proc spawnWorker(req: RunRequest): Worker =
|
||||
proc spawnWorker(cfg: StrawBossConfig, req: RunRequest): Worker =
|
||||
## Kick off a new worker process with the given run information
|
||||
|
||||
let dir = mkdtemp()
|
||||
var args = @["run", req.projectName, req.stepName, "-r", req.buildRef, "-w", dir]
|
||||
var args = @["run", req.projectName, req.stepName, "-r", req.buildRef,
|
||||
"-w", dir, "-c", cfg.filePath]
|
||||
if req.forceRebuild: args.add("-f")
|
||||
debug "Launching worker: " & cfg.pathToExe & " " & args.join(" ")
|
||||
result = Worker(
|
||||
process: startProcess("strawboss", ".", args, loadEnv(), {poUsePath}),
|
||||
process: startProcess(cfg.pathToExe, ".", args, loadEnv(), {poUsePath}),
|
||||
workingDir: dir)
|
||||
|
||||
proc hashPwd*(pwd: string, cost: int8): string =
|
||||
@ -248,7 +252,18 @@ proc start*(cfg: StrawBossConfig): void =
|
||||
projectName: @"projectName",
|
||||
stepName: @"stepName",
|
||||
buildRef: if @"buildRef" != "": @"buildRef" else: nil,
|
||||
forceRebuild: false))) # TODO support this with optional query params
|
||||
forceRebuild: false) # TODO support this with optional query params
|
||||
|
||||
# TODO: instead of immediately spawning a worker, add the request to a
|
||||
# queue to be picked up by a worker. Allows capping the number of worker
|
||||
# prcesses, distributing, etc.
|
||||
let worker = spawnWorker(cfg, runRequest)
|
||||
workers.add(worker)
|
||||
|
||||
resp($(%*{
|
||||
"runRequest": runRequest,
|
||||
"status": { "state": "accepted", "details": "Run request has been queued." }
|
||||
}))
|
||||
|
||||
post "/service/debug/stop":
|
||||
if not cfg.debug: resp(Http404, makeJsonResp(Http404), JSON)
|
||||
|
Reference in New Issue
Block a user