forked from tilt-dev/tilt-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tiltfile
94 lines (82 loc) · 4.1 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
# * Load extensions
load('ext://helm_remote', 'helm_remote')
def wait_for(url):
return """while [[ "$(curl -s -o /dev/null -w ''%{{http_code}}'' {})" != "200" ]]; do sleep 5; done""".format(url)
DEFAULT_HASURA_SECRET = 'hasura-dev-secret'
DEFAULT_HASURA_PORT = 8080
DEFAULT_HASURA_RESOURCE_NAME = 'hasura'
def hasura_console(release_name='',
path='.',
hasura_resource_name=None,
hasura_endpoint= 'http://localhost:8080',
hasura_secret=DEFAULT_HASURA_SECRET,
wait_for_services=[]):
# * Wait for Hasura, then run the console locally
# ? fetch admin secret from k8s?
# "--admin-secret `kubectl get secret {} -o jsonpath='{{.data.adminSecret}}' | base64 -D`".format(hasura_resource),
console_options = '--project {} --endpoint {} --admin-secret {}'.format(
path,
hasura_endpoint,
hasura_secret
)
config = read_yaml(os.path.join(path, 'config.yaml'), False)
if not config:
local('mkdir -p {}'.format(os.path.join(path, '..')))
local('hasura init {} --version 3 --endpoint {}'.format(path, hasura_endpoint))
serve_cmds = [
'hasura migrate apply {} --all-databases'.format(console_options),
# test if databases.yaml contains more than '[]\n', meaning a database has been set, therefore hasura config has been loaded
# this test is not perfect but avoids requiring additional tools such as yq to check if the yaml file is something else thant an empty array
'[ $(wc -c <"{}/metadata/databases/databases.yaml") -ge 4 ] && hasura metadata apply {} || hasura metadata export {}'.format(path, console_options, console_options),
'hasura console {}'.format(console_options)
]
hasura_resource = '{}-{}'.format(release_name,
hasura_resource_name) if release_name else hasura_resource_name
console_resource = '{}-hasura-console'.format(
release_name) if release_name else 'hasura-console'
local_resource(console_resource,
'\n'.join([wait_for(x) for x in wait_for_services + ['{}/healthz'.format(hasura_endpoint)]]),
resource_deps=[hasura_resource] if hasura_resource else [],
serve_cmd=' && '.join(["{{ {}; }}".format(cmd) for cmd in serve_cmds]),
allow_parallel=True,
links=[link('http://localhost:9695/', 'Hasura Console')])
def hasura(release_name='',
path='.',
resource_name=DEFAULT_HASURA_RESOURCE_NAME,
port=DEFAULT_HASURA_PORT,
postgres_port=5432,
repository='hasura/graphql-engine',
tag='latest',
hasura_secret=DEFAULT_HASURA_SECRET,
postgresql_password='development-postgres-password',
yaml='',
wait_for_services=[],
console=True
):
# * Expose Hasura service
hasura_resource = '{}-{}'.format(release_name,
resource_name) if release_name else resource_name
k8s_resource(hasura_resource,
port_forwards='8080:{}'.format(port),
links=[link('http://localhost:9695/', 'Hasura Console')])
# * Expose Postgresql service
postgresql_resource = '{}-postgresql'.format(
release_name) if release_name else '{}-postgresql'.format(resource_name)
k8s_resource(postgresql_resource,
port_forwards='5432:{}'.format(postgres_port))
# * Deploy Hasura Helm Chart
if yaml:
k8s_yaml(yaml)
else:
helm_remote('hasura',
repo_name='platyplus',
repo_url='https://charts.platy.plus',
release_name=release_name,
set=['imageConfig.repository={}'.format(repository),
'imageConfig.tag={}'.format(tag),
'adminSecret={}'.format(hasura_secret),
'postgresql.postgresqlPassword={}'.format(postgresql_password),
]
)
if console:
hasura_console(release_name, path, resource_name, 'http://localhost:8080', hasura_secret)