From 026b0e2b831aa62f58665cc2165b5b947b41f11d Mon Sep 17 00:00:00 2001 From: Greg Anders Date: Wed, 11 Dec 2024 08:16:49 -0600 Subject: [PATCH] cloudchamber/create: always print deployment and placement ID We currently only print the full deployment ID when the deployment has an IPv4 address. This commit makes the deployment ID always print, as well as the placement ID. We also move the printing of the IPv4 address (if one exists) to the same place as the IPv6 address so that they are printed together. There are a few other nit-picky changes as well. I've tried to make capitalization of labels more consistent (there doesn't appear to be a rule on when someone should be capitalized and when it shouldn't be, but I've at least made it more consistent within the subcommands themselves). I also changed the green "SUCCESS" message to only print once at the very end of the `cloudchamber create` command. This is consistent with the flow for creating a Worker. --- .../src/cloudchamber/cli/deployments.ts | 11 +++--- .../wrangler/src/cloudchamber/cli/index.ts | 36 ++++++++++++------- packages/wrangler/src/cloudchamber/common.ts | 16 ++++----- packages/wrangler/src/cloudchamber/create.ts | 20 +++++------ 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/packages/wrangler/src/cloudchamber/cli/deployments.ts b/packages/wrangler/src/cloudchamber/cli/deployments.ts index 36d17ecb1e31..73988f58922c 100644 --- a/packages/wrangler/src/cloudchamber/cli/deployments.ts +++ b/packages/wrangler/src/cloudchamber/cli/deployments.ts @@ -1,5 +1,5 @@ import { exit } from "process"; -import { cancel, crash, endSection, log } from "@cloudflare/cli"; +import { cancel, crash, endSection, log, newline } from "@cloudflare/cli"; import { processArgument } from "@cloudflare/cli/args"; import { brandColor, dim, yellow } from "@cloudflare/cli/colors"; import { spinner } from "@cloudflare/cli/interactive"; @@ -172,11 +172,10 @@ export async function pickDeployment(deploymentIdPrefix?: string) { } export function logDeployment(deployment: DeploymentV2) { + log(`${brandColor("image")} ${dim(deployment.image)}`); log( - `${brandColor("Image")} ${dim(deployment.image)}\n${brandColor( - "Location" - )} ${dim(idToLocationName(deployment.location.name))}\n${brandColor( - "Version" - )} ${dim(`${deployment.version}`)}\n` + `${brandColor("location")} ${dim(idToLocationName(deployment.location.name))}` ); + log(`${brandColor("version")} ${dim(`${deployment.version}`)}`); + newline(); } diff --git a/packages/wrangler/src/cloudchamber/cli/index.ts b/packages/wrangler/src/cloudchamber/cli/index.ts index f25e747f34f0..dee7561b8867 100644 --- a/packages/wrangler/src/cloudchamber/cli/index.ts +++ b/packages/wrangler/src/cloudchamber/cli/index.ts @@ -3,6 +3,7 @@ import { endSection, log, logRaw, + newline, status, updateStatus, } from "@cloudflare/cli"; @@ -277,13 +278,20 @@ async function waitForVMToStart(deployment: DeploymentV2) { checkPlacementStatus(eventPlacement.placement); } - updateStatus(status.success + " Created your container"); - log( - `${brandColor("assigned ipv6 address")} ${dim( - eventPlacement.placement.status["ipv6Address"] - )}\n` - ); - endSection("Your container is up and running"); + const ipv4 = eventPlacement.placement.status["ipv4Address"]; + if (ipv4) { + log(`${brandColor("assigned IPv4 address")} ${dim(ipv4)}\n`); + } + + const ipv6 = eventPlacement.placement.status["ipv6Address"]; + if (ipv6) { + log(`${brandColor("assigned IPv6 address")} ${dim(ipv6)}\n`); + } + + endSection("Done"); + + logRaw(status.success + " Created your container\n"); + logRaw( `Run ${brandColor( `wrangler cloudchamber list ${deployment.id.slice(0, 6)}` @@ -334,15 +342,18 @@ async function waitForPlacementInstance(deployment: DeploymentV2) { } updateStatus( - "Assigned placement in " + idToLocationName(deployment.location.name) + "Assigned placement in " + idToLocationName(deployment.location.name), + false ); - if (d.current_placement?.deployment_version) { + + if (d.current_placement !== undefined) { log( - `${brandColor("assigned placement")} ${dim( - `version ${d.current_placement.deployment_version}` - )}\n` + `${brandColor("version")} ${dim(d.current_placement.deployment_version)}` ); + log(`${brandColor("id")} ${dim(d.current_placement?.id)}`); + newline(); } + deployment.current_placement = d.current_placement; } @@ -370,7 +381,6 @@ export async function waitForPlacement(deployment: DeploymentV2) { crash( "Couldn't retrieve a new deployment: " + getDeploymentError.message ); - return; } currentDeployment = newDeployment; diff --git a/packages/wrangler/src/cloudchamber/common.ts b/packages/wrangler/src/cloudchamber/common.ts index efa75a43aaa4..dc81123f2725 100644 --- a/packages/wrangler/src/cloudchamber/common.ts +++ b/packages/wrangler/src/cloudchamber/common.ts @@ -344,17 +344,15 @@ export function renderDeploymentConfiguration( } const containerInformation = [ - ["Image", image], - ["Location", idToLocationName(location)], - ["VCPU", `${vcpu}`], - ["Memory", memory], - ["Environment variables", environmentVariablesText], - ["Labels", labelsText], + ["image", image], + ["location", idToLocationName(location)], + ["vCPU", `${vcpu}`], + ["memory", memory], + ["environment variables", environmentVariablesText], + ["labels", labelsText], ...(network === undefined ? [] - : [ - ["Include IPv4", network.assign_ipv4 === "predefined" ? "yes" : "no"], - ]), + : [["IPv4", network.assign_ipv4 === "predefined" ? "yes" : "no"]]), ] as const; updateStatus( diff --git a/packages/wrangler/src/cloudchamber/create.ts b/packages/wrangler/src/cloudchamber/create.ts index dc74056b43c7..6740b6cf7d37 100644 --- a/packages/wrangler/src/cloudchamber/create.ts +++ b/packages/wrangler/src/cloudchamber/create.ts @@ -3,10 +3,10 @@ import { endSection, log, startSection, - status, updateStatus, } from "@cloudflare/cli"; import { processArgument } from "@cloudflare/cli/args"; +import { brandColor, dim } from "@cloudflare/cli/colors"; import { inputPrompt, spinner } from "@cloudflare/cli/interactive"; import { pollSSHKeysUntilCondition, waitForPlacement } from "./cli"; import { getLocation } from "./cli/locations"; @@ -171,9 +171,9 @@ async function askWhichSSHKeysDoTheyWantToAdd( if (keys.length === 1) { const yes = await inputPrompt({ - question: `Do you want to add the ssh key ${keyItems[0].name}?`, + question: `Do you want to add the SSH key ${keyItems[0].name}?`, type: "confirm", - helpText: "You need this to ssh into the VM", + helpText: "You need this to SSH into the VM", defaultValue: false, label: "", }); @@ -190,15 +190,15 @@ async function askWhichSSHKeysDoTheyWantToAdd( const res = await inputPrompt({ question: - "You have multiple ssh keys in your account, what do you want to do for this new deployment?", - label: "", + "You have multiple SSH keys in your account, what do you want to do for this new deployment?", + label: "ssh", defaultValue: false, helpText: "", type: "select", options: [ { label: "Add all of them", value: "all" }, { label: "Select the keys", value: "select" }, - { label: "Don't add any ssh keys", value: "none" }, + { label: "Don't add any SSH keys", value: "none" }, ], }); if (res === "all") { @@ -294,7 +294,7 @@ async function handleCreateCommand( const yes = await inputPrompt({ type: "confirm", - question: "Do you want to go ahead and create your container?", + question: "Proceed?", label: "", }); if (!yes) { @@ -323,10 +323,8 @@ async function handleCreateCommand( } stop(); - updateStatus(`${status.success} Created deployment!`); - if (deployment.network?.ipv4) { - log(`${deployment.id}\nIP: ${deployment.network.ipv4}`); - } + updateStatus("Created deployment", false); + log(`${brandColor("id")} ${dim(deployment.id)}\n`); endSection("Creating a placement for your container"); startSection("Create a Cloudflare container", "Step 2 of 2");