Skip to content

pass provider options as json #12807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ with subcommands `up` and `down`.
## Up lifecycle

To execute an application's `up` lifecycle, Compose executes the provider's `compose up` command, passing
the project name, service name, and additional options. The `provider.options` are translated
into command line flags. For example:
the project name, service name, and additional options. The `provider.options` are marshalled into a JSON
document and set as command line stdin.

Illustration example will execute:
```console
awesomecloud compose --project-name <NAME> up --type=mysql --size=256 "database"
awesomecloud compose --project-name <NAME> up "database"
```
Command will get stdin set to JSON content:
```json
{"type": "mysql", "size": "256"}
```

> __Note:__ `project-name` _should_ be used by the provider to tag resources
Expand Down
23 changes: 15 additions & 8 deletions pkg/compose/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package compose

import (
"bytes"
"context"
"encoding/json"
"errors"
Expand Down Expand Up @@ -55,7 +56,10 @@ func (s *composeService) runPlugin(ctx context.Context, project *types.Project,
return err
}

cmd := s.setupPluginCommand(ctx, project, service, plugin, command)
cmd, err := s.setupPluginCommand(ctx, project, service, plugin, command)
if err != nil {
return err
}

variables, err := s.executePlugin(ctx, cmd, command, service)
if err != nil {
Expand Down Expand Up @@ -158,19 +162,22 @@ func (s *composeService) getPluginBinaryPath(provider string) (path string, err
return path, err
}

func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, service types.ServiceConfig, path, command string) *exec.Cmd {
func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, service types.ServiceConfig, path, command string) (*exec.Cmd, error) {
provider := *service.Provider

args := []string{"compose", "--project-name", project.Name, command}
for k, v := range provider.Options {
args = append(args, fmt.Sprintf("--%s=%s", k, v))
}
args = append(args, service.Name)
args := []string{"compose", "--project-name", project.Name, command, service.Name}

cmd := exec.CommandContext(ctx, path, args...)
// Remove DOCKER_CLI_PLUGIN... variable so plugin can detect it run standalone
cmd.Env = filter(os.Environ(), manager.ReexecEnvvar)

opts, err := json.Marshal(provider.Options)
if err != nil {
return nil, err
}

cmd.Stdin = bytes.NewBuffer(opts)

// Use docker/cli mechanism to propagate termination signal to child process
server, err := socket.NewPluginServer(nil)
if err == nil {
Expand All @@ -185,5 +192,5 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
carrier := propagation.MapCarrier{}
otel.GetTextMapPropagator().Inject(ctx, &carrier)
cmd.Env = append(cmd.Env, types.Mapping(carrier).Values()...)
return cmd
return cmd, nil
}