-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure-script.js
75 lines (64 loc) · 1.75 KB
/
configure-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//setup
const readline = require('readline');
const fs = require('fs');
const crypto = require("crypto");
const uuid = (bytes = 16) => crypto.randomBytes(bytes).toString("hex");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
//manually promisify this (util didn't work)
const question = (prompt, def = null) => {
return new Promise((resolve, reject) => {
rl.question(`${prompt}${def ? ` (${def})` : ''}: `, answer => {
//loop on required
if (def === null && !answer) {
return resolve(question(prompt, def));
}
return resolve(answer || def);
});
});
};
//questions
(async () => {
//app configuration
const appName = await question('App Name');
const webAddr = await question('Web Addr');
//generate the files
const ymlfile = `
version: "3.6"
services:
${appName}:
container_name: ${appName}
build: .
volumes:
- static_volume:/app/public
nginx:
image: nginx
container_name: ${appName}-nginx
restart: always
volumes:
- ./traefik-files:/etc/nginx/conf.d
- static_volume:/static
labels:
- "traefik.enable=true"
- "traefik.http.routers.${appName}router.rule=Host(\`${webAddr}\`)"
- "traefik.http.routers.${appName}router.entrypoints=websecure"
- "traefik.http.routers.${appName}router.tls.certresolver=myresolver"
- "traefik.http.routers.${appName}router.service=${appName}service@docker"
- "traefik.http.services.${appName}service.loadbalancer.server.port=3000"
networks:
- traefik-network
volumes:
static_volume:
driver: local
networks:
traefik-network:
external: true
`;
fs.writeFileSync('docker-compose.yml', ymlfile);
})()
.then(() => rl.close())
.catch(e => console.error(e))
;