From 4382c0943c5e84477fcdf6f1d26397c8a60a4624 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 26 Nov 2017 14:35:09 +0100 Subject: Add: pipeline sub-API --- yarns/150-pipelines.yarn | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 yarns/150-pipelines.yarn (limited to 'yarns/150-pipelines.yarn') diff --git a/yarns/150-pipelines.yarn b/yarns/150-pipelines.yarn new file mode 100644 index 0000000..f0f678e --- /dev/null +++ b/yarns/150-pipelines.yarn @@ -0,0 +1,168 @@ + + +# Controller pipeline management + +The Ick2 controller manages information about named pipelines. +Pipelines are sequences of steps to achieve part of a project build. +They're described like resources like this: + + EXAMPLE pipeline resource + { + "name": "build-website", + "parameters": { + "foo": "bar" + }, + "actions": [ + { + "shell": "git clone git://git.liw.fi/ick2-website src" } + }, + { + "shell": "cd src && ikiwiki --setup ikiwiki.setup" + }, + { + "shell": "cd html && rsync -a --delete . server::/srv/http/ick2/." + } + ] + } + +In other words, there are several things that define a pipeline: + +* The `name`. This is used for referreing to the pipeline in the API. +* A set of parameters, which are currently ignored. +* A sequence of actions. At the moment, each action is a shell + command to be run, but that will change later. + +## Managing pipelines + +First we test the controller API for managing pipelines, without +running them. We start by starting an instance of the controller. + + SCENARIO managing pipelines + GIVEN an RSA key pair for token signing + AND an access token for user with scopes + ... uapi_pipelines_get + ... uapi_pipelines_post + ... uapi_pipelines_id_get + ... uapi_pipelines_id_put + ... uapi_pipelines_id_delete + AND controller config uses statedir at the state directory + AND a running ick controller + + WHEN user makes request GET /pipelines + THEN result has status code 200 + AND body matches { "pipelines": [] } + + WHEN user makes request POST /pipelines with a valid token and body + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "git clone git://repo src" }, + ... { "shell": "mkdir html" }, + ... { "shell": "ikiwiki src html" } + ... ] + ... } + THEN result has status code 201 + AND body matches + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "git clone git://repo src" }, + ... { "shell": "mkdir html" }, + ... { "shell": "ikiwiki src html" } + ... ] + ... } + +Creating a new pipeline with the same name is forbidden. + + WHEN user makes request POST /pipelines with a valid token and body + ... { + ... "name": "build_website" + ... } + THEN result has status code 409 + + WHEN user makes request GET /pipelines + THEN result has status code 200 + AND body matches + ... { + ... "pipelines": [ + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "git clone git://repo src" }, + ... { "shell": "mkdir html" }, + ... { "shell": "ikiwiki src html" } + ... ] + ... } + ... ] + ... } + + WHEN user stops ick controller + GIVEN a running ick controller + WHEN user makes request GET /pipelines/build_website + THEN result has status code 200 + AND body matches + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "git clone git://repo src" }, + ... { "shell": "mkdir html" }, + ... { "shell": "ikiwiki src html" } + ... ] + ... } + + WHEN user makes request PUT /pipelines/build_websitte with a valid token + ... and body + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "build-it" } + ... ] + ... } + THEN result has status code 200 + AND body matches + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "build-it" } + ... ] + ... } + + WHEN user makes request GET /pipelines/build_website + THEN result has status code 200 + AND body matches + ... { + ... "name": "build_website", + ... "actions": [ + ... { "shell": "build-it" } + ... ] + ... } + + WHEN user makes request DELETE /pipelines/build_website + THEN result has status code 200 + WHEN user makes request GET /pipelines/build_website + THEN result has status code 404 + + WHEN user makes request PUT /pipelines/doesnotexist with a valid token and body + ... { + ... "name": "doesnotexist" + ... } + THEN result has status code 404 + + FINALLY stop ick controller -- cgit v1.2.1