From 8d6a621bfb62147ed0a88f58057e38211e82f841 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne <1822826+pipex@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:03:37 -0300 Subject: [PATCH] Fix target state construction with livepush When constructing the target state after a reported change from livepush, the handler function would not pass all build tasks to the function that constructs the target state, causing a TypeError when trying to obtain the target image name for each service. This updates the handler to pass all build tasks, ensuring the information is available to construct the target state. Relates-to: #2724 Change-type: patch --- lib/utils/device/deploy.ts | 15 ++++----------- lib/utils/device/live.ts | 7 ++++++- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/utils/device/deploy.ts b/lib/utils/device/deploy.ts index 6717735b..cae5c955 100644 --- a/lib/utils/device/deploy.ts +++ b/lib/utils/device/deploy.ts @@ -627,17 +627,10 @@ export function generateTargetState( }; opts.environment = _.merge(opts.environment, env[name]); - // This function can be called with a subset of the - // build tasks, when a single dockerfile has changed - // when livepushing, so check the build task exists for - // this composition entry (everything else in this - // function comes from the composition which doesn't - // change) - let contract; - if (name in keyedBuildTasks) { - contract = keyedBuildTasks[name].contract; - } - + // This function should always be called with all the build tasks + // so we can construct the correct target state so we don't really need + // to check that the key exists on the `keyedBuildTasks` object + const contract = keyedBuildTasks[name].contract; const task = keyedBuildTasks[name]; services[idx] = { diff --git a/lib/utils/device/live.ts b/lib/utils/device/live.ts index 6bc83cc9..48bafea5 100644 --- a/lib/utils/device/live.ts +++ b/lib/utils/device/live.ts @@ -423,7 +423,12 @@ export class LivepushManager { // If we re-apply the target state, the supervisor // should recreate the container await this.api.setTargetState( - generateTargetState(currentState, this.composition, [buildTask], {}), + generateTargetState( + currentState, + this.composition, + this.buildTasks, + {}, + ), ); await this.awaitDeviceStateSettle();