create-directus-docker 1.4.0 → 1.4.2
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/README.md
CHANGED
|
@@ -31,6 +31,10 @@ Directus CMS: http://localhost:8055
|
|
|
31
31
|
Adminer (for MySQL): http://localhost:8080
|
|
32
32
|
GraphQL Playground: http://localhost:4000/graphql
|
|
33
33
|
|
|
34
|
+
## Seeding MySQL data
|
|
35
|
+
|
|
36
|
+
If you want to seed your database with data on first launch, place your .sql file(s) in the "init" directory at the root of this package, BEFORE you run all services. MySQL will run any files in this directory the first time it launches.
|
|
37
|
+
|
|
34
38
|
## Starting/stopping with Docker Compose
|
|
35
39
|
|
|
36
40
|
To **stop** your running containers, simply run either `npm run stop` or `docker compose down` from within the project directory. All containers will be stopped.
|
package/package.json
CHANGED
|
@@ -6,8 +6,30 @@ import logUpdate from 'log-update';
|
|
|
6
6
|
import open from 'open';
|
|
7
7
|
import inquirer from 'inquirer';
|
|
8
8
|
import * as dotenv from 'dotenv';
|
|
9
|
+
import jq from 'node-jq';
|
|
9
10
|
dotenv.config();
|
|
10
11
|
|
|
12
|
+
function outputDone() {
|
|
13
|
+
if (process.env.DIRECTUS_DOMAIN === 'localhost') {
|
|
14
|
+
var appURL = 'http://localhost';
|
|
15
|
+
} else {
|
|
16
|
+
var appURL = process.env.DIRECTUS_DOMAIN;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(chalk.green("\nAll services should be ready. You can access them at the following URLs:\n"));
|
|
20
|
+
console.log(`Directus CMS: ${chalk.cyan(process.env.PUBLIC_URL)}`);
|
|
21
|
+
console.log(`Adminer: ${chalk.cyan(appURL + ":8080")}`);
|
|
22
|
+
console.log(`GraphiQL Playground: ${chalk.cyan(appURL + ":4000/graphql")}`);
|
|
23
|
+
|
|
24
|
+
console.log(`\n${chalk.redBright("Note: learn how to avoid CORS errors in the GraphiQL Playground when running on localhost:")}`);
|
|
25
|
+
console.log(`https://github.com/rollmug/directus-mysql-template#cors-problems-on-localhost`)
|
|
26
|
+
|
|
27
|
+
console.log(`\n${chalk.green("When you're finished, you can stop all running containers with:")}\n`);
|
|
28
|
+
console.log(`npm run stop\n`);
|
|
29
|
+
console.log(`${chalk.green("You can start them all back up again with:")}`);
|
|
30
|
+
console.log(`npm run launch\n`);
|
|
31
|
+
}
|
|
32
|
+
|
|
11
33
|
export default function launchServices() {
|
|
12
34
|
const launch = spawn('docker-compose', ['up', '-d', 'mysql']);
|
|
13
35
|
|
|
@@ -34,83 +56,81 @@ export default function launchServices() {
|
|
|
34
56
|
waitOn(opts, (err) => {
|
|
35
57
|
if (err) console.log(err);
|
|
36
58
|
// once here, all resources are available
|
|
59
|
+
loader.stop();
|
|
60
|
+
console.log('MySQL ready.');
|
|
37
61
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
sleeper.on('close', code => {
|
|
41
|
-
loader.stop();
|
|
42
|
-
console.log('MySQL ready.');
|
|
62
|
+
logUpdate("Building and launching containers:\n");
|
|
63
|
+
logUpdate.done();
|
|
43
64
|
|
|
44
|
-
|
|
45
|
-
logUpdate.done();
|
|
65
|
+
const launch2 = spawn('docker-compose', ['up', '-d']);
|
|
46
66
|
|
|
47
|
-
|
|
67
|
+
launch2.stderr.on('data', (data) => {
|
|
68
|
+
logUpdate(`${data}`);
|
|
69
|
+
});
|
|
48
70
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
launch2.on('close', code => {
|
|
72
|
+
logUpdate('Done.');
|
|
73
|
+
logUpdate.done();
|
|
52
74
|
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
const pingOpts = {
|
|
76
|
+
resources: [
|
|
77
|
+
`${process.env.PUBLIC_URL}`
|
|
78
|
+
],
|
|
79
|
+
delay: 1000,
|
|
80
|
+
interval: 300,
|
|
81
|
+
timeout: 40000,
|
|
82
|
+
tcpTimeout: 40000
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const loader2 = ora('Waiting for Directus to be ready').start();
|
|
86
|
+
|
|
87
|
+
waitOn(pingOpts).then(() => {
|
|
88
|
+
loader2.stop();
|
|
89
|
+
logUpdate('Directus ready.');
|
|
55
90
|
logUpdate.done();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
]).then(answers => {
|
|
100
|
-
if(answers.open_now === true) {
|
|
101
|
-
open(process.env.PUBLIC_URL);
|
|
102
|
-
open(`${appURL}:8080`);
|
|
103
|
-
open(`${appURL}:4000/graphql`);
|
|
104
|
-
} else {
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}).catch((err) => {
|
|
109
|
-
//console.log(err);
|
|
110
|
-
loader2.stop();
|
|
111
|
-
console.log(`${chalk.redBright("Directus taking too long to respond. You may need to manually start it.")}`);
|
|
112
|
-
console.log(`Just run ${chalk.greenBright("npm run launch")} and you should be good to go.`)
|
|
113
|
-
process.exit(1);
|
|
91
|
+
outputDone();
|
|
92
|
+
|
|
93
|
+
inquirer.prompt([
|
|
94
|
+
{
|
|
95
|
+
type: 'confirm',
|
|
96
|
+
name: 'open_now',
|
|
97
|
+
message: "Open services in browser now?"
|
|
98
|
+
}
|
|
99
|
+
]).then(answers => {
|
|
100
|
+
if (answers.open_now === true) {
|
|
101
|
+
open(process.env.PUBLIC_URL);
|
|
102
|
+
open(`${appURL}:8080`);
|
|
103
|
+
open(`${appURL}:4000/graphql`);
|
|
104
|
+
} else {
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}).catch((err) => {
|
|
109
|
+
loader2.stop();
|
|
110
|
+
//if we're here, it's because directus is taking too long to respond.
|
|
111
|
+
//It may be that it's running, so let's be sure.
|
|
112
|
+
logUpdate('Directus taking a long time to respond...');
|
|
113
|
+
|
|
114
|
+
const check = spawn('docker-compose', ['ps', '--format', 'json']);
|
|
115
|
+
|
|
116
|
+
check.stdout.on('data', (data) => {
|
|
117
|
+
const q = 'map(select(.Name == "directus")) | .[0] | {Name: .Name, Service: .Service, State: .State}';
|
|
118
|
+
jq.run(q, data.toString(), { input: 'string' })
|
|
119
|
+
.then((data) => {
|
|
120
|
+
const json = JSON.parse(data);
|
|
121
|
+
|
|
122
|
+
if(json.State == 'running') {
|
|
123
|
+
logUpdate(`${chalk.yellowBright("Directus appears to be running, but took a while to respond.")}`);
|
|
124
|
+
console.log(`Just run ${chalk.greenBright("npm run launch")} to verify, and you should be good to go.`);
|
|
125
|
+
logUpdate.done();
|
|
126
|
+
process.exit(1);
|
|
127
|
+
} else {
|
|
128
|
+
logUpdate.done();
|
|
129
|
+
console.log(`${chalk.redBright("Directus taking too long to respond. You may need to manually start it.")}`);
|
|
130
|
+
console.log(`Just run ${chalk.greenBright("npm run launch")} and you should be good to go.`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
114
134
|
});
|
|
115
135
|
});
|
|
116
136
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-mysql-docker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A helper app to configure Directus on Docker with MySQL, Adminer, and GraphQL",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"inquirer": "^9.1.4",
|
|
53
53
|
"log-update": "^5.0.1",
|
|
54
54
|
"lookpath": "^1.2.2",
|
|
55
|
+
"node-jq": "^2.3.5",
|
|
55
56
|
"open": "^8.4.0",
|
|
56
57
|
"ora": "^6.1.2",
|
|
57
58
|
"wait-on": "^7.0.1"
|