-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.coffee
More file actions
executable file
·98 lines (81 loc) · 1.6 KB
/
Copy pathenv.coffee
File metadata and controls
executable file
·98 lines (81 loc) · 1.6 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env coffee
> path > dirname join
@rmw/thisdir
utax/write
utax/read
fs > existsSync
fs/promises > opendir
nanoid > nanoid
os > cpus
dotenv > parse
ROOT = thisdir(import.meta)
ENV = join(
ROOT
'.env'
)
if existsSync ENV
pre = parse read ENV
else
pre = {}
pg_pwd = nanoid()
host = 'user.tax'
data = {
NODE_ENV: 'production'
PG_HOST:'pg'
PG_DB:host
PG_USER:host
PG_PORT:9997
PG_POOL_CONN:32
PG_SSL: 'false'
PG_PASSWORD:pg_pwd
REDIS_DB:0
REDIS_USER:'default'
REDIS_PASSWORD:nanoid()
REDIS_HOST:'redis'
REDIS_PORT:9998
SMTP_HOST: 'smtp.user.tax'
SMTP_PORT: 465
SMTP_TLS: 1
SMTP_USER: 'smtp_login_account'
SMTP_PASSWORD: 'password'
API_PORT:80
API_HTTPS:443
CPU_NUM:cpus().length
}
txt = []
namespace = ''
for [k,v] from Object.entries data
ns = k[...k.indexOf('_')]
if namespace and ns != namespace
txt.push ''
namespace = ns
txt.push "#{k}=#{pre[k] or v}"
if not 'DEBUG' of pre
txt.push '# DEBUG=1'
await write ENV, txt.join('\n')+'\n'
for await fp from await opendir ROOT
if not fp.isDirectory()
continue
docker = join(ROOT,fp.name,'docker-compose.yml')
if not existsSync docker
continue
li = read(docker).split('\n')
txt = []
state = 0
for i from li
i = i.trimEnd()
t = i.trimStart()
if state == 2
if t.endsWith ':'
state = 3
txt.push i
else
txt.push i
if state == 1
if t == 'environment:'
state = 2
for k from Object.keys data
txt.push " #{k}: ${#{k}}"
else if t=='api:'
state = 1
await write docker, txt.join('\n')