From 3983190c864978c04621ba4ccd7e81aa3b3582fa Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 8 Jan 2025 14:25:48 +0100 Subject: [PATCH] Add a new `lifetime` property to the `container` process Closes #1013 Signed-off-by: Charles d'Avernas --- dsl-reference.md | 32 +++++++++++++++++++ examples/run-container-cleanup-always.yaml | 12 +++++++ .../run-container-cleanup-eventually.yaml | 14 ++++++++ schema/workflow.yaml | 30 +++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 examples/run-container-cleanup-always.yaml create mode 100644 examples/run-container-cleanup-eventually.yaml diff --git a/dsl-reference.md b/dsl-reference.md index 92b02d60..da1d0286 100644 --- a/dsl-reference.md +++ b/dsl-reference.md @@ -55,6 +55,7 @@ + [HTTP Response](#http-response) + [HTTP Request](#http-request) + [URI Template](#uri-template) + + [Container Lifetime](#container-lifetime) ## Abstract @@ -772,6 +773,7 @@ Enables the execution of external processes encapsulated within a containerized | ports | `map` | `no` | The container's port mappings, if any | | volumes | `map` | `no` | The container's volume mappings, if any | | environment | `map` | `no` | A key/value mapping of the environment variables, if any, to use when running the configured process | +| lifetime | [`containerLifetime`](#container-lifetime) | `no` | An object used to configure the container's lifetime. | ###### Examples @@ -1888,3 +1890,33 @@ This has the following limitations compared to runtime expressions: ```yaml uri: https://petstore.swagger.io/v2/pet/{petId} ``` + +### Container Lifetime + +Configures the lifetime of a container. + +#### Properties + +| Property | Type | Required | Description | +|----------|:----:|:--------:|-------------| +| cleanup | `string` | `yes` | The cleanup policy to use.
*Supported values are:
- `always`: the container is deleted immediately after execution.
-`never`: the runtime should never delete the container.
-`eventually`: the container is deleted after a configured amount of time after its execution.*
*Defaults to `never`.* | +| after | [`duration`](#duration) | `no` | The [`duration`](#duration), if any, after which to delete the container once executed.
*Required if `cleanup` has been set to `eventually`, otherwise ignored.* | + +#### Examples + +```yaml +document: + dsl: '1.0.0-alpha5' + namespace: test + name: run-container-example + version: '0.1.0' +do: + - runContainer: + run: + container: + image: fake-image + lifetime: + cleanup: eventually + after: + minutes: 30 +``` \ No newline at end of file diff --git a/examples/run-container-cleanup-always.yaml b/examples/run-container-cleanup-always.yaml new file mode 100644 index 00000000..f399d07b --- /dev/null +++ b/examples/run-container-cleanup-always.yaml @@ -0,0 +1,12 @@ +document: + dsl: '1.0.0-alpha5' + namespace: test + name: run-container + version: '0.1.0' +do: + - runContainer: + run: + container: + image: hello-world + lifetime: + cleanup: always \ No newline at end of file diff --git a/examples/run-container-cleanup-eventually.yaml b/examples/run-container-cleanup-eventually.yaml new file mode 100644 index 00000000..58fbfdf3 --- /dev/null +++ b/examples/run-container-cleanup-eventually.yaml @@ -0,0 +1,14 @@ +document: + dsl: '1.0.0-alpha5' + namespace: test + name: run-container + version: '0.1.0' +do: + - runContainer: + run: + container: + image: hello-world + lifetime: + cleanup: eventually + after: + minutes: 30 \ No newline at end of file diff --git a/schema/workflow.yaml b/schema/workflow.yaml index aecbeacb..a2765400 100644 --- a/schema/workflow.yaml +++ b/schema/workflow.yaml @@ -611,6 +611,10 @@ $defs: type: object title: ContainerEnvironment description: A key/value mapping of the environment variables, if any, to use when running the configured process. + lifetime: + $ref: '#/$defs/containerLifetime' + title: ContainerLifetime + description: An object, if any, used to configure the container's lifetime required: [ image ] required: [ container ] - title: RunScript @@ -1535,3 +1539,29 @@ $defs: title: RuntimeExpression description: A runtime expression. pattern: "^\\s*\\$\\{.+\\}\\s*$" + containerLifetime: + type: object + title: ContainerLifetime + description: The configuration of a container's lifetime + unevaluatedProperties: false + properties: + cleanup: + type: string + title: ContainerCleanupPolicy + description: The container cleanup policy to use + enum: [ always, never, eventually ] + default: never + after: + $ref: '#/$defs/duration' + title: ContainerLifetimeDuration + description: The duration after which to cleanup the container, in case the cleanup policy has been set to 'eventually' + required: [ cleanup ] + if: + properties: + cleanup: + const: eventually + then: + required: [ after ] + else: + not: + required: [ after ] \ No newline at end of file