Skip to content
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ To expose local packages in the Package Registry, build them first and boot up t

For details on how to connect the service with the Elastic stack, see the [service command](https://github.com/elastic/elastic-package/blob/main/README.md#elastic-package-service).

You can customize your stack using profile settings, see [Elastic Package profiles](https://github.com/elastic/elastic-package/blob/main/README.md#elastic-package-profiles-1) section. These settings can be also overriden with the --parameter flag. Settings configured this way are not persisted.

### `elastic-package stack update`

_Context: global_
Expand Down
14 changes: 13 additions & 1 deletion cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Be aware that a common issue while trying to boot up the stack is that your Dock

To expose local packages in the Package Registry, build them first and boot up the stack from inside of the Git repository containing the package (e.g. elastic/integrations). They will be copied to the development stack (~/.elastic-package/stack/development) and used to build a custom Docker image of the Package Registry. Starting with Elastic stack version >= 8.7.0, it is not mandatory to be available local packages in the Package Registry to run the tests.

For details on how to connect the service with the Elastic stack, see the [service command](https://github.com/elastic/elastic-package/blob/main/README.md#elastic-package-service).`
For details on how to connect the service with the Elastic stack, see the [service command](https://github.com/elastic/elastic-package/blob/main/README.md#elastic-package-service).

You can customize your stack using profile settings, see [Elastic Package profiles](https://github.com/elastic/elastic-package/blob/main/README.md#elastic-package-profiles-1) section. These settings can be also overriden with the --parameter flag. Settings configured this way are not persisted.`

func setupStackCommand() *cobraext.Command {
upCommand := &cobra.Command{
Expand Down Expand Up @@ -86,6 +88,15 @@ func setupStackCommand() *cobraext.Command {
return err
}

// Parameters provided through the CLI are not persisted.
// Stack providers can get them with `profile.Config`, and they
// need to handle and store them if they need it.
userParameters, err := cobraext.GetStackUserParameterFlags(cmd)
if err != nil {
return err
}
profile.RuntimeOverrides(userParameters)

cmd.Printf("Using profile %s.\n", profile.ProfilePath)
cmd.Println(`Remember to load stack environment variables using 'eval "$(elastic-package stack shellinit)"'.`)
err = provider.BootUp(stack.Options{
Expand All @@ -108,6 +119,7 @@ func setupStackCommand() *cobraext.Command {
fmt.Sprintf(cobraext.StackServicesFlagDescription, strings.Join(availableServicesAsList(), ",")))
upCommand.Flags().StringP(cobraext.StackVersionFlagName, "", install.DefaultStackVersion, cobraext.StackVersionFlagDescription)
upCommand.Flags().String(cobraext.StackProviderFlagName, "", fmt.Sprintf(cobraext.StackProviderFlagDescription, strings.Join(stack.SupportedProviders, ", ")))
upCommand.Flags().StringSliceP(cobraext.StackUserParameterFlagName, cobraext.StackUserParameterFlagShorthand, nil, cobraext.StackUserParameterDescription)

downCommand := &cobra.Command{
Use: "down",
Expand Down
4 changes: 4 additions & 0 deletions internal/cobraext/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ const (
StackDumpOutputFlagName = "output"
StackDumpOutputFlagDescription = "output location for the stack dump"

StackUserParameterFlagName = "parameter"
StackUserParameterFlagShorthand = "U"
StackUserParameterDescription = "optional parameter for the stack provider, as key=value"

StatusKibanaVersionFlagName = "kibana-version"
StatusKibanaVersionFlagDescription = "show packages for the given kibana version"

Expand Down
19 changes: 19 additions & 0 deletions internal/cobraext/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,22 @@ func GetStackProviderFromProfile(cmd *cobra.Command, profile *profile.Profile, c

return stack.BuildProvider(providerName, profile)
}

// GetStackUserParameterFlags returns the parameters defined by the user in the command line
func GetStackUserParameterFlags(cmd *cobra.Command) (map[string]string, error) {
parameters, err := cmd.Flags().GetStringSlice(StackUserParameterFlagName)
if err != nil {
return nil, FlagParsingError(err, StackUserParameterFlagName)
}

values := make(map[string]string)
for _, p := range parameters {
k, v, valid := strings.Cut(p, "=")
if !valid {
return nil, fmt.Errorf("invalid format for user parameter, expected key=value, found %q", p)
}
values[k] = v
}

return values, nil
}
22 changes: 17 additions & 5 deletions internal/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ type Profile struct {
ProfilePath string
ProfileName string

config config
config config
overrides map[string]string
}

// Path returns an absolute path to the given file
Expand All @@ -147,11 +148,22 @@ func (profile Profile) Path(names ...string) string {

// Config returns a configuration setting, or its default if setting not found
func (profile Profile) Config(name string, def string) string {
v, found := profile.config.get(name)
if !found {
return def
v, found := profile.overrides[name]
if found {
return v
}
return v

v, found = profile.config.get(name)
if found {
return v
}

return def
}

// RuntimeOverrides defines configuration overrides for the current session.
func (profile *Profile) RuntimeOverrides(overrides map[string]string) {
profile.overrides = overrides
}

// ErrNotAProfile is returned in cases where we don't have a valid profile directory
Expand Down