Skip to content

Commit

Permalink
cloudchamber/create: always print deployment and placement ID (#7523)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gpanders authored Dec 12, 2024
1 parent 004af53 commit eba018e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
11 changes: 5 additions & 6 deletions packages/wrangler/src/cloudchamber/cli/deployments.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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();
}
36 changes: 23 additions & 13 deletions packages/wrangler/src/cloudchamber/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
endSection,
log,
logRaw,
newline,
status,
updateStatus,
} from "@cloudflare/cli";
Expand Down Expand Up @@ -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)}`
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -370,7 +381,6 @@ export async function waitForPlacement(deployment: DeploymentV2) {
crash(
"Couldn't retrieve a new deployment: " + getDeploymentError.message
);
return;
}

currentDeployment = newDeployment;
Expand Down
16 changes: 7 additions & 9 deletions packages/wrangler/src/cloudchamber/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 9 additions & 11 deletions packages/wrangler/src/cloudchamber/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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: "",
});
Expand All @@ -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") {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit eba018e

Please sign in to comment.