create-directus-docker 1.3.4 → 1.4.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-directus-docker",
3
3
  "description": "An installer for Dockerized Directus + MySQL + Adminer + GraphiQL with a helper Node app",
4
- "version": "1.3.4",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Dave Kobrenski",
@@ -37,6 +37,10 @@ As an alternative, you can install this package by following these steps. Once y
37
37
 
38
38
  *Note that you'll only have to do these two steps the first time you run this.*
39
39
 
40
+ ### Seeding MySQL data
41
+
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
+
40
44
  ### Starting/stopping with Docker Compose
41
45
 
42
46
  To **stop** your running containers, simply run `docker compose down` in your terminal from within the project directory. All containers will be stopped.
@@ -7,7 +7,7 @@ services:
7
7
  image: mysql:8
8
8
  restart: always
9
9
  healthcheck:
10
- test: ['mysqladmin', 'ping', '--silent']
10
+ test: ['CMD', 'mysqladmin', 'ping', '--silent']
11
11
  interval: 5s
12
12
  timeout: 20s
13
13
  retries: 3
@@ -18,6 +18,7 @@ services:
18
18
  - 3306:3306
19
19
  volumes:
20
20
  - ./mysql:/var/lib/mysql
21
+ - ./init:/docker-entrypoint-initdb.d
21
22
  command: --default-authentication-plugin=mysql_native_password
22
23
  environment:
23
24
  MYSQL_USER: ${MYSQL_USER}
@@ -47,8 +48,9 @@ services:
47
48
  directus:
48
49
  container_name: directus
49
50
  image: directus/directus:latest
51
+ restart: always
50
52
  ports:
51
- - 8055:8055
53
+ - ${DIRECTUS_PORT}:8055
52
54
  volumes:
53
55
  - ./directus/uploads:/directus/uploads
54
56
  networks:
@@ -72,7 +74,7 @@ services:
72
74
  ADMIN_EMAIL: ${ADMIN_EMAIL}
73
75
  ADMIN_PASSWORD: ${ADMIN_PASSWORD}
74
76
  CORS_ENABLED: 'true'
75
- CORS_ORIGIN: '*'
77
+ CORS_ORIGIN: 'true'
76
78
 
77
79
  PUBLIC_URL: ${PUBLIC_URL}
78
80
 
@@ -56,6 +56,12 @@ try {
56
56
  });
57
57
  }
58
58
 
