@fishawack/lab-env 1.10.0 → 1.12.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/CHANGELOG.md +17 -0
- package/cli.js +4 -11
- package/commands/create/cmds/diagnose.js +4 -0
- package/commands/create/services/guide.js +16 -0
- package/commands/create/services/test.js +25 -4
- package/commands/docker/compose.js +15 -0
- package/commands/docker/up.js +11 -1
- package/commands/script.js +16 -0
- package/commands/setup.js +1 -8
- package/commands/start.js +3 -10
- package/globals.js +42 -8
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 1.12.1 (2021-11-26)
|
|
4
|
+
* [Bug] Pass along errors thrown in new _.up function so commands correctly come to a stop when errors are thrown
|
|
5
|
+
|
|
6
|
+
### 1.12.0 (2021-11-17)
|
|
7
|
+
* [Feature] Test for watertight-node-auto access
|
|
8
|
+
* [Feature] Test for multiple ssh keys
|
|
9
|
+
|
|
10
|
+
### 1.11.0 (2021-10-26)
|
|
11
|
+
* [Feature] Show ports on up command if -v flag given
|
|
12
|
+
* [Feature] Added compose command
|
|
13
|
+
* [Change] If ports are already running then grab what they are from docker ps
|
|
14
|
+
* [Change] Show ports on all projects when fw start called
|
|
15
|
+
* [Bug] Fixed typo throwing r is not defined warning
|
|
16
|
+
|
|
17
|
+
### 1.10.1 (2021-10-26)
|
|
18
|
+
* [Feature] Added a script command
|
|
19
|
+
|
|
3
20
|
### 1.10.0 (2021-10-26)
|
|
4
21
|
* [Change] Drupal now uses apache instead of nginx
|
|
5
22
|
* [Change] Custom php docker image for Drupal with mysql client installed
|
package/cli.js
CHANGED
|
@@ -10,22 +10,15 @@ updateNotifier({pkg, updateCheckInterval: 0}).notify();
|
|
|
10
10
|
|
|
11
11
|
const execSync = require('child_process').execSync;
|
|
12
12
|
|
|
13
|
-
const getPort = require('get-port');
|
|
14
|
-
|
|
15
13
|
const yargs = require('yargs/yargs');
|
|
16
14
|
const { hideBin } = require('yargs/helpers');
|
|
17
15
|
|
|
18
16
|
const args = hideBin(process.argv);
|
|
19
17
|
|
|
20
18
|
(async () => {
|
|
21
|
-
process.env.PORT = await getPort({port: getPort.makeRange(3000, 3100)});
|
|
22
|
-
process.env.PORT_OPT = +process.env.PORT + 1;
|
|
23
19
|
process.env.REPO = _.repo;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
process.env.PORT_WEB = await getPort({port: getPort.makeRange(8000, 8100)});
|
|
27
|
-
process.env.PORT_DB = await getPort({port: getPort.makeRange(3306, 3406)});
|
|
28
|
-
}
|
|
20
|
+
|
|
21
|
+
await _.ports.set();
|
|
29
22
|
|
|
30
23
|
try{
|
|
31
24
|
let cli = yargs(args)
|
|
@@ -35,7 +28,7 @@ const args = hideBin(process.argv);
|
|
|
35
28
|
});
|
|
36
29
|
|
|
37
30
|
// Repo commands
|
|
38
|
-
let commands = ['start', 'watch', 'setup', 'content', 'production', 'test', 'deploy', 'reinstall', 'install', 'uninstall', 'run', 'check', 'clean', 'nuke', 'regenerate', 'connect', 'execute', 'origin', 'npm'];
|
|
31
|
+
let commands = ['start', 'watch', 'setup', 'content', 'production', 'test', 'deploy', 'reinstall', 'install', 'uninstall', 'run', 'check', 'clean', 'nuke', 'regenerate', 'connect', 'execute', 'origin', 'npm', 'script'];
|
|
39
32
|
|
|
40
33
|
if(_.platform === "laravel"){
|
|
41
34
|
commands.push('artisan');
|
|
@@ -52,7 +45,7 @@ const args = hideBin(process.argv);
|
|
|
52
45
|
commands.forEach(d => cli.command(...require(`./commands/${d}.js`)));
|
|
53
46
|
|
|
54
47
|
// Docker commands
|
|
55
|
-
['build', 'config', 'down', 'mocha', 'rebuild', 'up', 'volumes'].forEach(d => cli.command(...require(`./commands/docker/${d}.js`)));
|
|
48
|
+
['build', 'config', 'down', 'mocha', 'rebuild', 'up', 'volumes', 'compose'].forEach(d => cli.command(...require(`./commands/docker/${d}.js`)));
|
|
56
49
|
|
|
57
50
|
// Create commands
|
|
58
51
|
['new', 'diagnose', 'delete'].forEach(d => cli.command(...require(`./commands/create/cmds/${d}.js`)));
|
|
@@ -293,4 +293,20 @@ module.exports.key = async () => {
|
|
|
293
293
|
} else {
|
|
294
294
|
throw('');
|
|
295
295
|
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
module.exports.watertight = async () => {
|
|
299
|
+
let inputs = await inquirer.prompt([
|
|
300
|
+
{
|
|
301
|
+
type: 'confirm',
|
|
302
|
+
name: 'confirm',
|
|
303
|
+
message: 'Re-run watertight check? (ensure your ssh key is uploaded to bitbucket)',
|
|
304
|
+
default: true
|
|
305
|
+
}
|
|
306
|
+
]);
|
|
307
|
+
|
|
308
|
+
if(inputs.confirm){
|
|
309
|
+
} else {
|
|
310
|
+
throw('');
|
|
311
|
+
}
|
|
296
312
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const os = require('os');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const glob = require("glob");
|
|
3
4
|
|
|
4
5
|
const utils = require('../libs/utilities');
|
|
5
6
|
const vars = require('../libs/vars');
|
|
7
|
+
const { execSync, exec } = require('child_process');
|
|
6
8
|
|
|
7
9
|
module.exports.targets = async () => {
|
|
8
10
|
// Check targets folder exists
|
|
@@ -127,12 +129,31 @@ module.exports.ssh = async () => {
|
|
|
127
129
|
|
|
128
130
|
module.exports.key = async () => {
|
|
129
131
|
// Check misc.json exists
|
|
130
|
-
let spinner = new utils.Spinner('Looking for id_rsa
|
|
131
|
-
|
|
132
|
+
let spinner = new utils.Spinner('Looking for id_rsa key in .ssh');
|
|
133
|
+
|
|
132
134
|
if (fs.existsSync(`${os.homedir()}/.ssh/id_rsa`)) {
|
|
133
|
-
spinner.update('Found \'id_rsa\'
|
|
135
|
+
spinner.update('Found \'id_rsa\' key');
|
|
136
|
+
return true;
|
|
137
|
+
} else if (glob.sync(`${os.homedir()}/.ssh/**/*.pub`).length) {
|
|
138
|
+
spinner.update('Found multiple ssh keys');
|
|
134
139
|
return true;
|
|
135
140
|
} else {
|
|
136
|
-
spinner.update('Could not find \'id_rsa\'
|
|
141
|
+
spinner.update('Could not find \'id_rsa\' key', 'fail');
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports.watertight = async () => {
|
|
146
|
+
// Check misc.json exists
|
|
147
|
+
let spinner = new utils.Spinner('Testing access to watertight-node-auto repository');
|
|
148
|
+
|
|
149
|
+
try{
|
|
150
|
+
!await new Promise((resolve, reject) => exec('git clone --bare git@bitbucket.org:fishawackdigital/watertight-node-auto ./.tmp/watertight-node-auto', (error, stdout, stderr) => (error) ? reject(error) : resolve()));
|
|
151
|
+
|
|
152
|
+
spinner.update('Successfully accessed watertight-node-auto repository');
|
|
153
|
+
return true;
|
|
154
|
+
} catch(e){
|
|
155
|
+
spinner.update('Could not access watertight-node-auto repository', 'fail');
|
|
156
|
+
} finally{
|
|
157
|
+
execSync('rm -rf ./.tmp/watertight-node-auto', {stdio: 'pipe'});
|
|
137
158
|
}
|
|
138
159
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const _ = require('../../globals.js');
|
|
2
|
+
|
|
3
|
+
const execSync = require('child_process').execSync;
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
'compose [command...]',
|
|
7
|
+
false,
|
|
8
|
+
yargs => {
|
|
9
|
+
yargs.positional('command', {
|
|
10
|
+
describe: 'command to run',
|
|
11
|
+
default: ''
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
argv => execSync(`${_.docker} ${argv.command.join(' ')}`, _.opts)
|
|
15
|
+
];
|
package/commands/docker/up.js
CHANGED
|
@@ -10,6 +10,16 @@ module.exports = [
|
|
|
10
10
|
describe: 'flags to pass',
|
|
11
11
|
default: ''
|
|
12
12
|
});
|
|
13
|
+
|
|
14
|
+
yargs.option('verbose', {
|
|
15
|
+
alias: 'v',
|
|
16
|
+
describe: 'Show breakdown of packages',
|
|
17
|
+
type: 'boolean'
|
|
18
|
+
});
|
|
13
19
|
},
|
|
14
|
-
argv =>
|
|
20
|
+
argv => {
|
|
21
|
+
if(argv.v) _.ports.get();
|
|
22
|
+
|
|
23
|
+
execSync(`${_.docker} up ${argv.flags.join(' ')}`, _.opts);
|
|
24
|
+
}
|
|
15
25
|
];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const _ = require('../globals.js');
|
|
2
|
+
|
|
3
|
+
const execSync = require('child_process').execSync;
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
'script <script>',
|
|
7
|
+
'Runs a bash script from the _Scripts directory',
|
|
8
|
+
yargs => {
|
|
9
|
+
yargs.positional('script', {
|
|
10
|
+
describe: 'script to run (exlude extension)'
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
argv => {
|
|
14
|
+
_.up(() => execSync(`source ${__dirname}/../intercept.sh && /bin/bash ./_Scripts/${argv.script}.sh`, _.opts));
|
|
15
|
+
}
|
|
16
|
+
];
|
package/commands/setup.js
CHANGED
|
@@ -8,14 +8,7 @@ module.exports = [
|
|
|
8
8
|
yargs => {},
|
|
9
9
|
argv => {
|
|
10
10
|
if(_.platform === "laravel" || _.platform === "wordpress" || _.platform === "drupal"){
|
|
11
|
-
_.up(
|
|
12
|
-
() => execSync(`source ${__dirname}/../intercept.sh && /bin/bash ./_Scripts/setup.sh`, _.opts),
|
|
13
|
-
e => {
|
|
14
|
-
if(e.status !== 130 && e.status !== 131 && e.status !== 1){
|
|
15
|
-
console.log(e.message);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
);
|
|
11
|
+
_.up(() => execSync(`source ${__dirname}/../intercept.sh && /bin/bash ./_Scripts/setup.sh`, _.opts));
|
|
19
12
|
} else {
|
|
20
13
|
execSync(`${_.docker} ${_.run}c "npm run setup"`, _.opts);
|
|
21
14
|
}
|
package/commands/start.js
CHANGED
|
@@ -12,17 +12,10 @@ module.exports = [
|
|
|
12
12
|
});
|
|
13
13
|
},
|
|
14
14
|
argv => {
|
|
15
|
+
_.ports.get();
|
|
16
|
+
|
|
15
17
|
if(_.platform === "laravel" || _.platform === "wordpress" || _.platform === "drupal"){
|
|
16
|
-
_.
|
|
17
|
-
|
|
18
|
-
_.up(
|
|
19
|
-
() => execSync(`${_.docker} ${_.exec} core bash -lc "npm start -- -- ${argv.flags.join(' ')}" 2>/dev/null`, _.opts),
|
|
20
|
-
e => {
|
|
21
|
-
if(e.status !== 130 && e.status !== 131 && e.status !== 1){
|
|
22
|
-
console.log(e);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
);
|
|
18
|
+
_.up(() => execSync(`${_.docker} ${_.exec} core bash -lc "npm start -- -- ${argv.flags.join(' ')}" 2>/dev/null`, _.opts));
|
|
26
19
|
} else {
|
|
27
20
|
execSync(`${_.docker} ${_.run}c "npm start -- -- ${argv.flags.join(' ')}" 2>/dev/null`, _.opts);
|
|
28
21
|
}
|
package/globals.js
CHANGED
|
@@ -2,6 +2,7 @@ const execSync = require('child_process').execSync;
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { lstatSync, readdirSync, copyFileSync, existsSync } = require('fs');
|
|
4
4
|
const semver = require('semver');
|
|
5
|
+
const getPort = require('get-port');
|
|
5
6
|
|
|
6
7
|
const isDirectory = source => lstatSync(source).isDirectory();
|
|
7
8
|
const getDirectories = source => readdirSync(source).map(name => path.join(source, name)).filter(isDirectory);
|
|
@@ -15,6 +16,7 @@ var method;
|
|
|
15
16
|
var run;
|
|
16
17
|
var exec;
|
|
17
18
|
var running;
|
|
19
|
+
var services;
|
|
18
20
|
var opts = {encoding: 'utf8', stdio: 'inherit', shell: '/bin/bash'};
|
|
19
21
|
|
|
20
22
|
try{
|
|
@@ -70,7 +72,8 @@ if(platform === 'laravel'){
|
|
|
70
72
|
docker = `docker-compose -f ${__dirname}/core/${process.env.VERSION}/docker-compose.yml -p ${repo}`;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
services = execSync(`${docker} ps --services --filter "status=running"`, {encoding: 'utf8'});
|
|
76
|
+
running = services.trim().length;
|
|
74
77
|
exec = `exec ${process.env.CI_BUILD_ID ? '-T' : ''}`;
|
|
75
78
|
method = running ? exec : 'run --rm --service-ports';
|
|
76
79
|
run = `${method} core bash -l`;
|
|
@@ -86,12 +89,43 @@ module.exports = {
|
|
|
86
89
|
exec,
|
|
87
90
|
running,
|
|
88
91
|
opts,
|
|
89
|
-
ports
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
ports: {
|
|
93
|
+
async set(){
|
|
94
|
+
if(!running){
|
|
95
|
+
process.env.PORT = await getPort({port: getPort.makeRange(3000, 3100)});
|
|
96
|
+
process.env.PORT_OPT = +process.env.PORT + 1;
|
|
97
|
+
|
|
98
|
+
if(platform === "laravel" || platform === "wordpress" || platform === "drupal"){
|
|
99
|
+
process.env.PORT_WEB = await getPort({port: getPort.makeRange(8000, 8100)});
|
|
100
|
+
process.env.PORT_DB = await getPort({port: getPort.makeRange(3306, 3406)});
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
try{
|
|
104
|
+
let env = execSync(`${docker} exec -T core env`, {encoding: 'utf8'});
|
|
105
|
+
let ports = env.split('\n').reduce((obj, d) => { obj[d.split('=')[0]] = d.split('=')[1]; return obj; }, {});
|
|
106
|
+
|
|
107
|
+
process.env.PORT = ports.PORT;
|
|
108
|
+
process.env.PORT_OPT = ports.PORT_OPT;
|
|
109
|
+
|
|
110
|
+
if(platform === "laravel" || platform === "wordpress" || platform === "drupal"){
|
|
111
|
+
process.env.PORT_WEB = ports.PORT_WEB;
|
|
112
|
+
process.env.PORT_DB = ports.PORT_DB;
|
|
113
|
+
}
|
|
114
|
+
} catch(e){
|
|
115
|
+
console.log(e.message);
|
|
116
|
+
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
get(){
|
|
122
|
+
let ports = { core: {port: +process.env.PORT} };
|
|
123
|
+
|
|
124
|
+
if(+process.env.PORT_WEB) ports.web = {port: +process.env.PORT_WEB};
|
|
125
|
+
if(+process.env.PORT_DB) ports.db = {port: +process.env.PORT_DB};
|
|
126
|
+
|
|
127
|
+
console.table(ports);
|
|
128
|
+
}
|
|
95
129
|
},
|
|
96
130
|
up(cb, err){
|
|
97
131
|
if(!running) execSync(`lab-env up -d`, opts);
|
|
@@ -99,7 +133,7 @@ module.exports = {
|
|
|
99
133
|
try{
|
|
100
134
|
cb();
|
|
101
135
|
} catch(e){
|
|
102
|
-
|
|
136
|
+
throw(e);
|
|
103
137
|
} finally{
|
|
104
138
|
if(!running) execSync(`lab-env down`, opts);
|
|
105
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fishawack/lab-env",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "Docker manager for FW",
|
|
5
5
|
"main": "cli.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"axios": "0.21.1",
|
|
25
25
|
"chalk": "4.1.0",
|
|
26
26
|
"get-port": "5.1.1",
|
|
27
|
+
"glob": "7.1.7",
|
|
27
28
|
"inquirer": "8.1.2",
|
|
28
29
|
"ora": "5.4.1",
|
|
29
30
|
"semver": "7.3.4",
|