-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from zapier/tilt-ngrok-fix
Copy improved ngrok setup from kubechecks
- Loading branch information
Showing
8 changed files
with
54 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,5 @@ build/ | |
.env | ||
|
||
go.work | ||
go.work.sum | ||
go.work.sum | ||
ngrok.url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,38 @@ | ||
load('ext://secret', 'secret_from_dict') | ||
|
||
# ///////////////////////////////////////////////////////////////////////////// | ||
# N G R O K | ||
# ///////////////////////////////////////////////////////////////////////////// | ||
|
||
def get_ngrok_url(): | ||
if config.tilt_subcommand == 'down': | ||
check_cmd='/usr/bin/curl -v http://localhost:4040/api/tunnels | jq --raw-output ".tunnels[0].public_url"' | ||
|
||
def get_ngrok_url(cfg): | ||
if cfg.get("ngrok_fqdn"): | ||
return "https://"+cfg.get("ngrok_fqdn") | ||
|
||
elif config.tilt_subcommand == 'down': | ||
local('rm ngrok.url || true') | ||
return 'http://xyz.ngrok.io' | ||
|
||
else: | ||
return str(local( | ||
'curl -s http://localhost:4040/api/tunnels \ | ||
| jq --raw-output ".tunnels[0].public_url"'.format( | ||
k8s_namespace, | ||
k8s_context | ||
), | ||
)).rstrip('\n') | ||
|
||
# Read Auth token for ngrok (assumes ngrok has been installed and configured) | ||
ngrok_config_file = str(local('ngrok config check', quiet=True)).lstrip('Valid configuration file at ').rstrip('\n') | ||
ngrok_config = read_yaml(ngrok_config_file) | ||
k8s_yaml( | ||
secret_from_dict("ngrok-config", inputs = { | ||
'NGROK_AUTHTOKEN' : ngrok_config['authtoken'], | ||
}) | ||
) | ||
k8s_resource( | ||
objects=['ngrok-config:secret'], | ||
labels=["ngrok"], | ||
new_name='ngrok-config', | ||
resource_deps=['k8s:namespace'] | ||
) | ||
|
||
# Deploy ngrok proxy | ||
k8s_yaml( | ||
kustomize('./') | ||
) | ||
k8s_resource( | ||
'ngrok', | ||
resource_deps=['ngrok-config', 'k8s:namespace'], | ||
labels=["ngrok"], | ||
port_forwards=4040, | ||
) | ||
k8s_resource( | ||
'wait-ngrok-url', | ||
resource_deps=['k8s:namespace', 'ngrok'], | ||
labels=["ngrok"] | ||
) | ||
url=str(read_file('ngrok.url', "")).rstrip('\n') | ||
|
||
return url | ||
|
||
def deploy_ngrok(cfg): | ||
|
||
hostnameArg = "" | ||
if cfg.get("ngrok_fqdn"): | ||
hostnameArg = " --hostname {}".format(cfg.get("ngrok_fqdn")) | ||
|
||
local_resource( | ||
"ngrok", | ||
serve_cmd="ngrok http localhost:8080 {}".format(hostnameArg), | ||
readiness_probe=probe( | ||
initial_delay_secs=5, | ||
period_secs=10, | ||
exec=exec_action(["bash", "-c", 'localdev/ngrok/update-url.sh']) | ||
), | ||
labels=["ngrok"], | ||
links=["http://localhost:4040"] | ||
) | ||
|
||
watch_file('./ngrok.url') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
url=$(curl -s http://localhost:4040/api/tunnels | jq --raw-output ".tunnels[0].public_url") | ||
|
||
if grep -q $url ngrok.url; then | ||
echo "URL already set" | ||
else | ||
echo "Updating ngrok.url" | ||
echo -n $url > ngrok.url | ||
fi |