59
+ if (fs.existsSync(path.join(rootPath, 'init')) === false) {
60
+ fs.mkdir(path.join(rootPath, 'init'), () => {
61
+ //console.log(`'init' directory created. If you want to seed your database on first lanch, place your .sql file(s) in this directory BEFORE running services.`);
62
+ });
63
+ }
64
+
59
65
  inquirer.prompt([
60
66
  {
61
67
  name: 'ADMIN_EMAIL',
@@ -103,6 +109,16 @@ try {
103
109
  name: 'MYSQL_ROOT_PASS',
104
110
  message: "Root password:",
105
111
  default: generator.generate({ length: 14, numbers: true, symbols: false })
112
+ },
113
+ {
114
+ name: 'DIRECTUS_DOMAIN',
115
+ message: "Web address to run on. For example, 'https://mydomain.com' Leave as localhost if running in dev environment.",
116
+ default: 'localhost'
117
+ },
118
+ {
119
+ name: 'DIRECTUS_PORT',
120
+ message: "Port to access Directus on:",
121
+ default: '8055'
106
122
  }
107
123
  ]).then(answers => {
108
124
  console.log(chalk.magentaBright("\nWriting to environment file. Be sure to take note of your credentials below, you'll need them shortly!\n"));
@@ -136,13 +152,32 @@ try {
136
152
  writeStream.write("# Set the domain for directus to use:\n");
137
153
  writeStream.write("# eg, https://mydomain.com\n");
138
154
  writeStream.write("# in local dev environments, just leave it set to localhost:port\n");
139
- writeStream.write("PUBLIC_URL=\"http://localhost:8055\"\n");
140
- writeStream.write("API_ENDPOINT=\"http://localhost:8055/graphql\"");
155
+ writeStream.write(`DIRECTUS_DOMAIN="${answers.DIRECTUS_DOMAIN}"\n`);
156
+ writeStream.write(`DIRECTUS_PORT="${answers.DIRECTUS_PORT}"\n`);
157
+
158
+ if(answers.DIRECTUS_DOMAIN === "localhost") {
159
+ if(answers.DIRECTUS_PORT === 80) {
160
+ writeStream.write(`PUBLIC_URL="http://localhost"\n`);
161
+ writeStream.write(`API_ENDPOINT="http://localhost/graphql"`);
162
+ } else {
163
+ writeStream.write(`PUBLIC_URL="http://localhost:${answers.DIRECTUS_PORT}"\n`);
164
+ writeStream.write(`API_ENDPOINT="http://localhost:${answers.DIRECTUS_PORT}/graphql"`);
165
+ }
166
+ } else {
167
+ if(answers.DIRECTUS_PORT === 80) {
168
+ writeStream.write(`PUBLIC_URL="${answers.DIRECTUS_DOMAIN}"\n`);
169
+ writeStream.write(`API_ENDPOINT="${answers.DIRECTUS_DOMAIN}/graphql"`);
170
+ } else {
171
+ writeStream.write(`PUBLIC_URL="${answers.DIRECTUS_DOMAIN}:${answers.DIRECTUS_PORT}"\n`);
172
+ writeStream.write(`API_ENDPOINT="${answers.DIRECTUS_DOMAIN}:${answers.DIRECTUS_PORT}/graphql"`);
173
+ }
174
+ }
141
175
 
142
176
  writeStream.end();
143
177
 
144
- //console.log(chalk.greenBright("\nAll set!"));
145
- console.log("\nYou can always edit the variables that we've just set in the .env file manually.\n");
178
+ console.log("\nYou can always edit the variables that we've just set in the .env file manually.\n\n");
179
+ console.log(chalk.redBright("If you want to seed your database on first launch, place your .sql file(s) in the \"init\" directory BEFORE running services."));
180
+ console.log("");
146
181
 
147
182
  inquirer.prompt([
148
183
  {
@@ -5,9 +5,11 @@ import { spawn } from 'node:child_process';
5
5
  import logUpdate from 'log-update';
6
6
  import open from 'open';
7
7
  import inquirer from 'inquirer';
8
+ import * as dotenv from 'dotenv';
9
+ dotenv.config();
8
10
 
9
11
  export default function launchServices() {
10
- const launch = spawn('docker', ['compose', 'up', 'mysql', '-d']);
12
+ const launch = spawn('docker-compose', ['up', '-d', 'mysql']);
11
13
 
12
14
  const opts = {
13
15
  resources: [
@@ -42,7 +44,7 @@ export default function launchServices() {
42
44
  logUpdate("Building and launching containers:\n");
43
45
  logUpdate.done();
44
46
 
45
- const launch2 = spawn('docker', ['compose', 'up', '-d']);
47
+ const launch2 = spawn('docker-compose', ['up', '-d']);
46
48
 
47
49
  launch2.stderr.on('data', (data) => {
48
50
  logUpdate(`${data}`);
@@ -52,9 +54,15 @@ export default function launchServices() {
52
54
  logUpdate('Done.');
53
55
  logUpdate.done();
54
56
 
57
+ if(process.env.DIRECTUS_DOMAIN === 'localhost') {
58
+ var appURL = 'http://localhost';
59
+ } else {
60
+ var appURL = process.env.DIRECTUS_DOMAIN;
61
+ }
62
+
55
63
  const pingOpts = {
56
64
  resources: [
57
- 'http://localhost:8055'
65
+ `${process.env.PUBLIC_URL}`
58
66
  ],
59
67
  delay: 1000,
60
68
  interval: 300,
@@ -70,10 +78,9 @@ export default function launchServices() {
70
78
  logUpdate.done();
71
79
 
72
80
  console.log(chalk.green("\nAll services should be ready. You can access them at the following URLs:\n"));
73
-
74
- console.log(`Directus CMS: ${chalk.cyan("http://localhost:8055")}`);
75
- console.log(`Adminer: ${chalk.cyan("http://localhost:8080")}`);
76
- console.log(`GraphiQL Playground: ${chalk.cyan("http://localhost:4000/graphql")}`);
81
+ console.log(`Directus CMS: ${chalk.cyan(process.env.PUBLIC_URL)}`);
82
+ console.log(`Adminer: ${chalk.cyan(appURL + ":8080")}`);
83
+ console.log(`GraphiQL Playground: ${chalk.cyan(appURL + ":4000/graphql")}`);
77
84
 
78
85
  console.log(`\n${chalk.redBright("Note: learn how to avoid CORS errors in the GraphiQL Playground when running on localhost:")}`);
79
86
  console.log(`https://github.com/rollmug/directus-mysql-template#cors-problems-on-localhost`)
@@ -91,9 +98,9 @@ export default function launchServices() {
91
98
  }
92
99
  ]).then(answers => {
93
100
  if(answers.open_now === true) {
94
- open('http://localhost:8055');
95
- open('http://localhost:8080');
96
- open('http://localhost:4000/graphql');
101
+ open(process.env.PUBLIC_URL);
102
+ open(`${appURL}:8080`);
103
+ open(`${appURL}:4000/graphql`);
97
104
  } else {
98
105
  process.exit(1);
99
106
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directus-mysql-docker",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
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",