@@ -14,6 +14,28 @@ import (
1414 "github.com/elastic/elastic-package/internal/profile"
1515)
1616
17+ type envBuilder struct {
18+ vars []string
19+ }
20+
21+ func newEnvBuilder () * envBuilder {
22+ return new (envBuilder )
23+ }
24+
25+ func (eb * envBuilder ) withEnvs (envs []string ) * envBuilder {
26+ eb .vars = append (eb .vars , envs ... )
27+ return eb
28+ }
29+
30+ func (eb * envBuilder ) withEnv (env string ) * envBuilder {
31+ eb .vars = append (eb .vars , env )
32+ return eb
33+ }
34+
35+ func (eb * envBuilder ) build () []string {
36+ return eb .vars
37+ }
38+
1739func dockerComposeBuild (options Options ) error {
1840 c , err := compose .NewProject (DockerComposeProjectName , options .Profile .FetchPath (profile .SnapshotFile ))
1941 if err != nil {
@@ -26,7 +48,11 @@ func dockerComposeBuild(options Options) error {
2648 }
2749
2850 opts := compose.CommandOptions {
29- Env : append (appConfig .StackImageRefs (options .StackVersion ).AsEnv (), options .Profile .ComposeEnvVars ()... ),
51+ Env : newEnvBuilder ().
52+ withEnvs (appConfig .StackImageRefs (options .StackVersion ).AsEnv ()).
53+ withEnv (stackVariantAsEnv (options .StackVersion )).
54+ withEnvs (options .Profile .ComposeEnvVars ()).
55+ build (),
3056 Services : withIsReadyServices (withDependentServices (options .Services )),
3157 }
3258
@@ -48,7 +74,11 @@ func dockerComposePull(options Options) error {
4874 }
4975
5076 opts := compose.CommandOptions {
51- Env : append (appConfig .StackImageRefs (options .StackVersion ).AsEnv (), options .Profile .ComposeEnvVars ()... ),
77+ Env : newEnvBuilder ().
78+ withEnvs (appConfig .StackImageRefs (options .StackVersion ).AsEnv ()).
79+ withEnv (stackVariantAsEnv (options .StackVersion )).
80+ withEnvs (options .Profile .ComposeEnvVars ()).
81+ build (),
5282 Services : withIsReadyServices (withDependentServices (options .Services )),
5383 }
5484
@@ -75,7 +105,11 @@ func dockerComposeUp(options Options) error {
75105 }
76106
77107 opts := compose.CommandOptions {
78- Env : append (appConfig .StackImageRefs (options .StackVersion ).AsEnv (), options .Profile .ComposeEnvVars ()... ),
108+ Env : newEnvBuilder ().
109+ withEnvs (appConfig .StackImageRefs (options .StackVersion ).AsEnv ()).
110+ withEnv (stackVariantAsEnv (options .StackVersion )).
111+ withEnvs (options .Profile .ComposeEnvVars ()).
112+ build (),
79113 ExtraArgs : args ,
80114 Services : withIsReadyServices (withDependentServices (options .Services )),
81115 }
@@ -98,7 +132,11 @@ func dockerComposeDown(options Options) error {
98132 }
99133
100134 downOptions := compose.CommandOptions {
101- Env : append (appConfig .StackImageRefs (options .StackVersion ).AsEnv (), options .Profile .ComposeEnvVars ()... ),
135+ Env : newEnvBuilder ().
136+ withEnvs (appConfig .StackImageRefs (options .StackVersion ).AsEnv ()).
137+ withEnv (stackVariantAsEnv (options .StackVersion )).
138+ withEnvs (options .Profile .ComposeEnvVars ()).
139+ build (),
102140 // Remove associated volumes.
103141 ExtraArgs : []string {"--volumes" , "--remove-orphans" },
104142 }
0 commit comments