-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·124 lines (95 loc) · 3.17 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
import argparse
import os
import sys
SONARQUBE_COMPOSE_FILE = "docker-compose.sonarqube.yml"
SONARQUBE_SCANNER_COMPOSE_FILE = "docker-compose.sonarqube-scanner.yml"
def run_cmd(cmd):
print(cmd)
os.system(cmd)
def startup_sonar_server():
cmd = "docker-compose -f {} up -d".format(SONARQUBE_COMPOSE_FILE)
print("Starting up containers...")
run_cmd(cmd)
def shutdown_sonar_server():
cmd = "docker-compose -f {} down".format(SONARQUBE_COMPOSE_FILE)
print("Stopping all containers...")
run_cmd(cmd)
def show_docker_logs(container_name):
cmd = "docker logs -f {}".format(container_name)
print("Printing logs for {}...".format(container_name))
run_cmd(cmd)
def run_code_analysis():
cmd = "docker-compose -f {} up".format(SONARQUBE_SCANNER_COMPOSE_FILE)
print("Running code analysis...")
run_cmd(cmd)
def docker_clean_up():
print("Cleaning up docker containers and volumes")
run_cmd("docker system prune")
run_cmd("docker volume prune")
def run_unit_tests():
print("Running unit tests...")
run_cmd("poetry run coverage erase")
run_cmd("poetry run coverage run")
run_cmd("poetry run coverage xml -i")
def sonar_server(command):
ref = {"start": startup_sonar_server, "stop": shutdown_sonar_server}
ref[command]()
def docker(command, container_name):
ref = {"logs": show_docker_logs}
ref[command](container_name)
def sonar_client(skip, clean):
if skip is True:
run_unit_tests()
else:
print("Skipping unit tests...")
if clean is True:
docker_clean_up()
run_code_analysis()
class MyParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write("error: %s\n" % message)
self.print_help()
sys.exit(2)
if __name__ == "__main__":
try:
parser = MyParser()
subparsers = parser.add_subparsers(dest="subparser")
sonar_server_parser = subparsers.add_parser("sonar_server")
sonar_server_parser.add_argument(
dest="command",
default="start",
nargs="?",
help="The name of the command to run",
)
sonar_client_parser = subparsers.add_parser("sonar_client")
sonar_client_parser.add_argument(
"-s",
"--skip-tests",
dest="skip",
action="store_false",
help="Skip unit tests",
)
sonar_client_parser.add_argument(
"-s",
"--clean-up",
dest="clean",
action="store_true",
help="Cleanup all docker containers and volumes",
)
docker_parser = subparsers.add_parser("docker")
docker_parser.add_argument(
dest="command", nargs="?", default="logs", help="Name of the command"
)
docker_parser.add_argument(
"-n",
"--container-name",
dest="container_name",
default="devinstaller_sonarqube_1",
help="Name of the container",
)
kwargs = vars(parser.parse_args())
globals()[kwargs.pop("subparser")](**kwargs)
except Exception:
parser.print_help()
sys.exit(2)