diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..0f148de --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "esbenp.prettier-vscode" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..89d1965 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.formatOnSave": true, + "editor.defaultFormatter": "esbenp.prettier-vscode" +} \ No newline at end of file diff --git a/README.md b/README.md index b9db300..bc48589 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # launch-coder -⚠️: This was a hackathon project and is not recommended for production use or in sensative environments. +⚠️: This was a hackathon project and is not recommended for production deployments or in sensitive environments. + +This does not work for Coder v1.21+. Specify a --version flag --- @@ -13,7 +15,7 @@ Preferred environment: Google Cloud Shell. It just works. ## How to use -No need to install: +No need to install the CLI tool locally, run from NPM: ```sh # For a guided install: @@ -35,4 +37,16 @@ launch-coder launch-coder will not install or provision anything without your permission :) +## Troubleshooting + +On non-public Dev URLs: `An internal server error occurred`: + +- This is an error I get frequently with Dev URLs, GKE, and CloudFlare domains, and it always seems to go away. + - Re-create Dev URL + - Re create environment + - Wait patiently + - Last resort: Make Dev URL public + +--- + Questions? Join Slack [https://cdr.co/join-community](https://cdr.co/join-community) diff --git a/package.json b/package.json index 28ecdba..992427c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bpmct/launch-coder", - "version": "1.0.3", + "version": "1.0.5", "main": "src/index.js", "bin": { "launch-coder": "bin/launch-coder" diff --git a/shell-helpers/googleCloudK8sEnabled.sh b/shell-helpers/googleCloudK8sEnabled.sh new file mode 100755 index 0000000..4cd44c8 --- /dev/null +++ b/shell-helpers/googleCloudK8sEnabled.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# thanks https://gist.github.com/pydevops/cffbd3c694d599c6ca18342d3625af97#0212-enable-service + + +SERVICE="container.googleapis.com" +if [[ $(gcloud services list --format="value(config.name)" \ + --filter="config.name:$SERVICE" 2>&1) != \ + "$SERVICE" ]]; then +echo "false" +else +echo "true" +fi diff --git a/src/cli.js b/src/cli.js index 1c443d4..50e53e5 100644 --- a/src/cli.js +++ b/src/cli.js @@ -214,7 +214,10 @@ export async function cli(args) { // TODO: add better user education on what the prereqs are try { await runHelperScript("googleCloudPrereqs"); - console.log("✅", "You seem to have all the dependencies installed!"); + console.log( + "✅", + "You seem to have all the local dependencies installed!" + ); } catch (err) { console.log("❌", err.stderr); return; @@ -294,6 +297,45 @@ export async function cli(args) { } } + // check if the kubernetes service is enabled in google cloud + + const check_K8s = await runHelperScript("googleCloudK8sEnabled"); + + if (check_K8s && check_K8s != "true") { + if (!argv.skipConfirmPrompts) { + const runCommand = await inquirer.prompt({ + type: "confirm", + default: true, + name: "runIt", + message: + "Kubernetes (container.googleapis.com) is not enabled on this Google Cloud project. Enable?", + }); + + if (!runCommand.runIt) { + console.log( + `\n\nOk :) Kubernetes is required to run Coder. You can manually enable it here:\n`, + "\t👉 https://console.cloud.google.com/marketplace/product/google/container.googleapis.com\n" + ); + return; + } + } + + try { + console.log( + "⏳", + "Enabling the Kubernetes service for this project..." + ); + await execa("gcloud", [ + "services", + "enable", + "container.googleapis.com", + ]); + console.log("✅", "Enabled the Google Cloud Kubernetes service\n\n"); + } catch (err) { + console.log("❌", "Error enabling the Kubernetes service", err); + } + } + let gCloudCommand = generateGoogleClusterCommand(argv); // TODO: add info on what this cluster means @@ -855,5 +897,4 @@ export async function cli(args) { // TODO: tell the user they can save this to a PRIVATE // repo in GIT (maybe idk if that is bad practice) - console.log("\n\nat the end with a long argv:", Object.keys(argv).length); }