mirror of
https://github.com/docker/compose.git
synced 2026-08-03 22:27:30 +00:00
Add rawsetenv message type for provider plugins
Providers can now send rawsetenv messages to inject environment variables into dependent services without the automatic service name prefix. This enables use cases where applications require exact variable names that cannot be altered. Closes #13727 Signed-off-by: Yohta Kimura <38206553+rajyan@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
46b806eafb
commit
332e0add14
5 changed files with 79 additions and 15 deletions
|
|
@ -96,6 +96,7 @@ func up(options options, args []string) {
|
|||
fmt.Printf(`{ "type": "info", "message": "Processing ... %d%%" }%s`, i*100/options.size, lineSeparator)
|
||||
}
|
||||
fmt.Printf(`{ "type": "setenv", "message": "URL=https://magic.cloud/%s" }%s`, servicename, lineSeparator)
|
||||
fmt.Printf(`{ "type": "rawsetenv", "message": "CLOUD_REGION=us-east-1" }%s`, lineSeparator)
|
||||
}
|
||||
|
||||
func down(_ *cobra.Command, _ []string) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ JSON messages MUST include a `type` and a `message` attribute.
|
|||
`type` can be either:
|
||||
- `info`: Reports status updates to the user. Compose will render message as the service state in the progress UI
|
||||
- `error`: Lets the user know something went wrong with details about the error. Compose will render the message as the reason for the service failure.
|
||||
- `setenv`: Lets the plugin tell Compose how dependent services can access the created resource. See next section for further details.
|
||||
- `setenv`: Lets the plugin tell Compose how dependent services can access the created resource. The variable is automatically prefixed with the service name. See next section for further details.
|
||||
- `rawsetenv`: Same as `setenv`, but the variable is injected as-is without the service name prefix. Useful when applications require exact variable names that cannot be altered.
|
||||
- `debug`: Those messages could help debugging the provider, but are not rendered to the user by default. They are rendered when Compose is started with `--verbose` flag.
|
||||
|
||||
```mermaid
|
||||
|
|
@ -99,6 +100,16 @@ automatically prefixing it with the service name. For example, if `awesomecloud
|
|||
Then the `app` service, which depends on the service managed by the provider, will receive a `DATABASE_URL` environment variable injected
|
||||
into its runtime environment.
|
||||
|
||||
When the provider command sends a `rawsetenv` JSON message, Compose injects the variable as-is without any prefix:
|
||||
```json
|
||||
{"type": "rawsetenv", "message": "SECRET_KEY=xxx"}
|
||||
```
|
||||
The `app` service will receive `SECRET_KEY` exactly as specified, regardless of the provider service name.
|
||||
This is useful when injecting secrets or configuration values that must match exact variable names expected by
|
||||
applications or frameworks. Unlike `setenv`, which avoids collisions through automatic prefixing, `rawsetenv` keys
|
||||
are the provider's responsibility to keep unique. If multiple providers emit the same `rawsetenv` key, the last one
|
||||
to run will overwrite previous values.
|
||||
|
||||
> __Note:__ The `compose up` provider command _MUST_ be idempotent. If resource is already running, the command _MUST_ set
|
||||
> the same environment variables to ensure consistent configuration of dependent services.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue