create-directus-docker 1.4.2 → 1.4.4
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 +22 -0
- package/package.json +1 -1
- package/templates/default/README.md +22 -0
- package/templates/default/docker-compose.yml +1 -0
- package/templates/default/lib/check-requirements.js +3 -3
- package/templates/default/lib/index.js +6 -0
- package/templates/default/lib/launch-services.js +23 -5
- package/templates/default/package.json +4 -2
package/README.md
CHANGED
|
@@ -35,6 +35,28 @@ GraphQL Playground: http://localhost:4000/graphql
|
|
|
35
35
|
|
|
36
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
37
|
|
|
38
|
+
### Snapshot the Data Model
|
|
39
|
+
|
|
40
|
+
Directus can automatically generate a snapshot of your current data model in YAML format. This includes all collections, fields, and relations, and their configuration. This snapshot can be checked in version control and shared with your team. To generate the snapshot, run:
|
|
41
|
+
|
|
42
|
+
`npm run snapshot`
|
|
43
|
+
|
|
44
|
+
The 'directus' container **must be running** in order to take a snapshot.
|
|
45
|
+
|
|
46
|
+
### Apply a Snapshot
|
|
47
|
+
|
|
48
|
+
To overwrite the current Directus instance with the data model specified in that snapshot, you can apply a snapshot by running:
|
|
49
|
+
|
|
50
|
+
`npm run snapshot-apply --snapshot=snapshot-file.yaml`
|
|
51
|
+
|
|
52
|
+
Change the name of the file in the command to match an actual snapshot file in your 'snapshots' directory.
|
|
53
|
+
|
|
54
|
+
By applying the snapshot, Directus will auto-detect the changes required to make the current instance up to date with the proposed data model in the snapshot file, and will run the required migrations to the database to make it match the snapshot. This is useful when migrating to/from another directus instance.
|
|
55
|
+
|
|
56
|
+
**It is recommended that you test this first by doing a dry-run like this:**
|
|
57
|
+
|
|
58
|
+
`npm run snapshot-test --snapshot=snapshot-file.yaml`
|
|
59
|
+
|
|
38
60
|
## Starting/stopping with Docker Compose
|
|
39
61
|
|
|
40
62
|
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
|
@@ -41,6 +41,28 @@ As an alternative, you can install this package by following these steps. Once y
|
|
|
41
41
|
|
|
42
42
|
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. MySQL will run any files in this directory the first time it launches.
|
|
43
43
|
|
|
44
|
+
### Snapshot the Data Model
|
|
45
|
+
|
|
46
|
+
Directus can automatically generate a snapshot of your current data model in YAML format. This includes all collections, fields, and relations, and their configuration. This snapshot can be checked in version control and shared with your team. To generate the snapshot, run:
|
|
47
|
+
|
|
48
|
+
`npm run snapshot`
|
|
49
|
+
|
|
50
|
+
The 'directus' container **must be running** in order to take a snapshot.
|
|
51
|
+
|
|
52
|
+
### Apply a Snapshot
|
|
53
|
+
|
|
54
|
+
To overwrite the current Directus instance with the data model specified in that snapshot, you can apply a snapshot by running:
|
|
55
|
+
|
|
56
|
+
`npm run snapshot-apply --snapshot=snapshot-file.yaml`
|
|
57
|
+
|
|
58
|
+
Change the name of the file in the command to match an actual snapshot file in your 'snapshots' directory.
|
|
59
|
+
|
|
60
|
+
By applying the snapshot, Directus will auto-detect the changes required to make the current instance up to date with the proposed data model in the snapshot file, and will run the required migrations to the database to make it match the snapshot. This is useful when migrating to/from another directus instance.
|
|
61
|
+
|
|
62
|
+
**It is recommended that you test this first by doing a dry-run like this:**
|
|
63
|
+
|
|
64
|
+
`npm run snapshot-test --snapshot=snapshot-file.yaml`
|
|
65
|
+
|
|
44
66
|
### Starting/stopping with Docker Compose
|
|
45
67
|
|
|
46
68
|
To **stop** your running containers, simply run `docker compose down` in your terminal from within the project directory. All containers will be stopped.
|
|
@@ -4,7 +4,7 @@ import { lookpath } from 'lookpath';
|
|
|
4
4
|
export default async function checkRequirements() {
|
|
5
5
|
const nodeVersion = process.versions.node;
|
|
6
6
|
const major = +nodeVersion.split('.')[0];
|
|
7
|
-
const docker = await lookpath('
|
|
7
|
+
const docker = await lookpath('docker');
|
|
8
8
|
|
|
9
9
|
if(!docker) {
|
|
10
10
|
console.error(`${chalk.red(`Docker needs to be installed and running`)}.`);
|
|
@@ -14,9 +14,9 @@ export default async function checkRequirements() {
|
|
|
14
14
|
process.exit(1);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (major <
|
|
17
|
+
if (major < 14) {
|
|
18
18
|
console.error(`You are running ${chalk.red(`Node ${nodeVersion}`)}.`);
|
|
19
|
-
console.error(`Directus requires ${chalk.green(`Node
|
|
19
|
+
console.error(`Directus requires ${chalk.green(`Node 14`)} and up.`);
|
|
20
20
|
console.error('Please update your Node version and try again.');
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
@@ -62,6 +62,12 @@ try {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
if (fs.existsSync(path.join(rootPath, 'snapshots')) === false) {
|
|
66
|
+
fs.mkdir(path.join(rootPath, 'snapshots'), () => {
|
|
67
|
+
//console.log(`'snapshots' directory created. If you want to seed your database on first lanch, place your .sql file(s) in this directory BEFORE running services.`);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
inquirer.prompt([
|
|
66
72
|
{
|
|
67
73
|
name: 'ADMIN_EMAIL',
|
|
@@ -44,7 +44,13 @@ export default function launchServices() {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
launch.stderr.on('data', (data) => {
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
if(data.includes('Cannot connect to the Docker daemon')) {
|
|
49
|
+
logUpdate(chalk.redBright(`${data}`));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
} else {
|
|
52
|
+
logUpdate(`${data}`);
|
|
53
|
+
}
|
|
48
54
|
});
|
|
49
55
|
|
|
50
56
|
launch.on('close', code => {
|
|
@@ -111,27 +117,39 @@ export default function launchServices() {
|
|
|
111
117
|
//It may be that it's running, so let's be sure.
|
|
112
118
|
logUpdate('Directus taking a long time to respond...');
|
|
113
119
|
|
|
114
|
-
const check = spawn('docker-compose', ['ps', '--format', 'json']);
|
|
120
|
+
const check = spawn('docker-compose', ['ps', '-a', '--format', 'json']);
|
|
115
121
|
|
|
116
122
|
check.stdout.on('data', (data) => {
|
|
117
123
|
const q = 'map(select(.Name == "directus")) | .[0] | {Name: .Name, Service: .Service, State: .State}';
|
|
118
124
|
jq.run(q, data.toString(), { input: 'string' })
|
|
119
125
|
.then((data) => {
|
|
120
126
|
const json = JSON.parse(data);
|
|
127
|
+
console.log(data);
|
|
121
128
|
|
|
122
129
|
if(json.State == 'running') {
|
|
123
130
|
logUpdate(`${chalk.yellowBright("Directus appears to be running, but took a while to respond.")}`);
|
|
124
131
|
console.log(`Just run ${chalk.greenBright("npm run launch")} to verify, and you should be good to go.`);
|
|
132
|
+
|
|
125
133
|
logUpdate.done();
|
|
126
|
-
process.exit(1);
|
|
127
134
|
} else {
|
|
135
|
+
logUpdate(`${chalk.redBright("Directus taking too long to respond. You may need to manually start it.")}`);
|
|
128
136
|
logUpdate.done();
|
|
129
|
-
console.log(`${chalk.redBright("Directus taking too long to respond. You may need to manually start it.")}`);
|
|
130
137
|
console.log(`Just run ${chalk.greenBright("npm run launch")} and you should be good to go.`);
|
|
131
|
-
process.exit(1);
|
|
132
138
|
}
|
|
133
139
|
});
|
|
134
140
|
});
|
|
141
|
+
|
|
142
|
+
check.on('close', (code) => {
|
|
143
|
+
if (code !== 0) {
|
|
144
|
+
console.log(`${chalk.redBright("Directus taking too long to respond. You may need to manually start it.")}`);
|
|
145
|
+
console.log(`Just run ${chalk.greenBright("npm run launch")} and you should be good to go.`);
|
|
146
|
+
console.log(`You can also check if it is running with ${chalk.greenBright("docker-compose ps")}`);
|
|
147
|
+
} else {
|
|
148
|
+
console.log(`${chalk.yellowBright("Directus appears to be running, but took a while to respond.")}`);
|
|
149
|
+
console.log(`Just run ${chalk.greenBright("npm run launch")} to verify, and you should be good to go.`);
|
|
150
|
+
console.log(`You can also check if it is running with ${chalk.greenBright("docker-compose ps")}`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
135
153
|
});
|
|
136
154
|
});
|
|
137
155
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "directus-mysql-docker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"start": "node ./lib/index.js",
|
|
9
9
|
"launch": "node ./lib/index.js",
|
|
10
10
|
"stop": "docker-compose down",
|
|
11
|
-
"
|
|
11
|
+
"snapshot": "docker-compose exec directus npx directus schema snapshot /directus/snapshots/\"$(date \"+%F\")\"-snapshot-\"$(date \"+%s\")\".yaml",
|
|
12
|
+
"snapshot-apply": "docker-compose exec directus npx directus schema apply /directus/snapshots/$npm_config_snapshot",
|
|
13
|
+
"snapshot-test": "docker-compose exec directus npx directus schema apply --dry-run /directus/snapshots/$npm_config_snapshot"
|
|
12
14
|
},
|
|
13
15
|
"bin": {
|
|
14
16
|
"create-directus-docker": "./lib/index.js",
|