-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjust
executable file
·205 lines (182 loc) · 5.79 KB
/
just
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env -S npm exec --yes --package=zx@latest zx --
const gitRepositories = [
{ git: '[email protected]:epfl-si/lhd.frontend.git', subdir: 'frontend' },
{ git: '[email protected]:epfl-si/lhd.graphql.git', subdir: 'backend' },
{ git: '[email protected]:epfl-si/epfl-elements-react.git', subdir: 'epfl-elements-react' },
];
await parseCmdLineDoThingsAndCleanup();
function help() {
echo(
chalk.blue(`
Usage: just [command]
Commands:
run Clone git repositories, install dependencies, start servers.
clean Stop and remove containers started by keycloak compose.
purge Remove the keycloak_mariadb docker volume used by keycloak.
unclone Remove cloned repositories.
Options:
--help
--version
Examples:
just run OR just
just clean
just purge
just unclone
`)
);
}
function version() {
echo(chalk.blue(`just v0.0.1`));
}
async function unclone() {
for (const { subdir } of gitRepositories) {
let isClean = false;
try {
await $`cd ${subdir}; git status`;
isClean = true;
await $`rm -rf ${subdir}`;
} catch (e) {
if (!isClean) {
throw new Error(`${subdir} is not clean: ${e.stderr}`);
}
}
}
}
async function gitCloneAll() {
for (const toClone of gitRepositories) {
const { subdir, git } = toClone;
if (!(await fs.exists(subdir))) {
await $`git clone ${git} ${subdir}`;
}
}
}
async function gitPullAll() {
await $`git pull --rebase --autostash`;
for (const toClone of gitRepositories) {
const { subdir, git } = toClone;
await $`cd ${subdir}; git pull --rebase --autostash`;
}
}
async function keybase_fs_read(path) {
const p = await $`keybase fs read ${path}`.quiet();
return p.stdout;
}
async function writeBackendDotEnv () {
const lhdTestfile = YAML.parse(
await keybase_fs_read('/keybase/team/epfl_lhd/secrets_test.yml')
);
const lhdTestDbPassword = lhdTestfile.mysql.lhd_app.password;
const lhdImapPassword = lhdTestfile.imap.password;
const lhdEncryptionKey = lhdTestfile.lhd_encryption_key;
const lhdTestAdmDbPassword = lhdTestfile.mysql.lhd_admin.password;
if (! await fs.exists('./backend/.env')) {
await fs.writeFile(
'./backend/.env',
`LHD_DB_URL=mysql://lhd_test_app:${lhdTestDbPassword}@localhost:33006/lhd_test
ALLOWED_GROUPS=lhd_acces_lecture,LHD_acces_admin
LHD_API_PASSWORD=${lhdImapPassword}
LHD_ENCRYPTION_KEY=${lhdEncryptionKey}
API_EPFL_CH_URL=api.epfl.ch
HAZARD_DOCUMENT_FOLDER=hazards/
DOCUMENTS_PATH=../LHD_documents/upload`
);
}
}
async function writeBackendDotEnvForDebug () {
const lhdTestfile = YAML.parse(
await keybase_fs_read('/keybase/team/epfl_lhd/secrets_test.yml')
);
const lhdImapPassword = lhdTestfile.imap.password;
const lhdEncryptionKey = lhdTestfile.lhd_encryption_key;
if (! await fs.exists('./backend/.env')) {
await fs.writeFile(
'./backend/.env',
`LHD_DB_URL=mysql://root:ROOT@localhost:3307/lhd_test
ALLOWED_GROUPS=lhd_acces_lecture,LHD_acces_admin
LHD_API_PASSWORD=${lhdImapPassword}
LHD_ENCRYPTION_KEY=${lhdEncryptionKey}
API_EPFL_CH_URL=api-preprod.epfl.ch
HAZARD_DOCUMENT_FOLDER=hazards/
DOCUMENTS_PATH=../LHD_documents/upload`
);
}
}
async function run() {
await gitCloneAll();
await $`cd keycloak && docker compose up -d`;
await $`cd frontend && yarn`;
await $`cd backend && yarn && yarn codegen`;
await writeBackendDotEnv ();
await $`npx --package concurrently@latest -y concurrently --kill-others-on-fail --names "frontend,backend,keycloak" "cd frontend && yarn start" "cd backend && yarn start" "cd keycloak && docker compose logs -f keycloak"`;
}
async function runFrontend() {
await gitCloneAll();
await $`cd frontend && yarn`;
await $`npx --package concurrently@latest -y concurrently --kill-others-on-fail --names "frontend" "cd frontend && yarn start"`;
}
async function runBackend() {
await gitCloneAll();
await $`cd backend && yarn`;
await writeBackendDotEnv ();
await $`npx --package concurrently@latest -y concurrently --kill-others-on-fail --names "backend" "cd backend && yarn start"`;
}
async function runAuth() {
await gitCloneAll();
await $`cd keycloak && docker compose up -d`;
await $`npx --package concurrently@latest -y concurrently --kill-others-on-fail --names "keycloak" "cd keycloak && docker compose logs -f keycloak"`;
}
async function runDebug() {
await gitCloneAll();
await $`cd keycloak && docker compose up -d`;
await $`cd frontend && yarn`;
await $`cd backend && yarn && yarn codegen`;
await $`cd ../LHD && docker compose up -d db`;
await writeBackendDotEnvForDebug ();
await $`npx --package concurrently@latest -y concurrently --kill-others-on-fail --names "frontend,backend,keycloak" "cd frontend && yarn start" "cd keycloak && docker compose logs -f keycloak"`;
}
async function clean() {
await $`cd keycloak && docker compose down`;
}
async function purge() {
await clean();
await $`docker volume rm keycloak_mariadb`;
}
async function parseCmdLineDoThingsAndCleanup() {
if (!argv._[0]) {
argv._ = ['run'];
}
if (argv.help || argv._[0] === 'help') {
argv._.shift();
help(...argv._);
} else if (argv.version || argv._[0] === 'version') {
argv._.shift();
version(...argv._);
} else if (argv._[0] === 'run') {
argv._.shift();
await run(...argv._);
} else if (argv._[0] === 'frontend') {
argv._.shift();
await runFrontend(...argv._);
} else if (argv._[0] === 'backend') {
argv._.shift();
await runBackend(...argv._);
} else if (argv._[0] === 'auth') {
argv._.shift();
await runAuth(...argv._);
} else if (argv._[0] === 'pull') {
argv._.shift();
await gitPullAll(...argv._);
} else if (argv._[0] === 'debug') {
argv._.shift();
await runDebug(...argv._);
} else if (argv._[0] === 'clean') {
argv._.shift();
await clean(...argv._);
} else if (argv._[0] === 'purge') {
argv._.shift();
await purge(...argv._);
} else if (argv._[0] === 'unclone') {
argv._.shift();
await unclone(...argv._);
}
}