Support container contracts when pushing to local devices

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-10-14 16:40:46 +01:00
parent 4280a3cd4a
commit 0c5ed7adfb
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 18 additions and 8 deletions

View File

@ -211,6 +211,7 @@ export async function deployToDevice(opts: DeviceDeployOptions): Promise<void> {
const targetState = generateTargetState(
currentTargetState,
project.composition,
buildTasks,
envs,
);
globalLogger.logDebug(`Sending target state: ${JSON.stringify(targetState)}`);
@ -488,8 +489,11 @@ function generateImageName(serviceName: string): string {
export function generateTargetState(
currentTargetState: any,
composition: Composition,
buildTasks: BuildTask[],
env: ParsedEnvironment,
): any {
const keyedBuildTasks = _.keyBy(buildTasks, 'serviceName');
const services: { [serviceId: string]: any } = {};
let idx = 1;
_.each(composition.services, (opts, name) => {
@ -504,14 +508,20 @@ export function generateTargetState(
};
opts.environment = _.merge(opts.environment, env[name]);
const contract = keyedBuildTasks[name].contract;
services[idx] = _.merge(defaults, opts, {
imageId: idx,
serviceName: name,
serviceId: idx,
image: generateImageName(name),
running: true,
});
services[idx] = {
...defaults,
...opts,
...(contract != null ? { contract } : {}),
...{
imageId: idx,
serviceName: name,
serviceId: idx,
image: generateImageName(name),
running: true,
},
};
idx += 1;
});

View File

@ -351,7 +351,7 @@ export class LivepushManager {
// If we re-apply the target state, the supervisor
// should recreate the container
await this.api.setTargetState(
generateTargetState(currentState, this.composition, {}),
generateTargetState(currentState, this.composition, [buildTask], {}),
);
await this.awaitDeviceStateSettle();