Repository navigation
Expand file tree
/
Copy pathharness-deployment
More file actions
269 lines (242 loc) · 7.4 KB
/
Copy pathharness-deployment
File metadata and controls
269 lines (242 loc) · 7.4 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/usr/bin/env python
import sys
from pathlib import Path
from cloudharness_utils.constants import DEPLOYMENT_PATH
from ch_cli_tools.api import deploy, hosts_info, perform_migration
from ch_cli_tools.model import CHDeployConfig, CHProject
from ch_cli_tools.utils import generation_argv
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(
description="Walk filesystem inside ./applications and define build and deploy scripts."
)
parser.add_argument(
"paths",
metavar="paths",
default=[ROOT],
type=Path,
nargs="*",
help="Base paths to start looking for applications. The paths will be processed "
"in the given order so determining the build and overriding precedence.",
)
parser.add_argument(
"-i",
"--include",
dest="include",
action="append",
default=[],
help="Specify the applications to include and exclude the rest. "
"Omit to build images for all Docker files.",
)
parser.add_argument(
"-t",
"--tag",
dest="tag",
action="store",
default=None,
help="Add a tag with the current version (default no value, content hash is used)",
)
parser.add_argument(
"-n",
"--namespace",
dest="namespace",
action="store",
default=None,
help="Specify the namespace of the deployment (default taken from values.yaml)",
)
parser.add_argument(
"--name",
dest="name",
action="store",
default=None,
help="Specify the helm chart name (default: namespace when provided, otherwise chart default)",
)
parser.add_argument(
"--chart-version",
dest="chart_version",
action="store",
default=None,
help="Specify the helm chart version",
)
parser.add_argument(
"--app-version",
dest="app_version",
action="store",
default=None,
help="Specify the helm chart appVersion",
)
parser.add_argument(
"-r",
"--registry",
dest="registry",
action="store",
default="",
help="Specify image registry prefix",
)
parser.add_argument(
"-rsn",
"-rs",
"--registry-secret-name",
dest="registry_secret_name",
action="store",
default="",
help="Specify image registry secret (-rs is deprecated, use -rsn)",
)
parser.add_argument(
"-o",
"--output",
dest="output_path",
action="store",
default="./deployment",
help="Specify helm chart base path (default `./deployment)`",
)
parser.add_argument(
"-d",
"--domain",
dest="domain",
action="store",
default="cloudharness.metacell.us",
help="Specify a domain different from cloudharness.metacell.us",
)
parser.add_argument(
"-l",
"--local",
dest="local",
action="store_true",
help="Specify for local deployments info and setup",
)
parser.add_argument(
"-u",
"--disable-security",
dest="unsecured",
action="store_true",
help="Disable secured gatekeepers access",
)
parser.add_argument(
"-ex",
"--exclude",
dest="exclude",
action="append",
default=[],
help="Specify application to exclude from the deployment",
)
parser.add_argument(
"-e",
"--env",
dest="env",
action="store",
default="",
help="Specify the name of the environment(s) (will load values-[ENV].yaml files). Specify multiple envs with dashes (e.g env1-env2)",
)
parser.add_argument(
"-dtls",
"--disable-tls",
dest="no_tls",
action="store_true",
help="Disable tls (serve on http)",
)
parser.add_argument(
"--deploy", dest="deploy", action="store_true", help="Deploy helm chart"
)
parser.add_argument(
"-N",
"--no-cd",
dest="no_cd_gen",
action="store_const",
default=None,
const=True,
help=f"Do not generate ci/cd files",
)
parser.add_argument(
"-we",
"--write-env",
dest="write_env",
action="store_const",
default=None,
const=True,
help=f"Write build env to .env file in {DEPLOYMENT_PATH}",
)
parser.add_argument(
"--migrate",
dest="migration",
action="store_true",
help="Perform a migration of the deployment to the latest supported version.",
)
parser.add_argument(
"--migrate-accept-all",
dest="migration_accept_all",
action="store_true",
help="Perform a migration of the deployment to the latest supported version without asking for confirmation. Use with caution.",
)
parser.add_argument(
"--docker-compose",
dest="docker_compose",
action="store_true",
help="Generate docker-compose.yaml and dedicated Skaffold configuration",
)
parser.add_argument(
"-cu",
"--cache-url",
dest="image_cache_url",
action="store",
default="",
help="Specify a custom cache URL for the docker images. This is used to speed up builds by caching layers. Example: https://cache.cloudharness.io?repository=[REGISTRY]/[IMAGE_NAME]&tag=[TAG]",
)
args, unknown = parser.parse_known_args(sys.argv[1:])
root_paths = [Path.cwd() / path for path in args.paths]
envs = args.env.split("-") if args.env else ()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
if unknown:
print(
"There are unknown args. Make sure to call the script with the accepted args. Try --help"
)
print(f"unknown: {unknown}")
sys.exit(2)
if args.migration_accept_all:
perform_migration(root_paths, accept_all=True)
elif args.migration:
perform_migration(root_paths, accept_all=False)
generation_argv.set(sys.argv)
config = CHDeployConfig(
includes=args.include,
excludes=args.exclude,
registry=args.registry,
tag=args.tag,
local=args.local,
namespace=args.namespace,
registry_secret_name=args.registry_secret_name,
output_path=args.output_path,
tls=not args.no_tls,
secured_gatekeepers=not args.unsecured,
domain=args.domain,
env=envs or None,
chart_name=args.name,
chart_version=args.chart_version,
app_version=args.app_version,
)
if args.docker_compose:
config.backend = "compose"
project = CHProject.init(root_paths, config=config)
if args.docker_compose:
project.docker_compose.generate()
else:
project.helm_chart.generate()
helm_values = project.build_final_helm_values()
if not args.no_cd_gen and envs and not args.docker_compose:
project.codefresh.generate()
if args.write_env:
project.codefresh.write_env_file(
root_paths[-1] / DEPLOYMENT_PATH / ".env",
args.image_cache_url,
)
project.skaffold.generate()
project.tilt.generate()
if not args.docker_compose:
project.vscode_debug.generate()
hosts_info(helm_values)
if args.deploy:
deploy(args.namespace, args.output_path)