mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-31 00:24:15 +00:00
Merge pull request #1257 from balena-io/better-livepush-dockerfile-change-restart
Better livepush dockerfile change restart
This commit is contained in:
commit
8c537c112d
@ -67,6 +67,7 @@ const deviceEndpoints = {
|
||||
ping: 'ping',
|
||||
version: 'v2/version',
|
||||
status: 'v2/state/status',
|
||||
containerId: 'v2/containerId',
|
||||
};
|
||||
|
||||
export class DeviceAPI {
|
||||
@ -124,6 +125,29 @@ export class DeviceAPI {
|
||||
});
|
||||
}
|
||||
|
||||
public async getContainerId(serviceName: string): Promise<string> {
|
||||
const url = this.getUrlForAction('containerId');
|
||||
|
||||
const body = await DeviceAPI.promisifiedRequest(
|
||||
request.get,
|
||||
{
|
||||
url,
|
||||
json: true,
|
||||
qs: {
|
||||
serviceName,
|
||||
},
|
||||
},
|
||||
this.logger,
|
||||
);
|
||||
|
||||
if (body.status !== 'success') {
|
||||
throw new ApiErrors.DeviceAPIError(
|
||||
'Non-successful response from supervisor containerId endpoint',
|
||||
);
|
||||
}
|
||||
return body.containerId;
|
||||
}
|
||||
|
||||
public async ping(): Promise<void> {
|
||||
const url = this.getUrlForAction('ping');
|
||||
|
||||
|
@ -337,24 +337,12 @@ export class LivepushManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: The code below is quite roundabout, and instead
|
||||
// we'd prefer just to call a supervisor endpoint which
|
||||
// recreates a container, but that doesn't exist yet
|
||||
|
||||
// First we request the current target state
|
||||
// Let's first delete the container from the device
|
||||
const containerId = await this.api.getContainerId(serviceName);
|
||||
await this.docker.getContainer(containerId).remove({ force: true });
|
||||
const currentState = await this.api.getTargetState();
|
||||
|
||||
// Then we generate a target state without the service
|
||||
// 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
|
||||
// If we re-apply the target state, the supervisor
|
||||
// should recreate the container
|
||||
await this.api.setTargetState(
|
||||
generateTargetState(currentState, this.composition, {}),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user