Skip to content

Commit

Permalink
Add containerName to Service interface
Browse files Browse the repository at this point in the history
This allows to compare the current and target container names and
trigger an `updateMetadata` step if they are different. This allows us
to normalize the container name format with a new supervisor update.

Change-type: minor
  • Loading branch information
pipex committed Dec 11, 2023
1 parent aedfd31 commit f7ed27f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/compose/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,10 @@ export class App {

private generateContainerStep(current: Service, target: Service) {
// if the services release doesn't match, then rename the container...
if (current.commit !== target.commit) {
if (
current.commit !== target.commit ||
current.containerName !== target.containerName
) {
return generateStep('updateMetadata', { current, target });
} else if (target.config.running !== current.config.running) {
if (target.config.running) {
Expand Down
2 changes: 1 addition & 1 deletion src/compose/service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function updateMetadata(service: Service, target: Service) {

try {
await docker.getContainer(svc.containerId).rename({
name: `${service.serviceName}_${target.commit}`,
name: target.containerName,
});
} catch (e) {
if (isNotFoundError(e)) {
Expand Down
10 changes: 9 additions & 1 deletion src/compose/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class Service {
public serviceId: number;
public imageName: string | null;
public containerId: string | null;
public containerName: string;
public exitErrorMessage: string | null;

public dependsOn: string[] | null;
Expand Down Expand Up @@ -153,6 +154,9 @@ export class Service {
service.commit = appConfig.commit;
service.appUuid = appConfig.appUuid;

// The target container name
service.containerName = `${service.serviceName}_${service.commit}`;

// dependsOn is used by other parts of the step
// calculation so we delete it from the composition
service.dependsOn = appConfig.composition?.dependsOn || null;
Expand Down Expand Up @@ -636,6 +640,9 @@ export class Service {
);
}

// The current container name, minus the initial '/'
svc.containerName = container.Name.slice(1);

// If we have not renamed the service yet we can still use the image id
svc.imageId = parseInt(nameMatch[1], 10);
svc.releaseId = parseInt(nameMatch[2], 10);
Expand Down Expand Up @@ -893,7 +900,8 @@ export class Service {
): boolean {
return (
this.isEqualConfig(service, currentContainerIds) &&
this.commit === service.commit
this.commit === service.commit &&
this.containerName === service.containerName
);
}

Expand Down

0 comments on commit f7ed27f

Please sign in to comment.