@@ -77,7 +77,8 @@ func (d *Deployment) deployService(project string, service *config.Service) erro
7777 }
7878
7979 if containerStatus == ContainerStatusStopped {
80- if err := d .startContainer (service ); err != nil {
80+ container := containerName (project , service .Name , "" )
81+ if err := d .startContainer (container ); err != nil {
8182 return fmt .Errorf ("failed to start container %s: %w" , service .Name , err )
8283 }
8384 return nil
@@ -91,17 +92,17 @@ func (d *Deployment) installService(project string, service *config.Service) err
9192 return fmt .Errorf ("failed to start container for %s: %v" , service .Image , err )
9293 }
9394
94- svcName := service .Name
95+ container := containerName ( project , service .Name , "" )
9596
96- if err := d .performHealthChecks (svcName , service .HealthCheck ); err != nil {
97- return fmt .Errorf ("install failed for %s: container is unhealthy: %w" , svcName , err )
97+ if err := d .performHealthChecks (container , service .HealthCheck ); err != nil {
98+ return fmt .Errorf ("install failed for %s: container is unhealthy: %w" , container , err )
9899 }
99100
100101 return nil
101102}
102103
103104func (d * Deployment ) updateService (project string , service * config.Service ) error {
104- svcName := service .Name
105+ container := containerName ( project , service .Name , "" )
105106
106107 if service .Recreate {
107108 if err := d .recreateService (project , service ); err != nil {
@@ -111,23 +112,23 @@ func (d *Deployment) updateService(project string, service *config.Service) erro
111112 }
112113
113114 if err := d .createContainer (project , service , newContainerSuffix ); err != nil {
114- return fmt .Errorf ("failed to start new container for %s: %v" , svcName , err )
115+ return fmt .Errorf ("failed to start new container for %s: %v" , container , err )
115116 }
116117
117- if err := d .performHealthChecks (svcName + newContainerSuffix , service .HealthCheck ); err != nil {
118- if _ , err := d .runCommand (context .Background (), "docker" , "rm" , "-f" , svcName + newContainerSuffix ); err != nil {
119- return fmt .Errorf ("update failed for %s: new container is unhealthy and cleanup failed: %v" , svcName , err )
118+ if err := d .performHealthChecks (container + newContainerSuffix , service .HealthCheck ); err != nil {
119+ if _ , err := d .runCommand (context .Background (), "docker" , "rm" , "-f" , container + newContainerSuffix ); err != nil {
120+ return fmt .Errorf ("update failed for %s: new container is unhealthy and cleanup failed: %v" , container , err )
120121 }
121- return fmt .Errorf ("update failed for %s: new container is unhealthy: %w" , svcName , err )
122+ return fmt .Errorf ("update failed for %s: new container is unhealthy: %w" , container , err )
122123 }
123124
124- oldContID , err := d .switchTraffic (project , svcName )
125+ oldContID , err := d .switchTraffic (project , service . Name )
125126 if err != nil {
126- return fmt .Errorf ("failed to switch traffic for %s: %v" , svcName , err )
127+ return fmt .Errorf ("failed to switch traffic for %s: %v" , container , err )
127128 }
128129
129- if err := d .cleanup (oldContID , svcName ); err != nil {
130- return fmt .Errorf ("failed to cleanup for %s: %v" , svcName , err )
130+ if err := d .cleanup (project , oldContID , service . Name ); err != nil {
131+ return fmt .Errorf ("failed to cleanup for %s: %v" , container , err )
131132 }
132133
133134 return nil
@@ -162,7 +163,7 @@ func (d *Deployment) recreateService(project string, service *config.Service) er
162163}
163164
164165func (d * Deployment ) switchTraffic (project , service string ) (string , error ) {
165- newContainer := service + newContainerSuffix
166+ newContainer := containerName ( project , service , newContainerSuffix )
166167 oldContainer , err := d .getContainerID (project , service )
167168 if err != nil {
168169 return "" , fmt .Errorf ("failed to get old container ID: %v" , err )
@@ -194,11 +195,13 @@ func (d *Deployment) switchTraffic(project, service string) (string, error) {
194195 return oldContainer , nil
195196}
196197
197- func (d * Deployment ) cleanup (oldContID , service string ) error {
198+ func (d * Deployment ) cleanup (project , oldContID , service string ) error {
199+ oldContainer := containerName (project , service , newContainerSuffix )
200+ newContainer := containerName (project , service , "" )
198201 cmds := [][]string {
199202 {"docker" , "stop" , oldContID },
200203 {"docker" , "rm" , oldContID },
201- {"docker" , "rename" , service + newContainerSuffix , service },
204+ {"docker" , "rename" , oldContainer , newContainer },
202205 }
203206
204207 for _ , cmd := range cmds {
0 commit comments