-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tiltfile
112 lines (91 loc) · 3.68 KB
/
Tiltfile
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
# constants
FRONTEND_SERVICE_NAME='frontend'
CARTSERVICE_SERVICE_NAME='cartservice'
PRODUCTCATALOG_SERVICE_NAME='productcatalogservice'
METRICS_SERVICE_NAME='metrics'
DEV_IMAGE_SUFFIX='-dev-image'
FRONTEND_REF=FRONTEND_SERVICE_NAME + DEV_IMAGE_SUFFIX
CARTSERVICE_REF=CARTSERVICE_SERVICE_NAME + DEV_IMAGE_SUFFIX
PRODUCTCATALOG_REF=PRODUCTCATALOG_SERVICE_NAME + DEV_IMAGE_SUFFIX
METRICS_REF=METRICS_SERVICE_NAME + DEV_IMAGE_SUFFIX
# enforces a minimum Tilt version
version_settings(constraint='>=0.22.2')
# check if Kardinal is installed
load('./dev/require-tool', 'require_tool')
require_tool('kardinal', 'Kardinal CLI is not installed, visit https://github.com/kurtosis-tech/kardinal#installation to install it')
# define and get the arguments
config.define_string_list('build')
arguments = config.parse()
# get the 'build' argument
build_arg = []
if 'build' in arguments:
build_arg = arguments['build']
build_arg_len = len(build_arg)
# validate the 'build' argument
valid_build_arguments = [FRONTEND_SERVICE_NAME, CARTSERVICE_SERVICE_NAME, PRODUCTCATALOG_SERVICE_NAME, METRICS_SERVICE_NAME]
for bu_arg in build_arg:
if bu_arg not in valid_build_arguments:
fail('build argument {} is not valid. Valid arguments are: {}'.format(bu_arg, valid_build_arguments))
# enforces to use this Tilt with Minikube or Docker desktop contexts to avoid deploying this stuff in cloud servers
allow_k8s_contexts(['minikube', 'docker-desktop'])
if k8s_context() == 'minikube':
#This allows Tilt to build and push images directly to Minikube's Docker daemon
print('Building container images with Minikube')
local('eval $(minikube docker-env)')
# set the env var to use the local Kontrol
os.environ["KARDINAL_CLI_DEV_MODE"] = "TRUE"
# clean current flows before creating new ones, it's just for the tilt up cmd
if config.tilt_subcommand == 'up':
local(['kardinal', 'flow', 'delete', '', '--all'])
# executing kardinal deploy
local(['kardinal', 'deploy', '-k', './release/obd-kardinal.yaml'])
if build_arg_len > 0:
# execute the kardinal flow create for the services we want to build
cmd_list = ['kardinal', 'flow', 'create']
for index, value in enumerate(build_arg):
service_name = value
service_image = value + DEV_IMAGE_SUFFIX
if index == 0:
cmd_list.extend([service_name, service_image])
else:
cmd_list.append('-s')
add_sv_flag = '{}={}'.format(service_name, service_image)
cmd_list.append(add_sv_flag)
# now execute the create flow command
local(cmd_list)
# CART SERVICE
if 'cartservice' in build_arg:
docker_build(
CARTSERVICE_REF,
context='./src',
dockerfile='./src/cartservice.dockerfile',
)
# PRODUCT CATALOG SERVICE
if 'productcatalogservice' in build_arg:
docker_build(
PRODUCTCATALOG_REF,
context='./src',
dockerfile='./src/productcatalogservice.dockerfile',
)
# FRONTEND
if 'frontend' in build_arg:
docker_build(
FRONTEND_REF,
context='./src',
dockerfile='./src/frontend.dockerfile',
)
# METRICS
if 'metrics' in build_arg:
docker_build(
METRICS_REF,
context='./src',
dockerfile='./src/metrics.dockerfile',
)
kardinal_topology_yaml = local(['kardinal', 'topology', 'print-manifest', '--add-trace-router'], quiet=True)
kardinal_topology_yaml_str = str(kardinal_topology_yaml)
if kardinal_topology_yaml_str != '':
k8s_yaml(kardinal_topology_yaml, allow_duplicates = True)
local_resource(
name='ingress-gateway-port-forward',
serve_cmd=['kubectl', 'port-forward', 'service/istio-ingressgateway', '80:80', '-n', 'istio-system']
)