-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrun
executable file
·100 lines (75 loc) · 2.19 KB
/
run
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
#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This script is designed to alias common docker-compose commands used for
# running tests, development, etc. Any complicated processing should
# be done inside the container in a proper command line application
# rather than this script.
import getpass
import grp
import os
import pwd
import sys
from typing import (
Tuple,
)
ENV_FILE_TEMPLATE = """
UID={uid}
GID={gid}
DOCKER_GID={docker_gid}
""".strip()
def get_user_uid_gid(user: str) -> Tuple[int, int]:
"""Get the uid and gid for the specified user."""
try:
pw_entry = pwd.getpwnam(user)
return pw_entry.pw_uid, pw_entry.pw_gid
except KeyError:
sys.exit(f"Couldn't find user `{user}`")
def get_gid(group: str) -> int:
"""Get the gid for the specified group."""
try:
return grp.getgrnam(group).gr_gid
except KeyError:
sys.exit(f"Couldn't find group `{group}`")
def env_cmd():
user = getpass.getuser()
uid, gid = get_user_uid_gid(user)
docker_gid = get_gid("docker")
env_content = ENV_FILE_TEMPLATE.format(
uid=uid,
gid=gid,
docker_gid=docker_gid,
)
print(env_content)
return 0
COMMANDS = {
"build": ("docker", "compose", "build"),
"env": env_cmd,
"hgmo": (
"docker",
"compose",
"run",
"-e",
"TESTNAME=test",
"test-runner",
"/app/vct/hgmo",
),
"shell": ("docker", "compose", "run", "--rm", "test-runner", "/bin/bash"),
"tests": ("docker", "compose", "run", "--rm", "test-runner", "/app/vct/run-tests"),
}
def main(args):
if not args or args[0] not in COMMANDS:
print("./run [command]\n")
print("Possible Commands:")
for cmd in COMMANDS:
print(f"\t{cmd}")
return 1
cmd = COMMANDS[args[0]]
if callable(cmd):
return cmd()
cmd = list(cmd) + args[1:]
print("$ {}".format(" ".join(cmd)))
os.execvp(cmd[0], cmd)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))