webdetta-scripts 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/deploy.sh +24 -0
- package/bin/index.js +73 -0
- package/bin/install-guidelines.sh +6 -0
- package/package.json +18 -0
package/bin/deploy.sh
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
SSH="$SSH_USER@$SSH_HOST"
|
|
4
|
+
|
|
5
|
+
status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 $SSH echo ok 2>&1)
|
|
6
|
+
if [[ $status == ok ]] ; then
|
|
7
|
+
:
|
|
8
|
+
else
|
|
9
|
+
echo "SSH connection error: $status"
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
|
|
13
|
+
ssh $SSH bash <<eof
|
|
14
|
+
if [ "\$(which docker)" == "" ]; then
|
|
15
|
+
curl -fsSL https://get.docker.com | bash
|
|
16
|
+
fi
|
|
17
|
+
sudo groupadd docker >/dev/null 2>&1
|
|
18
|
+
sudo usermod -aG docker \$USER
|
|
19
|
+
eof
|
|
20
|
+
|
|
21
|
+
export DOCKER_HOST="ssh://$SSH"
|
|
22
|
+
export DOCKER_BUILDKIT=1
|
|
23
|
+
docker compose --file $DOCKER_COMPOSE_FILE -p $COMPOSE_PROJECT_NAME up --build --renew-anon-volumes -d
|
|
24
|
+
docker ps
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import subprocess from 'webdetta/subprocess';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const program = new Command();
|
|
8
|
+
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name('npx webdetta-scripts')
|
|
12
|
+
.usage('<command>')
|
|
13
|
+
.version('1.0.0')
|
|
14
|
+
.configureHelp({
|
|
15
|
+
subcommandTerm: (cmd) => cmd.name() + (cmd.usage().replace('[options]', '') || ''),
|
|
16
|
+
})
|
|
17
|
+
.helpCommand(false);
|
|
18
|
+
|
|
19
|
+
program
|
|
20
|
+
.command('help')
|
|
21
|
+
.argument('[command]')
|
|
22
|
+
.action(function () {
|
|
23
|
+
if (this.args[0]) {
|
|
24
|
+
const cmd = this.parent.commands.find((c) => c._name === this.args[0]);
|
|
25
|
+
if (!cmd) console.error('Unknown command: ', this.args[0]);
|
|
26
|
+
else console.log(cmd.helpInformation());
|
|
27
|
+
} else {
|
|
28
|
+
console.log(program.help());
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
program
|
|
33
|
+
.command('install-guidelines')
|
|
34
|
+
.description('Clone guidelines repo to .GUIDELINES and add to .gitignore.')
|
|
35
|
+
.action(async () => {
|
|
36
|
+
await subprocess('bash', path.join(dir, 'install-guidelines.sh'), {
|
|
37
|
+
shell: true,
|
|
38
|
+
stdio: 'inherit',
|
|
39
|
+
cwd: process.cwd(),
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.command('deploy')
|
|
45
|
+
.description('Deploys services defined in docker-compose.yml file into a remote machine via SSH.')
|
|
46
|
+
.requiredOption('-f, --file <path>', 'Path to docker-compose.yml file')
|
|
47
|
+
.requiredOption('-p, --project <name>', 'Project name to distinguish different deployments')
|
|
48
|
+
.requiredOption('-u, --user <username>', 'Remote ssh user')
|
|
49
|
+
.requiredOption('-h, --host <host>', 'Remote ssh host')
|
|
50
|
+
.action(async (options) => {
|
|
51
|
+
await subprocess('bash', path.join(dir, 'deploy.sh'), {
|
|
52
|
+
shell: true,
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
env: {
|
|
55
|
+
...process.env,
|
|
56
|
+
DOCKER_COMPOSE_FILE: options.file,
|
|
57
|
+
COMPOSE_PROJECT_NAME: options.project,
|
|
58
|
+
SSH_USER: options.user,
|
|
59
|
+
SSH_HOST: options.host,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const cmd = process.argv[2];
|
|
65
|
+
if (!cmd) {
|
|
66
|
+
console.log(program.help());
|
|
67
|
+
} else if (cmd === '--help' || cmd === '-h' || cmd === '--version' || cmd === '-V') {
|
|
68
|
+
program.parse(process.argv);
|
|
69
|
+
} else if (!program.commands.find((c) => c._name.split(' ')[0] === cmd)) {
|
|
70
|
+
console.log('unknown command, try "npx webdetta --help"');
|
|
71
|
+
} else {
|
|
72
|
+
program.parse(process.argv);
|
|
73
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webdetta-scripts",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Webdetta Scripts",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": "./bin/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"bin"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"commander": "^12.0.0",
|
|
12
|
+
"webdetta": "^0.1.178"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@eslint/js": "^9.39.2",
|
|
16
|
+
"globals": "^17.3.0"
|
|
17
|
+
}
|
|
18
|
+
}
|