Skip to content

Commit ad2a273

Browse files
committed
Add SIP for target world validation
This SIP describes and motivates the functionality introduced in spinframework#2806. Signed-off-by: Till Schneidereit <[email protected]>
1 parent 0a4c05a commit ad2a273

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
title = "SIP 022 - Target Environment Validation"
2+
template = "main"
3+
date = "2024-03-14T01:01:01Z"
4+
---
5+
6+
Summary: Provide a mechanism to validate that a Spin application is compatible with its intended deployment environment(s).
7+
8+
9+
10+
Created: Aug 7, 2025
11+
12+
## Background
13+
14+
When developing a Spin application, developers might use features that are only available in a specific Spin environment. For example, an application might use a custom trigger or a host capability that is only available in a specific deployment environment, or in a self-hosted Spin instance with specific plugins.
15+
16+
Currently, there is no way to declare the intended deployment environment for an application and have Spin validate that the application is compatible with it. This can lead to situations where an application builds successfully but fails at runtime in the target environment due to missing dependencies, unsupported features, or other incompatibilities.
17+
18+
This SIP proposes a new mechanism to address this problem by allowing developers to specify the target environments for their applications and have Spin validate the compatibility of the application with those environments at build time.
19+
20+
## Proposal
21+
22+
The proposal is to introduce a new `targets` field in the `[application]` section of the `spin.toml` manifest file. This field will contain a list of identifiers for the target environments. Spin will use these identifiers to fetch environment definition files and validate the application against them.
23+
24+
### The `targets` field in `spin.toml`
25+
26+
The `targets` field is a list of strings or tables that identify the target environments. It can be specified in the `[application]` section of `spin.toml` like this:
27+
28+
```toml
29+
[application]
30+
name = "my-app"
31+
version = "1.0.0"
32+
targets = ["spin-up:3.3", "spinkube:0.4", { registry = "ghcr.io/my-org/environments", id = "my-env:1.0" }, { path = "local-env.toml" }]
33+
```
34+
35+
Each entry in the list can be:
36+
- A string that identifies an environment in the default registry (e.g., `"spin-up:3.3"`).
37+
- A table with `registry` and `id` keys to identify an environment in a custom OCI registry.
38+
- A table with a `path` key to specify a local environment definition file.
39+
40+
### Environment Definition Files
41+
42+
An environment definition is a TOML file that describes the capabilities of a Spin environment. It specifies the triggers that are available in the environment, and for each trigger, the WIT worlds that are compatible with it and the host capabilities that it supports.
43+
44+
Here is an example of an environment definition file:
45+
46+
```toml
47+
# spin-up.3.2.toml
48+
[triggers.http]
49+
worlds = ["spin:up/[email protected]", "spin:up/[email protected]"]
50+
capabilities = ["local_service_chaining"]
51+
52+
[triggers.redis]
53+
worlds = ["spin:up/[email protected]"]
54+
```
55+
56+
This file defines an environment that supports the `http` and `redis` triggers. The `http` trigger is compatible with two different WIT worlds and supports the `local_service_chaining` capability. The `redis` trigger is compatible with one WIT world and has no specific capabilities.
57+
58+
### Validation at Build Time
59+
60+
When the user runs `spin build`, Spin will perform the following steps if the `targets` field is present in `spin.toml`:
61+
62+
1. For each target environment specified in the `targets` field, Spin will fetch the corresponding environment definition file.
63+
2. For each component in the application, Spin will check if its trigger is supported in the target environment.
64+
3. If the trigger is supported, Spin will check if the component's WIT world is compatible with one of the worlds defined for that trigger in the environment definition.
65+
4. Spin will also check if all the capabilities required by the component are supported by the environment.
66+
67+
If any of these checks fail for any of the target environments, the build will fail with an error message indicating the incompatibility.
68+
69+
The user can bypass the validation by using the `--skip-target-checks` flag with the `spin build` command.
70+
71+
## Future work
72+
73+
- **Tooling for environment authors:** We could provide tools to help authors create and publish environment definition files.
74+
- **Using environment definitions for bindings generation:** With this SIP, we propose to use target worlds in a validation predicate. Building on this, we could also use them to better support authors in targeting the right environment to begin with.

0 commit comments

Comments
 (0)