-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstarter.py
58 lines (34 loc) · 1.52 KB
/
starter.py
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
import argparse
import os
import uuid
def generate_env(username, password):
env = []
compose_location = os.path.join(os.getcwd(), 'services/docker-compose.yml')
env.append(f'ADMIN_USERNAME={username}')
env.append(f'ADMIN_PASSWORD={password}')
env.append(f'COMPOSE_LOCATION={compose_location}')
credentials = [f'PASSWORD_{(i * 1000) + 10000}={uuid.uuid4().hex}' for i in range(20)]
env.extend(credentials)
return '\n'.join(env)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--username', type=str, default='admin')
parser.add_argument('-p', '--password', type=str, default='admin')
parser.add_argument('-c', '--challenges', type=str, default='', help='challenge names')
args = parser.parse_args()
cwd = os.getcwd()
env = generate_env(args.username, args.password)
receiver_env = os.path.join(cwd, 'receiver/.env')
services_env = os.path.join(cwd, 'services/.env')
with open(receiver_env, 'w') as f:
f.write(env)
with open(services_env, 'w') as f:
f.write(env)
os.chdir(os.path.join(cwd, 'services'))
os.system(f'docker compose -f docker-compose.yml up --build -d {args.challenges}')
os.chdir(os.path.join(cwd, 'receiver'))
os.system('apt-get install -y gcc python3-dev libgmp3-dev libssl-dev libffi-dev build-essential')
os.system('python3 -m pip install -r requirements.txt')
os.system('uvicorn main:app --reload --host 0.0.0.0 --port 80')
if __name__ == '__main__':
main()