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

View File

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