Finished refactor to base the build process around explicit run instances.

* Implemented periodic maintenance window.
* Moved worker creation into the core module.
* Worker processes no longer create run requests, but read queued requests from
  the file system.
* Build status and logs have been moved into the StrawBoss data directory.
* An initial build status is recorded when the job is queued.
* Build status is recorded for build references as well as actual versions.
  So there will be a build status for "master", for example, that is
  overwritten whenever "master" is built for that step.
* RunRequests now include a timestamp.
* Added a Run object to contain both a RunRequest and the corresponding
  BuildStatus for that run.
* API endpoints that talk about runs now return Run objects instead of
  RunRequests.
* Moved all data layer operations into the core module so that the
  "database API" only lives in one place.
This commit is contained in:
Jonathan Bernard
2017-11-23 07:30:48 -06:00
parent e000b37c35
commit 82a7b301ea
10 changed files with 364 additions and 228 deletions

View File

@ -1,4 +1,4 @@
import cliutils, docopt, os, sequtils, tempfile, uuids
import cliutils, docopt, os, sequtils, strutils, tempfile, uuids
import strawbosspkg/configuration
import strawbosspkg/core
@ -16,25 +16,13 @@ when isMainModule:
let doc = """
Usage:
strawboss serve [options]
strawboss run <project> <step> [options]
strawboss run <requestFile>
strawboss hashpwd <pwd>
Options
-c --config-file <cfgFile> Use this config file instead of the default
(strawboss.config.json).
-f --force-rebuild Force a build step to re-run even we have cached
results from building that step before for this
version of the project.
-r --reference <ref> Build the project at this commit reference.
-i --run-id <id> Use the given UUID as the run ID. If not given, a
new UUID is generated for this run.
-w --workspace <workspace> Use the given directory as the build workspace.
"""
let args = docopt(doc, version = "strawboss v" & SB_VER)
@ -53,25 +41,24 @@ Options
if args["run"]:
let wkspDir = if args["--workspace"]: $args["--workspace"] else: mkdtemp()
var req: RunRequest
try: req = loadRunRequest($args["<requestFile>"])
except:
echo "strawboss: unable to parse run request (" & $args["<requestFile>"] & ")"
quit(QuitFailure)
try:
let req = RunRequest(
id: if args["--run-id"]: parseUUID($args["--run-id"]) else: genUUID(),
projectName: $args["<project>"],
stepName: $args["<step>"],
buildRef: if args["--reference"]: $args["--reference"] else: nil,
forceRebuild: args["--force-rebuild"],
workspaceDir: wkspDir)
if req.workspaceDir.isNilOrEmpty: req.workspaceDir = mkdtemp()
let status = core.initiateRun(cfg, req, logProcOutput)
if status.state == "failed": raiseEx status.details
if status.state == BuildState.failed: raiseEx status.details
echo "strawboss: build passed."
except:
echo "strawboss: build FAILED: " & getCurrentExceptionMsg() & "."
quit(QuitFailure)
finally:
if existsDir(wkspDir): removeDir(wkspDir)
if existsDir(req.workspaceDir): removeDir(req.workspaceDir)
elif args["serve"]: server.start(cfg)