Skip to content

Commit 089d1ca

Browse files
committed
start auto cloudflare stuff
1 parent 0e529b2 commit 089d1ca

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { exec, spawn, fork, execFile } = require("promisify-child-process");
55

66
let inject = {
77
user_domain: `newest.coding.pics`,
8-
user_email: "victorialslocum@gmail.com",
8+
// user_email: "victorialslocum@gmail.com",
99
user_namespace: "script",
1010
cloudflare_email: process.env.CLOUDFLARE_EMAIL,
1111
cloudflare_api: process.env.CLOUDFLARE_TOKEN,

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
"dotenv": "^8.2.0",
2424
"esm": "^3.2.25",
2525
"execa": "^5.0.0",
26+
"js-sha256": "^0.9.0",
2627
"promisify-child-process": "^4.1.1",
2728
"yargs": "^16.2.0",
2829
"yargs-interactive": "^3.0.0"
2930
}
30-
}
31+
}

src/cli.js

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const execa = require("execa");
88
// reading and writing in out/ folder
99
const fs = require("fs");
1010

11+
// TODO change this
12+
const cloudflareEmail = "me@bpmct.net";
13+
const cloudflareDomain = "coding.pics";
14+
1115
require("dotenv").config();
1216

1317
const runHelperScript = async (filename, params) => {
@@ -90,6 +94,11 @@ export async function cli(args) {
9094
alias: "n",
9195
description: "Name for Coder subdomain",
9296
})
97+
.option("namespace", {
98+
type: "string",
99+
default: "coder",
100+
description: "Namespace for Coder",
101+
})
93102
.option("gcloud-project-id", {
94103
type: "string",
95104
})
@@ -206,9 +215,6 @@ export async function cli(args) {
206215
} catch (err) {
207216
// reset projects list
208217
projects = [];
209-
210-
// TODO: ensure it is actually no biggie
211-
console.log("Ran into an error fetching your projects... No biggie 🙂");
212218
}
213219

214220
// show a select field if we found a list
@@ -227,7 +233,11 @@ export async function cli(args) {
227233
choices: projects,
228234
})),
229235
};
230-
} else
236+
} else {
237+
console.log(
238+
"🤔 We couldn't determine if you have any Google Cloud Projects.\n",
239+
"\t➡️ Create one here: https://console.cloud.google.com/projectcreate"
240+
);
231241
argv = {
232242
...argv,
233243
...(await inquirer.prompt({
@@ -251,10 +261,13 @@ export async function cli(args) {
251261
],
252262
})),
253263
};
264+
}
254265
}
255266

256267
let gCloudCommand = generateGoogleClusterCommand(argv);
257268

269+
// TODO: add info on what this cluster means
270+
258271
// TODO: impliment pricing calculations with Google API
259272
let pricing_info = "";
260273

@@ -300,9 +313,9 @@ export async function cli(args) {
300313

301314
if (!runCommand.runIt) {
302315
console.log(
303-
`\n\nOk :) Feel free to modify the command as needed, run it yourself, then you can run "launch-coder --mode k8s" to install Coder on the cluster you manually created`
316+
`\n\nOk :) Feel free to modify the command as needed, run it yourself, then you can run "launch-coder --method k8s" to install Coder on the cluster you manually created`
304317
);
305-
return 0;
318+
return;
306319
}
307320
}
308321

@@ -332,12 +345,17 @@ export async function cli(args) {
332345
);
333346
await fs.chmodSync(argv.saveDir + "/createCluster.sh", "755");
334347

348+
// TODO: find a way to actually make live updates work
349+
// or point the user to the URL to watch live.
350+
// ex. https://console.cloud.google.com/kubernetes/clusters/details/us-central1-a/coder/details?project=kubernetes-cluster-302420
351+
// we have all the info
335352
console.log("\n⏳ Creating your cluster. This will take a few minutes...");
336353

337354
try {
338355
const subprocess = execa("/bin/sh", [argv.saveDir + "/createCluster.sh"]);
339356
subprocess.stdout.pipe(process.stdout);
340357
const { stdout } = await subprocess;
358+
// TODO: consolidate the spacers
341359
console.log("------------");
342360
console.log(
343361
"✅",
@@ -375,9 +393,9 @@ export async function cli(args) {
375393
// TODO: add checks to ensure the user has a cluster,
376394
// and it has the necessary stuff for Coder
377395
console.log(
378-
"This script does not currently verify that you cluster is ready for Coder yet.\n\nWe recommend checking the docs before continuing:"
396+
"This script does not currently verify that your cluster is ready for Coder.\n\nWe recommend checking the docs before continuing:"
379397
);
380-
console.log("\t➡️ https://coder.com/docs/setup/requirements");
398+
console.log("\t➡️ https://coder.com/docs/setup/requirements\n");
381399

382400
if (!argv.skipConfirmPrompts) {
383401
const runCommand = await inquirer.prompt({
@@ -406,7 +424,7 @@ export async function cli(args) {
406424
message: "What type of domain would you like to use?",
407425
choices: [
408426
{
409-
name: `A free domain from Coder (ex. [myname].${process.env.CLOUDFLARE_DOMAIN})`,
427+
name: `A free domain from Coder (ex. [myname].${cloudflareDomain})`,
410428
value: "auto",
411429
},
412430
{
@@ -420,13 +438,40 @@ export async function cli(args) {
420438
],
421439
})),
422440
};
441+
} else {
442+
console.log("------------");
423443
}
424444

425445
// validate domainType
426446
if (argv.domainType == "auto") {
427-
console.log("AUTOMA");
447+
// check if we have the cloudflare token
448+
if (!process.env.DOMAIN_TOKEN) {
449+
console.log(
450+
"\n🔒 At this time, you need a special token from a Coder rep to get a subdomain\n" +
451+
"For more info, join our Slack Community: https://cdr.co/join-community"
452+
);
453+
return;
454+
}
455+
456+
// sha256 validate the token
457+
// used for verifying domain token
458+
var sha256 = require("js-sha256");
459+
460+
// verify the token
461+
// TODO: potentially do this server-side so that expired tokens
462+
// don't get improperly verified on an old local version
463+
if (
464+
sha256(process.env.DOMAIN_TOKEN) !=
465+
"7d3eb96148c592b64ddfb4f3038a329acc22ea94669780dfa9de85b768ed27b1"
466+
) {
467+
console.log("\n❌ The domain token you supplied is not valid.");
468+
return;
469+
}
470+
471+
// hello
428472
} else if (argv.domainType == "cloud-dns") {
429473
console.log("Well, this is coming soon 💀");
474+
return 0;
430475
} else if (argv.domainType == "none") {
431476
console.log(
432477
"\nWarning: This means you can't use Coder with DevURLs, a primary way of accessing web services\ninside of a Coder Workspace:\n",
@@ -435,7 +480,7 @@ export async function cli(args) {
435480
);
436481

437482
console.log(
438-
"You can always add a domain later, and use a custom provider via our docs."
483+
"You can always add a domain later, and use a custom provider via our docs.\n"
439484
);
440485

441486
// TODO: add confirmations
@@ -447,5 +492,7 @@ export async function cli(args) {
447492

448493
// install and access Coder
449494

495+
// TODO: tell the user they can save this to a PRIVATE
496+
// repo in GIT (maybe idk if that is bad practice)
450497
console.log("\n\nat the end with a long argv:", Object.keys(argv).length);
451498
}

0 commit comments

Comments
 (0)