From e5037b92ac13b1b8a94434e1f9bfa70d4abf791a Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Fri, 11 Oct 2024 12:55:33 -0500 Subject: [PATCH] Pre-populate existing image when modifying a deployment (#6952) If a user wants to update a deployment to change only the tag of their image, then they must re-enter the entire image URL with the new tag. Instead, we can pre-populate the image field with the existing image URL (including the tag), which means a user can now simply modify the tag without needing to re-enter the full URL themselves. For example, if the deployment is currently using image "hello-world:1.0" and they want to modify it to use "hello-world:1.1", currently they would need to write the full text "hello-world:1.1". This can be quite cumbersome if the URL of the image is long (which it often is). With this change, the existing URL is pre-populated, so the user needs only to replace "0" with "1". If a user does not want to modify the image of the deployment then they can continue to just press "Enter" to keep the existing image as before. --- packages/wrangler/src/cloudchamber/modify.ts | 44 +++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/packages/wrangler/src/cloudchamber/modify.ts b/packages/wrangler/src/cloudchamber/modify.ts index ed06e02c68f4..91fb42686875 100644 --- a/packages/wrangler/src/cloudchamber/modify.ts +++ b/packages/wrangler/src/cloudchamber/modify.ts @@ -187,27 +187,22 @@ async function handleModifyCommand( const keys = await handleSSH(args, config, deployment); const givenImage = args.image ?? config.cloudchamber.image; - const imagePrompt = await processArgument( - { image: givenImage }, - "image", - { - question: modifyImageQuestion, - label: "", - validate: (value) => { - if (typeof value !== "string") { - return "unknown error"; - } - if (value.endsWith(":latest")) { - return "we don't allow :latest tags"; - } - }, - defaultValue: givenImage ?? "", - initialValue: givenImage ?? "", - helpText: "if you don't want to modify the image, press return", - type: "text", - } - ); - const image = !imagePrompt ? undefined : imagePrompt; + const image = await processArgument({ image: givenImage }, "image", { + question: modifyImageQuestion, + label: "", + validate: (value) => { + if (typeof value !== "string") { + return "unknown error"; + } + if (value.endsWith(":latest")) { + return "we don't allow :latest tags"; + } + }, + defaultValue: givenImage ?? deployment.image, + initialValue: givenImage ?? deployment.image, + helpText: "Press Return to leave unchanged", + type: "text", + }); const locationPick = await getLocation( { location: args.location ?? config.cloudchamber.location }, @@ -234,7 +229,7 @@ async function handleModifyCommand( ); renderDeploymentConfiguration("modify", { - image: image ?? deployment.image, + image, location: location ?? deployment.location.name, vcpu: args.vcpu ?? config.cloudchamber.vcpu ?? deployment.vcpu, memory: args.memory ?? config.cloudchamber.memory ?? deployment.memory, @@ -247,7 +242,7 @@ async function handleModifyCommand( }); const yesOrNo = await inputPrompt({ - question: "Want to go ahead and modify the deployment?", + question: "Modify the deployment?", label: "", type: "confirm", }); @@ -280,5 +275,4 @@ async function handleModifyCommand( await waitForPlacement(newDeployment); } -const modifyImageQuestion = - "Insert the image url you want to change your deployment to"; +const modifyImageQuestion = "URL of the image to use in your deployment";