Merge pull request #1469 from balena-io/local-contract-support

Support container contracts when pushing to local devices
This commit is contained in:
CameronDiver 2019-10-14 17:51:27 +01:00 committed by GitHub
commit 27270dd589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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] = {
...defaults,
...opts,
...(contract != null ? { contract } : {}),
...{
imageId: idx, imageId: idx,
serviceName: name, serviceName: name,
serviceId: idx, serviceId: idx,
image: generateImageName(name), image: generateImageName(name),
running: true, 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();