Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for Linux #91

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
36 changes: 36 additions & 0 deletions bin/c-dev-ip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const program = require('commander');
const { exec } = require('shelljs');
const {
devspacePath,
loadState,
newline,
reportError,
stateFilePath,
} = require('./lib/c');

// The basic program, which uses sub-commands.
program
.option('-n', 'Do not print the trailing newline character.')
.option(
'-p [profile]',
'Specify a minikube profile, otherwise the default minikube profile will be used.'
)
.parse(process.argv);

const run = async () => {
const devName = await loadState('devName', stateFilePath(devspacePath()));

exec(`c ts ip ${devName}`, { silent: true }, (err, stdout, stderr) => {
if (err) {
return reportError(new Error(stderr), false, true);
}

process.stdout.write(
`${stdout.replace(/\n/, '', 'g')}${newline(program.N)}`
);
});
};

run();
10 changes: 10 additions & 0 deletions bin/c-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env -S node

'use strict';

const program = require('commander');
const { missingCommand } = require('./lib/c');

program.command('ip', 'Manage your dev computer.').parse(process.argv);

missingCommand(program);
34 changes: 34 additions & 0 deletions bin/c-ds-dev-get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env -S node

'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('devName', stateFilePath(devspacePath()))
.then((data) => {
process.stdout.write(`${data}${newline(program.N)}`);
})
.catch((err) => {
if (err.code === 'ENOENT') {
return reportError(
new Error(
"Your dev computer name hasn't been configured yet. Use `c ds dev set <dev-name>`."
),
false,
true
);
}

return reportError(err, false, true);
});
35 changes: 35 additions & 0 deletions bin/c-ds-dev-set.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env -S node

'use strict';

const program = require('commander');
const {
devspacePath,
reportError,
stateFilePath,
storeState,
} = require('./lib/c');

program
.arguments('<dev-name>')
.description("Set your dev computer's name.")
.parse(process.argv);

const [name] = program.args;

if (!name) {
return reportError(
new Error("You must provide your dev computer's name."),
program
);
}

const run = async () => {
try {
await storeState('devName', name, stateFilePath(devspacePath()));
} catch (err) {
reportError(err, program, true);
}
};

run();
13 changes: 13 additions & 0 deletions bin/c-ds-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env -S node

'use strict';

const program = require('commander');
const { missingCommand } = require('./lib/c');

program
.command('get', 'Get your dev computer name.')
.command('set <dev-name>', 'Set your dev computer name.')
.parse(process.argv);

missingCommand(program);
2 changes: 1 addition & 1 deletion bin/c-ds-handle-get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
3 changes: 2 additions & 1 deletion bin/c-ds-handle-set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down Expand Up @@ -29,6 +29,7 @@ const run = async () => {

try {
await storeState('handle', handle, file);
await storeState('devName', `${handle}-dev`, file);
await storeState('mkName', `${handle}-minikube`, file);
await storeState('pcName', `${handle}-pc`, file);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-handle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-mk-get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-mk-set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-mk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-pc-get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-pc-set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion bin/c-ds-pc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand Down
8 changes: 5 additions & 3 deletions bin/c-ds.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node

'use strict';

Expand All @@ -7,8 +7,10 @@ const { missingCommand } = require('./lib/c');

program
.command('handle', 'Manage your Idearium handle.')
.command('mk', 'Manage your Minikube name.')
.command('pc', 'Manager your computer name.')
.command('mk', 'Manage your minikube name.')
.command('dev', 'Manage your dev computer name.')
.command('pc', 'Manage your computer name.')
.command('target', 'Manage your deployment target.')
.parse(process.argv);

missingCommand(program);
2 changes: 1 addition & 1 deletion bin/c-gc-cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
20 changes: 19 additions & 1 deletion bin/c-hosts-add.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const program = require('commander');
const { spawnSync } = require('child_process');
const { execSync, spawnSync } = require('child_process');
const { hostilePath, reportError } = require('./lib/c');

let ip;
Expand All @@ -27,7 +27,25 @@ if (!domains) {
);
}

const findNodePath = () => {
let nodePath;
try {
nodePath = execSync('which node').toString().trim();
} catch (error) {
console.error('Node.js is not installed or not found in PATH.');
process.exit(1);
}

if (!nodePath) {
console.error('Node.js is not installed or not found in PATH.');
process.exit(1);
}

return nodePath;
};

const { status, stderr } = spawnSync('sudo', [
findNodePath(),
hostilePath(),
'set',
ip,
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-apply.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-logs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-manifests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-pod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-start.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
2 changes: 1 addition & 1 deletion bin/c-kc-stop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S node --trace-warnings
#!/usr/bin/env -S node
'use strict';

const program = require('commander');
Expand Down
20 changes: 19 additions & 1 deletion bin/c-mk-start.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const os = require('os');
const program = require('commander');
const { exec } = require('shelljs');

Expand All @@ -11,9 +12,26 @@ program
)
.parse(process.argv);

const platform = os.platform();
const profile = program.P ? ` --profile ${program.P}` : '';
const command = `minikube start${profile}`;

const defaultSettings = {
cpus: 4,
memory: 12288,
};
const settings = {
darwin: defaultSettings,
linux: {
cpus: 12,
memory: 24576,
},
};

exec(
`${command} --extra-config=apiserver.service-node-port-range=80-32767 --cpus=4 --memory=12288 --vm-driver=docker`
`${command} --extra-config=apiserver.service-node-port-range=80-32767 --cpus=${
(settings[platform] ?? defaultSettings).cpus
} --memory=${
(settings[platform] ?? defaultSettings).memory
} --vm-driver=docker`
);
35 changes: 35 additions & 0 deletions bin/c-mongo-connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e;

SCRIPT_DIR=$(dirname "$0")

report_error() {
echo "Error: $1" >&2
exit 1
}

usage() {
printf "\n\tUsage: c mongo connect <environment>\n\n"
printf "\tConnect to a mongodb instance.\n"
printf "\tOptions:\n\n"
printf "\t-h, --help Display this help message\n\n"
}

if [ "$#" -lt 1 ]; then
usage
exit 1
fi

if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
exit 0
fi

ENV=$1

CONFIG=$(node "$SCRIPT_DIR/c-mongo-connect-config.js" "$ENV")

CONNECTION_STRING=$(echo $CONFIG | jq -r '.connectionString')

docker run -it --rm --network host -v $SCRIPT_DIR/data/mongo:/home/mongodb/ mongo:7 mongosh $CONNECTION_STRING
Loading
Loading