From 6606e89174b99985fa6cd650b6cb3396fcd9b4c6 Mon Sep 17 00:00:00 2001 From: Scott Mebberson Date: Tue, 2 Aug 2022 11:42:52 +0930 Subject: [PATCH 01/21] Update the c mk start command. --- bin/c-mk-start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/c-mk-start.js b/bin/c-mk-start.js index ac5f4c0..07db009 100644 --- a/bin/c-mk-start.js +++ b/bin/c-mk-start.js @@ -17,5 +17,5 @@ const profile = program.P ? ` --profile ${program.P}` : ''; const command = `minikube start${profile}`; exec( - `${command} --disk-size 64g --extra-config=apiserver.service-node-port-range=80-32767 --cpus=2 --memory=8192 --vm-driver=vmware --kubernetes-version=v1.20.7` + `${command} --extra-config=apiserver.service-node-port-range=80-32767 --vm-driver=docker --kubernetes-version=v1.20.7` ); From 60aff40196c000d37465e1ca5f8bfb1cc94b1fbf Mon Sep 17 00:00:00 2001 From: Scott Mebberson Date: Tue, 2 Aug 2022 11:44:29 +0930 Subject: [PATCH 02/21] Version bump to v4.4.0-beta.1. --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 550a3d5..f3072a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v4.4.0-beta.1 - 2022-08-02 + +### Changed + +- Updated `c mk start` to use the Docker driver. + ## v4.3.0 - 2022-08-02 ### Added diff --git a/package.json b/package.json index 5399350..df9687c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "4.3.0", + "version": "4.4.0-beta.1", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From 3b9ca156835aba8d802927299b54b0ac1ae335f7 Mon Sep 17 00:00:00 2001 From: Scott Mebberson Date: Tue, 2 Aug 2022 13:09:00 +0930 Subject: [PATCH 03/21] Added more CPU and memory when starting Minikube. --- CHANGELOG.md | 4 ++++ bin/c-mk-start.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3072a6..d6d79b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +### Changed + +- Added more CPU and memory when starting Minikube. + ## v4.4.0-beta.1 - 2022-08-02 ### Changed diff --git a/bin/c-mk-start.js b/bin/c-mk-start.js index 07db009..a6fb205 100644 --- a/bin/c-mk-start.js +++ b/bin/c-mk-start.js @@ -17,5 +17,5 @@ const profile = program.P ? ` --profile ${program.P}` : ''; const command = `minikube start${profile}`; exec( - `${command} --extra-config=apiserver.service-node-port-range=80-32767 --vm-driver=docker --kubernetes-version=v1.20.7` + `${command} --extra-config=apiserver.service-node-port-range=80-32767 --cpus=4 --memory=12288 --vm-driver=docker --kubernetes-version=v1.20.7` ); From 0e576dfa6a99872c820418b79d3b5ae30afd6756 Mon Sep 17 00:00:00 2001 From: Scott Mebberson Date: Tue, 2 Aug 2022 13:09:37 +0930 Subject: [PATCH 04/21] Version bump to v4.4.0-beta.2. --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d79b8..2b77b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v4.4.0-beta.2 - 2022-08-02 + ### Changed - Added more CPU and memory when starting Minikube. diff --git a/package.json b/package.json index df9687c..59f990c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "4.4.0-beta.1", + "version": "4.4.0-beta.2", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From 849328c225ae787da240ce26809323d11412fd63 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Wed, 3 Aug 2022 16:34:53 +0930 Subject: [PATCH 05/21] Added c ts commands. --- CHANGELOG.md | 4 ++++ bin/c-ts-ip.js | 33 +++++++++++++++++++++++++++++++++ bin/c-ts.js | 12 ++++++++++++ bin/c.js | 1 + bin/lib/c-ts.js | 7 +++++++ 5 files changed, 57 insertions(+) create mode 100644 bin/c-ts-ip.js create mode 100644 bin/c-ts.js create mode 100644 bin/lib/c-ts.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b77b2f..13c007c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +### Added + +- `c ts` commands. + ## v4.4.0-beta.2 - 2022-08-02 ### Changed diff --git a/bin/c-ts-ip.js b/bin/c-ts-ip.js new file mode 100644 index 0000000..5b3ed08 --- /dev/null +++ b/bin/c-ts-ip.js @@ -0,0 +1,33 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { exec } = require('shelljs'); +const { newline, reportError } = require('./lib/c'); +const { app } = require('./lib/c-ts'); + +program + .arguments('') + .description( + 'Retrieves the IP address for a machine on Tailscale. Defaults to the current machine.' + ) + .option('-n', 'Do not print the trailing newline character.') + .option('-4', 'Only find the IPv4 address (default).') + .option('-6', 'Only find the IPv6 address.') + .parse(process.argv); + +const [name = ''] = program.args; +const ipFlag = program[6] ? '-6' : '-4'; + +const command = `${app} ip ${ipFlag} ${name}`; + +exec(command, { silent: true }, (err, stdout) => { + if (err) { + return reportError(err, false, true); + } + + process.stdout.write( + `${stdout.replace(/\n/, '', 'g')}${newline(program.N)}` + ); +}); diff --git a/bin/c-ts.js b/bin/c-ts.js new file mode 100644 index 0000000..d2af9eb --- /dev/null +++ b/bin/c-ts.js @@ -0,0 +1,12 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program + .command('ip ', 'Find the IP for a machine on Tailscale.') + .parse(process.argv); + +missingCommand(program); diff --git a/bin/c.js b/bin/c.js index f86d0b4..ebc7f44 100755 --- a/bin/c.js +++ b/bin/c.js @@ -19,6 +19,7 @@ program .command('project ', 'Shortcuts to help with project management.') .command('sdp ', "Shortcuts to help with Section's devpop.") .command('skaffold ', 'Shortcuts to help with Skaffold.') + .command('ts ', 'Shortcuts to help with Tailscale.') .command( 'workflow ', 'Common workflows that can be executed within the context of a project.' diff --git a/bin/lib/c-ts.js b/bin/lib/c-ts.js new file mode 100644 index 0000000..d2bfaba --- /dev/null +++ b/bin/lib/c-ts.js @@ -0,0 +1,7 @@ +'use strict'; + +const app = '/Applications/Tailscale.app/Contents/MacOS/Tailscale'; + +module.exports = { + app, +}; From c002ac78efd7e5751342240a462b6c896ee272ea Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Wed, 3 Aug 2022 19:40:21 +0930 Subject: [PATCH 06/21] Added c ds commands. --- CHANGELOG.md | 1 + bin/c-ds-handle-get.js | 34 +++++++++++++++++++++++++++ bin/c-ds-handle-set.js | 39 +++++++++++++++++++++++++++++++ bin/c-ds-handle.js | 13 +++++++++++ bin/c-ds-mk-get.js | 34 +++++++++++++++++++++++++++ bin/c-ds-mk-set.js | 35 ++++++++++++++++++++++++++++ bin/c-ds-mk.js | 13 +++++++++++ bin/c-ds-pc-get.js | 34 +++++++++++++++++++++++++++ bin/c-ds-pc-set.js | 35 ++++++++++++++++++++++++++++ bin/c-ds-pc.js | 13 +++++++++++ bin/c-ds.js | 14 +++++++++++ bin/c.js | 1 + bin/lib/c.js | 53 ++++++++++++++++++++++++------------------ 13 files changed, 296 insertions(+), 23 deletions(-) create mode 100644 bin/c-ds-handle-get.js create mode 100644 bin/c-ds-handle-set.js create mode 100644 bin/c-ds-handle.js create mode 100644 bin/c-ds-mk-get.js create mode 100644 bin/c-ds-mk-set.js create mode 100644 bin/c-ds-mk.js create mode 100644 bin/c-ds-pc-get.js create mode 100644 bin/c-ds-pc-set.js create mode 100644 bin/c-ds-pc.js create mode 100644 bin/c-ds.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c007c..b036d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This file is a history of the changes made to @idearium/cli. ### Added - `c ts` commands. +- `c ds` commands. ## v4.4.0-beta.2 - 2022-08-02 diff --git a/bin/c-ds-handle-get.js b/bin/c-ds-handle-get.js new file mode 100644 index 0000000..56f68c4 --- /dev/null +++ b/bin/c-ds-handle-get.js @@ -0,0 +1,34 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + loadState, + devspacePath, + newline, + reportError, + stateFilePath, +} = require('./lib/c'); + +program + .option('-n', 'Do not print the trailing newline character.') + .parse(process.argv); + +return loadState('handle', stateFilePath(devspacePath())) + .then((data) => { + process.stdout.write(`${data}${newline(program.N)}`); + }) + .catch((err) => { + if (err.code === 'ENOENT') { + return reportError( + new Error( + "Your handle hasn't been configured yet. Use `c ds handle set `." + ), + false, + true + ); + } + + return reportError(err, false, true); + }); diff --git a/bin/c-ds-handle-set.js b/bin/c-ds-handle-set.js new file mode 100644 index 0000000..8ae4ca6 --- /dev/null +++ b/bin/c-ds-handle-set.js @@ -0,0 +1,39 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + devspacePath, + reportError, + stateFilePath, + storeState, +} = require('./lib/c'); + +program + .arguments('') + .description('Set your Idearium handle.') + .parse(process.argv); + +const [handle] = program.args; + +if (!handle) { + return reportError( + new Error('You must provide your Idearium handle.'), + program + ); +} + +const run = async () => { + const file = stateFilePath(devspacePath()); + + try { + await storeState('handle', handle, file); + await storeState('mkName', `${handle}-minikube`, file); + await storeState('pcName', `${handle}-macbook`, file); + } catch (err) { + reportError(err, program, true); + } +}; + +run(); diff --git a/bin/c-ds-handle.js b/bin/c-ds-handle.js new file mode 100644 index 0000000..744a707 --- /dev/null +++ b/bin/c-ds-handle.js @@ -0,0 +1,13 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program + .command('get', 'Get your handle.') + .command('set ', 'Set your handle.') + .parse(process.argv); + +missingCommand(program); diff --git a/bin/c-ds-mk-get.js b/bin/c-ds-mk-get.js new file mode 100644 index 0000000..affcb52 --- /dev/null +++ b/bin/c-ds-mk-get.js @@ -0,0 +1,34 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + loadState, + devspacePath, + newline, + reportError, + stateFilePath, +} = require('./lib/c'); + +program + .option('-n', 'Do not print the trailing newline character.') + .parse(process.argv); + +return loadState('mkName', stateFilePath(devspacePath())) + .then((data) => { + process.stdout.write(`${data}${newline(program.N)}`); + }) + .catch((err) => { + if (err.code === 'ENOENT') { + return reportError( + new Error( + "Your Minikube name hasn't been configured yet. Use `c ds mk set `." + ), + false, + true + ); + } + + return reportError(err, false, true); + }); diff --git a/bin/c-ds-mk-set.js b/bin/c-ds-mk-set.js new file mode 100644 index 0000000..cdc262e --- /dev/null +++ b/bin/c-ds-mk-set.js @@ -0,0 +1,35 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + devspacePath, + reportError, + stateFilePath, + storeState, +} = require('./lib/c'); + +program + .arguments('') + .description("Set your Minikube's name.") + .parse(process.argv); + +const [name] = program.args; + +if (!name) { + return reportError( + new Error("You must provide your Minikube's name."), + program + ); +} + +const run = async () => { + try { + await storeState('mkName', name, stateFilePath(devspacePath())); + } catch (err) { + reportError(err, program, true); + } +}; + +run(); diff --git a/bin/c-ds-mk.js b/bin/c-ds-mk.js new file mode 100644 index 0000000..cf09567 --- /dev/null +++ b/bin/c-ds-mk.js @@ -0,0 +1,13 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program + .command('get', 'Get your Minikube name.') + .command('set ', 'Set your Minikube name.') + .parse(process.argv); + +missingCommand(program); diff --git a/bin/c-ds-pc-get.js b/bin/c-ds-pc-get.js new file mode 100644 index 0000000..4b20798 --- /dev/null +++ b/bin/c-ds-pc-get.js @@ -0,0 +1,34 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + loadState, + devspacePath, + newline, + reportError, + stateFilePath, +} = require('./lib/c'); + +program + .option('-n', 'Do not print the trailing newline character.') + .parse(process.argv); + +return loadState('pcName', stateFilePath(devspacePath())) + .then((data) => { + process.stdout.write(`${data}${newline(program.N)}`); + }) + .catch((err) => { + if (err.code === 'ENOENT') { + return reportError( + new Error( + "Your pc name hasn't been configured yet. Use `c ds pc set `." + ), + false, + true + ); + } + + return reportError(err, false, true); + }); diff --git a/bin/c-ds-pc-set.js b/bin/c-ds-pc-set.js new file mode 100644 index 0000000..41dafb4 --- /dev/null +++ b/bin/c-ds-pc-set.js @@ -0,0 +1,35 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { + devspacePath, + reportError, + stateFilePath, + storeState, +} = require('./lib/c'); + +program + .arguments('') + .description("Set your pc's name.") + .parse(process.argv); + +const [name] = program.args; + +if (!name) { + return reportError( + new Error("You must provide your computer's name."), + program + ); +} + +const run = async () => { + try { + await storeState('pcName', name, stateFilePath(devspacePath())); + } catch (err) { + reportError(err, program, true); + } +}; + +run(); diff --git a/bin/c-ds-pc.js b/bin/c-ds-pc.js new file mode 100644 index 0000000..c83e3a2 --- /dev/null +++ b/bin/c-ds-pc.js @@ -0,0 +1,13 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program + .command('get', 'Get your pc name.') + .command('set ', 'Set your pc name.') + .parse(process.argv); + +missingCommand(program); diff --git a/bin/c-ds.js b/bin/c-ds.js new file mode 100644 index 0000000..0a55453 --- /dev/null +++ b/bin/c-ds.js @@ -0,0 +1,14 @@ +#!/usr/bin/env -S node --trace-warnings + +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program + .command('handle', 'Manage your Idearium handle.') + .command('mk', 'Manage your Minikube name.') + .command('pc', 'Manager your computer name.') + .parse(process.argv); + +missingCommand(program); diff --git a/bin/c.js b/bin/c.js index ebc7f44..cb69d24 100755 --- a/bin/c.js +++ b/bin/c.js @@ -10,6 +10,7 @@ program .command('d ', 'Shortcuts to control Docker.') .command('dc ', 'Shortcuts to control Docker Compose.') .command('gc ', 'Shortcuts to help with gcloud.') + .command('ds ', 'Shortcuts to manage DevSpace.') .command('hosts ', 'Shortcuts to help with hosts management.') .command('kc ', 'Shortcuts to help with kubectl.') .command('fs ', 'Shortcuts to help with the file system.') diff --git a/bin/lib/c.js b/bin/lib/c.js index 04393cb..b3f5cf7 100644 --- a/bin/lib/c.js +++ b/bin/lib/c.js @@ -3,7 +3,7 @@ const chalk = require('chalk'); const { readFile, writeFile } = require('fs'); const { homedir } = require('os'); -const { resolve: pathResolve, join } = require('path'); +const { resolve: pathResolve, join, dirname } = require('path'); const { compile } = require('handlebars'); const { promisify } = require('util'); const { red } = require('chalk'); @@ -23,11 +23,9 @@ const composeUp = (service) => { let upCommand = 'docker-compose up -d --force-recreate'; // We need to scale some containers. - /* eslint-disable padded-blocks */ if (['app', 'consul'].includes(service)) { upCommand += ` --scale ${service}=2`; } - /* eslint-enable padded-blocks */ upCommand += ` ${service}`; @@ -36,10 +34,19 @@ const composeUp = (service) => { /** * Resolve an asbsolute path to the devops folder for the project. + * @param {string} path The path for the project. * @return {String} The path to the devops folder. */ -const devopsPath = () => { - return pathResolve(process.cwd(), 'devops'); +const devopsPath = (path = process.cwd()) => { + return pathResolve(path, 'devops'); +}; + +/** + * Resolve an asbsolute path to the devops folder for devspace. + * @return {String} The path to the devops folder. + */ +const devspacePath = () => { + return devopsPath(pathResolve(homedir(), 'Developer', 'devspace')); }; /** @@ -106,11 +113,9 @@ const executeTemplate = (file, locals = {}) => join(devopsPath(), 'templates', file), 'utf-8', (err, data) => { - /* eslint-disable padded-blocks */ if (err) { return reject(err); } - /* eslint-enable padded-blocks */ const template = compile(data); @@ -184,11 +189,9 @@ const missingCommand = (program) => { const npmAuthToken = () => new Promise((resolve, reject) => { readFile(join(homedir(), '.npmrc'), 'utf-8', (err, data) => { - /* eslint-disable padded-blocks */ if (err) { return reject(err); } - /* eslint-enable padded-blocks */ const result = /(?:_authToken=)([0-9a-z-].+)/.exec(data); const authToken = result ? result[1] : ''; @@ -198,7 +201,7 @@ const npmAuthToken = () => }); /** - * Load and parse a JSON configuration fiile. + * Load and parse a JSON configuration file. * @param {String} keys The name of a top-level key to return. * @param {String} type The name of a config file to load. * @return {Promise} A promise that will resolve with some JSON data. @@ -228,14 +231,15 @@ const loadConfig = (keys, type = 'c') => }); /** - * Load and parse a JSON state fiile. + * Load and parse a JSON state file. * @param {String} key The name of a top-level key to return. + * @param {String} path The location of the state file to load. * @return {Promise} A promise that will resolve with some JSON data. */ -const loadState = (key) => +// eslint-disable-next-line no-use-before-define +const loadState = (key, path = stateFilePath()) => new Promise((resolve, reject) => { - // eslint-disable-next-line no-use-before-define - readFile(stateFilePath(), 'utf-8', (err, data) => { + readFile(path, 'utf-8', (err, data) => { if (err) { return reject(err); } @@ -307,11 +311,9 @@ const reportError = (err, program, exit = false) => { } /* eslint-enable no-process-env, no-console */ - /* eslint-disable padded-blocks */ if (program) { program.help(); } - /* eslint-enable padded-blocks */ if (exit) { // eslint-disable-next-line no-process-exit @@ -321,31 +323,33 @@ const reportError = (err, program, exit = false) => { /** * The path to the state file. + * @param {String} path The parent devops path. * @returns {String} An absolute path to the state file. */ -const stateFilePath = () => { - return pathResolve(devopsPath(), 'state.json'); +const stateFilePath = (path = devopsPath()) => { + return pathResolve(path, 'state.json'); }; /** * Given a key and a value, store it in the state file. * @param {String} keys A property path to store the state in. * @param {any} value The value to store. + * @param {String} file The file to store the value in. * @return {Promise} A promise. */ -const storeState = (keys, value) => +const storeState = (keys, value, file = pathResolve(stateFilePath())) => new Promise((resolve, reject) => { // Ignore any errors as it probably just means that the file hasn't been created yet. - readFile(pathResolve(stateFilePath()), 'utf-8', async (_, data) => { + readFile(file, 'utf-8', async (_, data) => { const json = data ? JSON.parse(data) : {}; const nestedData = setPropertyPath({}, keys, value); const state = merge({}, json, nestedData); - await ensureDir(devopsPath()); + await ensureDir(dirname(file)); writeFile( - stateFilePath(), - JSON.stringify(state, null, 2), + file, + `${JSON.stringify(state, null, 2)}\n`, { flag: 'w' }, (writeErr) => { if (writeErr) { @@ -369,6 +373,8 @@ const throwErr = (err) => { module.exports = { composeUp, + devopsPath, + devspacePath, dockerToKubernetesLocation, documentation, env, @@ -384,6 +390,7 @@ module.exports = { proxyCommand, proxyCommands, reportError, + stateFilePath, storeState, throwErr, writeFile: promisify(writeFile), From 5bab497c0bed7b11731d79ba1c97db9c6b7e2ed9 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 4 Aug 2022 08:00:21 +0930 Subject: [PATCH 07/21] c mk ip now works with Tailscale. --- CHANGELOG.md | 4 ++++ bin/c-mk-ip.js | 31 ++++++++++++++++++++----------- bin/c-ts-ip.js | 4 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b036d8a..aadaf74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ This file is a history of the changes made to @idearium/cli. - `c ts` commands. - `c ds` commands. +### Changed + +- `c mk ip` now retrieves the IP of your Minikube machine on tailnet as configured with `c ds handle set`, or `c ds mk set`. + ## v4.4.0-beta.2 - 2022-08-02 ### Changed diff --git a/bin/c-mk-ip.js b/bin/c-mk-ip.js index 11a65e8..20a8a84 100644 --- a/bin/c-mk-ip.js +++ b/bin/c-mk-ip.js @@ -4,7 +4,13 @@ const program = require('commander'); const { exec } = require('shelljs'); -const { newline, reportError } = require('./lib/c'); +const { + devspacePath, + loadState, + newline, + reportError, + stateFilePath, +} = require('./lib/c'); // The basic program, which uses sub-commands. program @@ -15,15 +21,18 @@ program ) .parse(process.argv); -const profile = program.P ? ` --profile ${program.P}` : ''; -const command = `minikube ip${profile}`; +const run = async () => { + const mkName = await loadState('mkName', stateFilePath(devspacePath())); -exec(command, { silent: true }, (err, stdout) => { - if (err) { - return reportError(err, false, true); - } + exec(`c ts ip ${mkName}`, { silent: true }, (err, stdout, stderr) => { + if (err) { + return reportError(new Error(stderr), false, true); + } - process.stdout.write( - `${stdout.replace(/\n/, '', 'g')}${newline(program.N)}` - ); -}); + process.stdout.write( + `${stdout.replace(/\n/, '', 'g')}${newline(program.N)}` + ); + }); +}; + +run(); diff --git a/bin/c-ts-ip.js b/bin/c-ts-ip.js index 5b3ed08..18e0f68 100644 --- a/bin/c-ts-ip.js +++ b/bin/c-ts-ip.js @@ -22,9 +22,9 @@ const ipFlag = program[6] ? '-6' : '-4'; const command = `${app} ip ${ipFlag} ${name}`; -exec(command, { silent: true }, (err, stdout) => { +exec(command, { silent: true }, (err, stdout, stderr) => { if (err) { - return reportError(err, false, true); + return reportError(new Error(stderr), false, true); } process.stdout.write( From d96d142ff7c2d20872284b1269c82dbef32ae880 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 4 Aug 2022 08:40:33 +0930 Subject: [PATCH 08/21] Updated the pc name derived when setting the handle. --- bin/c-ds-handle-set.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/c-ds-handle-set.js b/bin/c-ds-handle-set.js index 8ae4ca6..121bf19 100644 --- a/bin/c-ds-handle-set.js +++ b/bin/c-ds-handle-set.js @@ -30,7 +30,7 @@ const run = async () => { try { await storeState('handle', handle, file); await storeState('mkName', `${handle}-minikube`, file); - await storeState('pcName', `${handle}-macbook`, file); + await storeState('pcName', `${handle}-pc`, file); } catch (err) { reportError(err, program, true); } From dc7ca0d2a1e156785dcca69b51ee0f46bdcaab2a Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 4 Aug 2022 09:14:14 +0930 Subject: [PATCH 09/21] Version bump to v4.4.0-beta.3. --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aadaf74..5d356a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v4.4.0-beta.3 - 2022-08-04 + ### Added - `c ts` commands. diff --git a/package.json b/package.json index 59f990c..83b42ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "4.4.0-beta.2", + "version": "4.4.0-beta.3", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From 8e72150db8f27c159398d83107ea669497a0975f Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Tue, 9 Aug 2022 09:27:01 +0930 Subject: [PATCH 10/21] Version bump to v5.1.0-beta.1. --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e1bb0..407ba55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v5.1.0-beta.1 - 2022-08-09 + +- Re-release of v4.4.0-beta.3. + ## v5.0.0 - 2022-08-09 ### Changed diff --git a/package.json b/package.json index df96b44..28ffb31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "5.0.0", + "version": "5.1.0-beta.1", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From 55f2d1bbf3c0f5a69159107d97eb794a9c92b253 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Tue, 9 Aug 2022 09:29:35 +0930 Subject: [PATCH 11/21] GitHub workflow publish step now waits for build step. --- .github/workflows/cli.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 8389a0c..29cfd42 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -22,6 +22,7 @@ jobs: publish: if: github.event_name == 'release' name: Publish + needs: build runs-on: ubuntu-latest steps: - name: Checkout From b5c1b7f15262a359aebba821f8f4d39c54aa3244 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:09:04 +0930 Subject: [PATCH 12/21] Version bump to v5.1.0-beta.2. --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index efc0ffe..e69bd96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v5.1.0-beta.2 - 2022-08-09 + +### Added + +- Incorporated v5.0.1. + ## v5.1.0-beta.1 - 2022-08-09 - Re-release of v4.4.0-beta.3. diff --git a/package.json b/package.json index 28ffb31..5f31d0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "5.1.0-beta.1", + "version": "5.1.0-beta.2", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From 50fe80d435f70e52736d3bbdd95847b50c356cc3 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:43:25 +0930 Subject: [PATCH 13/21] Fixed issue with set-value usage. --- CHANGELOG.md | 4 ++++ bin/lib/c.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69bd96..f5c3720 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +### Fixed + +- Fixed issue with `set-value` usage. + ## v5.1.0-beta.2 - 2022-08-09 ### Added diff --git a/bin/lib/c.js b/bin/lib/c.js index b3f5cf7..3d6fff9 100644 --- a/bin/lib/c.js +++ b/bin/lib/c.js @@ -342,7 +342,9 @@ const storeState = (keys, value, file = pathResolve(stateFilePath())) => // Ignore any errors as it probably just means that the file hasn't been created yet. readFile(file, 'utf-8', async (_, data) => { const json = data ? JSON.parse(data) : {}; - const nestedData = setPropertyPath({}, keys, value); + const nestedData = setPropertyPath({}, keys, value, { + preservePaths: false, + }); const state = merge({}, json, nestedData); await ensureDir(dirname(file)); From 5fd639fe474cd0c4ba041d3dcf826ef6089b0198 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Tue, 9 Aug 2022 10:43:55 +0930 Subject: [PATCH 14/21] Version bump to v5.1.0-beta.3. --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c3720..00bc8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +## v5.1.0-beta.3 - 2022-08-09 + ### Fixed - Fixed issue with `set-value` usage. diff --git a/package.json b/package.json index 5f31d0a..90ce8f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@idearium/cli", - "version": "5.1.0-beta.2", + "version": "5.1.0-beta.3", "description": "The Idearium cli, which makes working with our projects much easier.", "main": "index.js", "bin": { From d93ef9ba1d17eb98f65b4059012a5a8417a5efb2 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 25 Aug 2022 10:32:44 +0930 Subject: [PATCH 15/21] Added c d image prune command. --- CHANGELOG.md | 4 ++++ bin/c-d-image-prune.js | 9 +++++++++ bin/c-d-image.js | 8 ++++++++ bin/c-d.js | 1 + 4 files changed, 22 insertions(+) create mode 100644 bin/c-d-image-prune.js create mode 100644 bin/c-d-image.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 00bc8f9..5fbf169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This file is a history of the changes made to @idearium/cli. ## Unreleased +### Added + +- `c d image prune` command. + ## v5.1.0-beta.3 - 2022-08-09 ### Fixed diff --git a/bin/c-d-image-prune.js b/bin/c-d-image-prune.js new file mode 100644 index 0000000..cf7b6dc --- /dev/null +++ b/bin/c-d-image-prune.js @@ -0,0 +1,9 @@ +'use strict'; + +const program = require('commander'); +const { exec } = require('shelljs'); + +// The basic program, which uses sub-commands. +program.parse(process.argv); + +exec('docker image prune'); diff --git a/bin/c-d-image.js b/bin/c-d-image.js new file mode 100644 index 0000000..81ff2b0 --- /dev/null +++ b/bin/c-d-image.js @@ -0,0 +1,8 @@ +'use strict'; + +const program = require('commander'); +const { missingCommand } = require('./lib/c'); + +program.command('prune', 'Removes unused dangling images.').parse(process.argv); + +missingCommand(program); diff --git a/bin/c-d.js b/bin/c-d.js index 764a713..25658b9 100644 --- a/bin/c-d.js +++ b/bin/c-d.js @@ -7,6 +7,7 @@ const { missingCommand } = require('./lib/c'); program .command('build ', 'Builds a Docker image from a Docker location') .command('clean ', 'Removes unused containers and images') + .command('image', 'Commands for working with images') .command('images', 'List images') .command('ps', 'List containers') .parse(process.argv); From d2756acbd486418c9b52aee478b6db5dfb7a6f84 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:53:24 +1030 Subject: [PATCH 16/21] Fixed error handling in c kc test. --- bin/c-kc-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/c-kc-test.js b/bin/c-kc-test.js index cdaeb68..713c781 100644 --- a/bin/c-kc-test.js +++ b/bin/c-kc-test.js @@ -117,9 +117,7 @@ return buildLocation(program.B, location) ); if (!buildTag) { - return Promise.resolve( - new Error(`Could not find a build tag for ${image}`) - ); + throw Error(`Could not find a build tag for ${image}`); } const cmd = `docker run --rm --name ${prefix}-${location}-test --tty ${prefixWith( From c88ee63bd5195aeada439558b26f75b61aaad607 Mon Sep 17 00:00:00 2001 From: Allan Chau Date: Thu, 19 Jan 2023 09:52:52 +0930 Subject: [PATCH 17/21] fix admin-static name not being picked up --- bin/c-project-bump.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/c-project-bump.js b/bin/c-project-bump.js index 6bc179a..e8c48a4 100644 --- a/bin/c-project-bump.js +++ b/bin/c-project-bump.js @@ -150,7 +150,7 @@ loadConfig('npm.locations') ? `-${prereleaseIdentifier}` : ''; - const toReplace = `gcr.io/${gcpProjectId}/${name}-([a-z]+)${suffix}:(?:.+)`; + const toReplace = `gcr.io/${gcpProjectId}/${name}-([a-z-]+)${suffix}:(?:.+)`; glob( `./manifests/${environment}/*.deployment.yaml`, From 87de7636d32a25170c67d49b228340f7bc6fb061 Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Thu, 9 Feb 2023 09:57:57 +1030 Subject: [PATCH 18/21] Added support for loading files (volumes) into the containers for all c mongo commands. --- bin/c-mongo-connect.js | 6 +++++- bin/c-mongo-download.js | 12 ++++++------ bin/c-mongo-import.js | 8 ++++++-- bin/lib/c-mongo.js | 14 ++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bin/c-mongo-connect.js b/bin/c-mongo-connect.js index 8f571dc..08c5182 100644 --- a/bin/c-mongo-connect.js +++ b/bin/c-mongo-connect.js @@ -23,7 +23,11 @@ const connectionStringWithHost = ({ auth, host, name, params }) => loadConfig(`mongo.${env}`) .then((details) => { const connection = connectionParts(details); - const cmd = `docker run -it --rm -v $(pwd)/data/mongo:/home/mongodb/ mongo:4.2 mongo ${ + const cmd = `docker run -it --rm -v $(pwd)/data/mongo:/home/mongodb/${ + connection.volumes.length > 0 + ? ` ${connection.volumes.join(' ')}` + : '' + } mongo:4.2 mongo ${ connection.host ? connectionStringWithHost(connection) : connectionStringWithAddress(connection) diff --git a/bin/c-mongo-download.js b/bin/c-mongo-download.js index e906d11..59de847 100644 --- a/bin/c-mongo-download.js +++ b/bin/c-mongo-download.js @@ -43,23 +43,23 @@ const connectionStringWithAddress = ({ }; const connectionStringWithHost = ({ auth, host, name, params }) => - `--authenticationDatabase ${name}${auth}${params} --host ${host} -d ${name}`; + `${auth}${params} --host ${host} -d ${name}`; loadConfig(`mongo.${env}`) .then((details) => { const collectionArg = typeof collection === 'undefined' ? '' : `-c ${collection}`; const connection = connectionParts(details); - const cmd = `docker run -it -v ${process.cwd()}/data:/data --rm mongo:4.2 mongodump ${ + const cmd = `docker run -it -v ${process.cwd()}/data:/data${ + connection.volumes.length > 0 + ? ` ${connection.volumes.join(' ')}` + : '' + } --rm mongo:4.2 mongodump ${ connection.host ? connectionStringWithHost(connection) : connectionStringWithAddress(connection) } ${collectionArg} -o data`; - console.log('cmd', cmd); - - // process.exit(0); - return spawn(cmd, { shell: true, stdio: 'inherit', diff --git a/bin/c-mongo-import.js b/bin/c-mongo-import.js index ab51d82..c988da0 100644 --- a/bin/c-mongo-import.js +++ b/bin/c-mongo-import.js @@ -31,11 +31,11 @@ const connectionStringWithAddress = ({ address, params, password, user }) => { return `${params} --uri ${url.href}`; }; -const connectionStringWithHost = ({ auth, host, name, params }) => { +const connectionStringWithHost = ({ auth, host, params }) => { let connectionString = `--host ${host}`; if (auth) { - connectionString = `--authenticationDatabase ${name}${auth}${params} ${connectionString}`; + connectionString = `${auth}${params} ${connectionString}`; } return connectionString; @@ -84,6 +84,10 @@ loadConfig('mongo') const cmd = `docker run -it -v ${process.cwd()}/data/${db.name}:/data/${ db.name + }${ + toDbConnection.volumes.length > 0 + ? ` ${toDbConnection.volumes.join(' ')}` + : '' }${addHost} --rm mongo:4.2 mongorestore --noIndexRestore --drop ${ toDbConnection.host ? connectionStringWithHost(toDbConnection) diff --git a/bin/lib/c-mongo.js b/bin/lib/c-mongo.js index cd3e07d..3d28182 100644 --- a/bin/lib/c-mongo.js +++ b/bin/lib/c-mongo.js @@ -8,6 +8,7 @@ const connectionParts = ({ password, port, user, + volumes = [], }) => { const auth = user && password ? ` -u ${user} -p ${password}` : ''; const params = paramsArray.length ? ` ${paramsArray.join(' ')}` : ''; @@ -18,14 +19,23 @@ const connectionParts = ({ params, password, user, + volumes: volumes.map((file) => { + const [local, remote] = file.split(':'); + + return `-v ${process.cwd()}/${local}:${remote}`; + }), }; if (address) { parts.address = address; } - if (host && port) { - parts.host = `${host}:${port}`; + if (host) { + parts.host = host; + } + + if (port) { + parts.host += `:${port}`; } return parts; From 47ff58e136d0b136e53ebc7939e9747b3c073964 Mon Sep 17 00:00:00 2001 From: Allan Chau Date: Fri, 24 Feb 2023 09:12:04 +0930 Subject: [PATCH 19/21] use mongo 4.4 --- bin/c-mongo-connect.js | 2 +- bin/c-mongo-download.js | 2 +- bin/c-mongo-import.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/c-mongo-connect.js b/bin/c-mongo-connect.js index 08c5182..bcec150 100644 --- a/bin/c-mongo-connect.js +++ b/bin/c-mongo-connect.js @@ -27,7 +27,7 @@ loadConfig(`mongo.${env}`) connection.volumes.length > 0 ? ` ${connection.volumes.join(' ')}` : '' - } mongo:4.2 mongo ${ + } mongo:4.4 mongo ${ connection.host ? connectionStringWithHost(connection) : connectionStringWithAddress(connection) diff --git a/bin/c-mongo-download.js b/bin/c-mongo-download.js index 59de847..8b144c0 100644 --- a/bin/c-mongo-download.js +++ b/bin/c-mongo-download.js @@ -54,7 +54,7 @@ loadConfig(`mongo.${env}`) connection.volumes.length > 0 ? ` ${connection.volumes.join(' ')}` : '' - } --rm mongo:4.2 mongodump ${ + } --rm mongo:4.4 mongodump ${ connection.host ? connectionStringWithHost(connection) : connectionStringWithAddress(connection) diff --git a/bin/c-mongo-import.js b/bin/c-mongo-import.js index c988da0..e1fd21c 100644 --- a/bin/c-mongo-import.js +++ b/bin/c-mongo-import.js @@ -88,7 +88,7 @@ loadConfig('mongo') toDbConnection.volumes.length > 0 ? ` ${toDbConnection.volumes.join(' ')}` : '' - }${addHost} --rm mongo:4.2 mongorestore --noIndexRestore --drop ${ + }${addHost} --rm mongo:4.4 mongorestore --noIndexRestore --drop ${ toDbConnection.host ? connectionStringWithHost(toDbConnection) : connectionStringWithAddress(toDbConnection) From fa37cdd7b70d7e72da0b5279c09d1a44299e6ced Mon Sep 17 00:00:00 2001 From: Scott Mebberson <74628+smebberson@users.noreply.github.com> Date: Wed, 31 May 2023 12:29:12 +0930 Subject: [PATCH 20/21] Improved c d build and c kc build commands. --- bin/c-d-build.js | 6 +----- bin/c-kc-build.js | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/bin/c-d-build.js b/bin/c-d-build.js index dc3655b..6506172 100644 --- a/bin/c-d-build.js +++ b/bin/c-d-build.js @@ -85,14 +85,10 @@ return loadConfig('docker.locations').then((locations) => { } exec(cmd, { silent: program.R }, (err, stdout, stderr) => { - if ((err || stderr) && stderr) { + if (err !== 0) { return reportError(stderr, false, true); } - if ((err || stderr) && err) { - return reportError(err, false, true); - } - if (program.R) { process.stdout.write(`${tag}${newline(opts.name)}`); } diff --git a/bin/c-kc-build.js b/bin/c-kc-build.js index 1c3663e..661c1d2 100644 --- a/bin/c-kc-build.js +++ b/bin/c-kc-build.js @@ -54,14 +54,10 @@ const buildLocation = ({ config, loc, prefix, state }) => )} ${loc}`; exec(cmd, (err, stdout, stderr) => { - if ((err || stderr) && stderr) { + if (err !== 0) { return reject(new Error(stderr)); } - if ((err || stderr) && err) { - return reject(err); - } - storeState( `kubernetes.environments.${state.env}.build.tags.${prefix}/${loc}`, tag From 9f2944495b91b5284fa1fbbc95caa154c87f2301 Mon Sep 17 00:00:00 2001 From: Allan Chau Date: Wed, 31 May 2023 12:32:30 +0930 Subject: [PATCH 21/21] remove --kubernetes-version=v1.20.7 requirement --- bin/c-mk-start.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/c-mk-start.js b/bin/c-mk-start.js index 001d778..067a8f3 100644 --- a/bin/c-mk-start.js +++ b/bin/c-mk-start.js @@ -15,5 +15,5 @@ const profile = program.P ? ` --profile ${program.P}` : ''; const command = `minikube start${profile}`; exec( - `${command} --extra-config=apiserver.service-node-port-range=80-32767 --cpus=4 --memory=12288 --vm-driver=docker --kubernetes-version=v1.20.7` + `${command} --extra-config=apiserver.service-node-port-range=80-32767 --cpus=4 --memory=12288 --vm-driver=docker` );