@@ -76,15 +76,15 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
7676 logger .Debug ("setting up service using Docker Compose service deployer" )
7777 service := dockerComposeDeployedService {
7878 ymlPaths : d .ymlPaths ,
79- project : fmt . Sprintf ( "elastic-package-service-%s" , svcInfo .Test . RunID ),
79+ project : svcInfo .ProjectName ( ),
8080 variant : d .variant ,
8181 env : []string {
8282 fmt .Sprintf ("%s=%s" , serviceLogsDirEnv , svcInfo .Logs .Folder .Local ),
8383 fmt .Sprintf ("%s=%s" , testRunIDEnv , svcInfo .Test .RunID ),
8484 },
8585 }
8686
87- p , err := compose . NewProject ( service .project , service . ymlPaths ... )
87+ p , err := service .Project ( )
8888 if err != nil {
8989 return nil , fmt .Errorf ("could not create Docker Compose project for service: %w" , err )
9090 }
@@ -114,9 +114,7 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
114114 }
115115
116116 opts := compose.CommandOptions {
117- Env : append (
118- service .env ,
119- d .variant .Env ... ),
117+ Env : service .Env (),
120118 ExtraArgs : []string {"--build" , "-d" },
121119 }
122120
@@ -194,17 +192,29 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
194192 return & service , nil
195193}
196194
195+ // Project returns the project for the deployed service.
196+ func (s * dockerComposeDeployedService ) Project () (* compose.Project , error ) {
197+ p , err := compose .NewProject (s .project , s .ymlPaths ... )
198+ if err != nil {
199+ return nil , fmt .Errorf ("could not create Docker Compose project for service: %w" , err )
200+ }
201+ return p , nil
202+ }
203+
204+ // Env returns a copy of the full env for the deployed service including any variant env.
205+ func (s * dockerComposeDeployedService ) Env () []string {
206+ return append (s .env [:len (s .env ):len (s .env )], s .variant .Env ... )
207+ }
208+
197209// Signal sends a signal to the service.
198210func (s * dockerComposeDeployedService ) Signal (ctx context.Context , signal string ) error {
199- p , err := compose . NewProject ( s . project , s . ymlPaths ... )
211+ p , err := s . Project ( )
200212 if err != nil {
201213 return fmt .Errorf ("could not create Docker Compose project for service: %w" , err )
202214 }
203215
204216 opts := compose.CommandOptions {
205- Env : append (
206- s .env ,
207- s .variant .Env ... ),
217+ Env : s .Env (),
208218 ExtraArgs : []string {"-s" , signal },
209219 }
210220 if s .svcInfo .Name != "" {
@@ -220,15 +230,13 @@ func (s *dockerComposeDeployedService) Signal(ctx context.Context, signal string
220230
221231// ExitCode returns true if the service is exited and its exit code.
222232func (s * dockerComposeDeployedService ) ExitCode (ctx context.Context , service string ) (bool , int , error ) {
223- p , err := compose . NewProject ( s . project , s . ymlPaths ... )
233+ p , err := s . Project ( )
224234 if err != nil {
225235 return false , - 1 , fmt .Errorf ("could not create Docker Compose project for service: %w" , err )
226236 }
227237
228238 opts := compose.CommandOptions {
229- Env : append (
230- s .env ,
231- s .variant .Env ... ),
239+ Env : s .Env (),
232240 }
233241
234242 return p .ServiceExitCode (ctx , service , opts )
@@ -261,9 +269,7 @@ func (s *dockerComposeDeployedService) TearDown(ctx context.Context) error {
261269 }
262270
263271 opts := compose.CommandOptions {
264- Env : append (
265- s .env ,
266- s .variant .Env ... ),
272+ Env : s .Env (),
267273 }
268274
269275 extraArgs := []string {}
0 commit comments