Add a much faster container replacement for livepush

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-05-27 13:19:14 +01:00
parent 39cf86ed85
commit 106b971410

View File

@ -337,24 +337,12 @@ export class LivepushManager {
return; return;
} }
// TODO: The code below is quite roundabout, and instead // Let's first delete the container from the device
// we'd prefer just to call a supervisor endpoint which const containerId = await this.api.getContainerId(serviceName);
// recreates a container, but that doesn't exist yet await this.docker.getContainer(containerId).remove({ force: true });
// First we request the current target state
const currentState = await this.api.getTargetState(); const currentState = await this.api.getTargetState();
// If we re-apply the target state, the supervisor
// Then we generate a target state without the service // should recreate the container
// we rebuilt
const comp = _.cloneDeep(this.composition);
delete comp.services[serviceName];
const intermediateState = generateTargetState(currentState, comp, {});
await this.api.setTargetState(intermediateState);
// Now we wait for the device state to settle
await this.awaitDeviceStateSettle();
// And re-set the target state
await this.api.setTargetState( await this.api.setTargetState(
generateTargetState(currentState, this.composition, {}), generateTargetState(currentState, this.composition, {}),
); );