-
Notifications
You must be signed in to change notification settings - Fork 0
/
adx
executable file
·194 lines (169 loc) · 5.97 KB
/
adx
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
#!/usr/bin/env python3
import argparse
import sys
import util
import os
import logging
parser = argparse.ArgumentParser(
description='This script provides a variety of tools for managing the'
' ADX development environment.'
)
subparsers = parser.add_subparsers(
title='Actions',
description='Choose which action to take.',
metavar='action',
dest='action'
)
actions = {}
actions['up'] = actions['dc'] = subparsers.add_parser(
'up',
description="Start docker containers (docker-compose).",
help="Start docker containers (docker-compose)."
)
actions['up'].set_defaults(func=util.up)
actions['stop'] = subparsers.add_parser(
'stop',
description="Stop docker containers (docker-compose).",
help="Stop docker containers (docker-compose)."
)
actions['stop'].set_defaults(func=util.run_docker_compose)
actions['down'] = subparsers.add_parser(
'down',
description="Stop and destroy docker containers (docker-compose).",
help="Stop and destroy docker containers (docker-compose)."
)
actions['down'].set_defaults(func=util.run_docker_compose)
actions['restart'] = subparsers.add_parser(
'restart',
description="Restart docker containers (docker-compose).",
help="Restart docker containers (docker-compose)."
)
actions['restart'].set_defaults(func=util.run_docker_compose)
actions['build'] = subparsers.add_parser(
'build',
description="Restart docker containers (docker-compose).",
help="Restart docker containers (docker-compose)."
)
actions['build'].set_defaults(func=util.run_docker_compose)
actions['logs'] = subparsers.add_parser(
'logs',
description="Open the logs for a service (docker-compose)",
help="Open the logs for a service (docker-compose)"
)
actions['logs'].set_defaults(func=util.run_docker_compose)
actions['dc'] = subparsers.add_parser(
'dc',
description="Run any docker-compose command.",
help='Run any docker-compose command'
)
actions['dc'].set_defaults(func=util.run_docker_compose)
actions['exec'] = subparsers.add_parser(
'exec',
description="Run any docker-compose exec command.",
help='Run any docker-compose exec command.'
)
actions['exec'].set_defaults(func=util.run_docker_compose)
# Docker exec bash
actions['bash'] = subparsers.add_parser(
'bash',
description="Open a bash prompt in the specified container.",
help='Open a bash prompt in the specified container'
)
actions['bash'].set_defaults(func=util.run_docker_compose)
actions['bash'].add_argument('container', metavar='container', type=str,
help='The service name e.g."frontend."')
# Add the setup command arguments
actions['setup'] = subparsers.add_parser(
'setup',
description='Sets up the ADR code base locally',
help='Sets up the ADR codebase locally.',
)
actions['setup'].set_defaults(func=util.setup)
actions['init'] = subparsers.add_parser(
'init',
description="Initializes ADX project",
help="Configures the already existing ADX codebase with already "
"checkout repositories."
)
actions['init'].set_defaults(func=util.init)
# Add the setup command arguments
actions['dbsetup'] = subparsers.add_parser(
'dbsetup',
description='Runs the initial configuration for CKAN plugins. Should be run'
'after the initial Ckan startup',
help='Performs initial CKAN database setup.',
)
actions['dbsetup'].set_defaults(func=util.init_ckan_db)
actions['demodata'] = subparsers.add_parser(
'demodata',
description='Loads demo example data to local ckan for easier development'
'Needs adx dbsetup',
help="Load demo example data to CKAN"
)
actions['demodata'].set_defaults(func=util.load_demo_data)
# Add the setup command arguments
actions['testsetup'] = subparsers.add_parser(
'testsetup',
description='Sets up the db for ckan tests',
help='Performs initial CKAN test database setup.',
)
actions['testsetup'].set_defaults(func=util.reset_test_db)
actions['test'] = subparsers.add_parser(
'test',
description="Test a CKAN extension.",
help='Test a CKAN extension.'
)
actions['test'].set_defaults(func=util.run_tests)
actions['test'].add_argument('extension', metavar='name', type=str,
help='The extension name e.g."validation", "ytp-request"')
actions['test'].add_argument(
'--no-interaction', action='store_const',
help='Removes the -it flag from the docker exec command',
dest="interaction",
default="-it",
const=""
)
parser.add_argument(
"-log",
"--log",
default="warning",
help=(
"Provide logging level. "
"Example --log debug', default='warning'"),
)
levels = {
'critical': logging.CRITICAL,
'error': logging.ERROR,
'warn': logging.WARNING,
'warning': logging.WARNING,
'info': logging.INFO,
'debug': logging.DEBUG
}
if os.path.exists((util.ADX_PATH + "/adx_deploy/deploy_master.bash")):
actions['deploy'] = subparsers.add_parser(
'deploy',
description='Opens up master/development comparisons of all repos in github.',
help='Compare pushed master/development branches and deploy if desired.',
)
actions['deploy'].set_defaults(func=util.deploy_master)
if os.path.exists((util.ADX_PATH + "/adx_deploy/deploy_master.bash")):
actions['deploy'] = subparsers.add_parser(
'deploy',
description='Opens up master/development comparisons of all repos in github.',
help='Compare pushed master/development branches and deploy if desired.',
)
actions['deploy'].set_defaults(func=util.deploy_master)
def main(orig_args):
args, extra_args = parser.parse_known_args(orig_args)
level = levels.get(args.log.lower())
if level is None:
raise ValueError(
f"log level given: {args.log}"
f" -- must be one of: {' | '.join(levels.keys())}")
logging.basicConfig(level=level)
if hasattr(args, 'func'):
args.func(args, extra_args)
else:
parser.print_help()
if __name__ == '__main__':
main(sys.argv[1:])