Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 1dd2852

Browse files
authored
feat(compose): accept env vars [EE-4538] (#29)
1 parent 2c30d1b commit 1dd2852

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

compose/internal/composeplugin/composeplugin.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func (wrapper *PluginWrapper) Deploy(ctx context.Context, filePaths []string, op
3737
output, err := wrapper.command(newUpCommand(filePaths, upOptions{
3838
forceRecreate: options.ForceRecreate,
3939
abortOnContainerExit: options.AbortOnContainerExit,
40-
}), options.Options,
41-
)
40+
}), options.Options)
41+
4242
if len(output) != 0 {
4343
if err != nil {
4444
return err
@@ -118,11 +118,22 @@ func (wrapper *PluginWrapper) command(command composeCommand, options libstack.O
118118
cmd := exec.Command(program, args...)
119119
cmd.Dir = options.WorkingDir
120120

121-
if wrapper.configPath != "" {
121+
if wrapper.configPath != "" || len(options.Env) > 0 {
122122
cmd.Env = os.Environ()
123+
}
124+
125+
if wrapper.configPath != "" {
123126
cmd.Env = append(cmd.Env, "DOCKER_CONFIG="+wrapper.configPath)
124127
}
125128

129+
cmd.Env = append(cmd.Env, options.Env...)
130+
131+
log.Debug().
132+
Str("command", program).
133+
Strs("args", args).
134+
Interface("env", cmd.Env).
135+
Msg("run command")
136+
126137
cmd.Stderr = &stderr
127138

128139
output, err := cmd.Output()
@@ -159,7 +170,7 @@ func newCommand(command []string, filePaths []string) composeCommand {
159170

160171
type upOptions struct {
161172
forceRecreate bool
162-
abortOnContainerExit bool ``
173+
abortOnContainerExit bool
163174
}
164175

165176
func newUpCommand(filePaths []string, options upOptions) composeCommand {

libstack.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ type Options struct {
1414
WorkingDir string
1515
Host string
1616
ProjectName string
17+
// EnvFilePath is the path to a .env file
1718
EnvFilePath string
19+
// Env is a list of environment variables to pass to the command, example: "FOO=bar"
20+
Env []string
1821
}
1922

2023
type DeployOptions struct {

0 commit comments

Comments
 (0)