2023-12-15 09:58:25 +01:00
|
|
|
load('ext://uibutton', 'cmd_button', 'location', 'text_input', 'bool_input')
|
2023-09-28 11:57:49 +08:00
|
|
|
running_under_parent_tiltfile = os.getenv("TILT_PARENT", "false") == "true"
|
2023-09-07 05:38:19 -06:00
|
|
|
# The user/pass that you will login to Grafana with
|
2023-09-28 11:57:49 +08:00
|
|
|
grafana_admin_user_pass = os.getenv("GRAFANA_ADMIN_USER_PASS", "oncall")
|
2024-04-25 08:25:59 +02:00
|
|
|
grafana_version = os.getenv("GRAFANA_VERSION", "latest")
|
2024-03-22 13:29:22 +01:00
|
|
|
e2e_tests_cmd=os.getenv("E2E_TESTS_CMD", "cd grafana-plugin && yarn test:e2e")
|
|
|
|
|
twilio_values=[
|
|
|
|
|
"oncall.twilio.accountSid=" + os.getenv("TWILIO_ACCOUNT_SID", ""),
|
|
|
|
|
"oncall.twilio.authToken=" + os.getenv("TWILIO_AUTH_TOKEN", ""),
|
|
|
|
|
"oncall.twilio.phoneNumber=" + os.getenv("TWILIO_PHONE_NUMBER", ""),
|
|
|
|
|
"oncall.twilio.verifySid=" + os.getenv("TWILIO_VERIFY_SID", ""),
|
|
|
|
|
]
|
|
|
|
|
is_ci=config.tilt_subcommand == "ci"
|
2023-09-07 05:38:19 -06:00
|
|
|
# HELM_PREFIX must be "oncall-dev" as it is hardcoded in dev/helm-local.yml
|
2023-09-28 11:57:49 +08:00
|
|
|
HELM_PREFIX = "oncall-dev"
|
2023-09-07 05:38:19 -06:00
|
|
|
# Use docker registery generated by ctlptl (dev/kind-config.yaml)
|
2023-09-28 11:57:49 +08:00
|
|
|
DOCKER_REGISTRY = "localhost:63628/"
|
2023-09-07 05:38:19 -06:00
|
|
|
|
|
|
|
|
if not running_under_parent_tiltfile:
|
|
|
|
|
# Load the custom Grafana extensions
|
2023-09-28 11:57:49 +08:00
|
|
|
v1alpha1.extension_repo(
|
|
|
|
|
name="grafana-tilt-extensions",
|
2024-01-12 16:45:24 +01:00
|
|
|
ref="v1.2.0",
|
2023-09-28 11:57:49 +08:00
|
|
|
url="https://github.com/grafana/tilt-extensions",
|
|
|
|
|
)
|
|
|
|
|
v1alpha1.extension(
|
|
|
|
|
name="grafana", repo_name="grafana-tilt-extensions", repo_path="grafana"
|
|
|
|
|
)
|
2023-09-07 05:38:19 -06:00
|
|
|
|
2023-09-28 11:57:49 +08:00
|
|
|
load("ext://grafana", "grafana")
|
|
|
|
|
load("ext://configmap", "configmap_create")
|
|
|
|
|
load("ext://docker_build_sub", "docker_build_sub")
|
2023-09-07 05:38:19 -06:00
|
|
|
|
|
|
|
|
# Tell ops-devenv/Tiltifle where our plugin.json file lives
|
2023-09-28 11:57:49 +08:00
|
|
|
plugin_file = os.path.abspath("grafana-plugin/src/plugin.json")
|
|
|
|
|
|
|
|
|
|
|
2023-09-07 05:38:19 -06:00
|
|
|
def plugin_json():
|
|
|
|
|
return plugin_file
|
|
|
|
|
|
2023-09-28 11:57:49 +08:00
|
|
|
|
2023-09-07 05:38:19 -06:00
|
|
|
allow_k8s_contexts(["kind-kind"])
|
|
|
|
|
|
2023-09-28 11:57:49 +08:00
|
|
|
# Build the image including frontend folder for pytest
|
|
|
|
|
docker_build_sub(
|
|
|
|
|
"localhost:63628/oncall/engine:dev",
|
|
|
|
|
context="./engine",
|
2023-12-12 06:30:48 +08:00
|
|
|
cache_from=["grafana/oncall:latest", "grafana/oncall:dev"],
|
2024-07-08 12:02:04 +08:00
|
|
|
ignore=["./test-results/", "./grafana-plugin/dist/", "./grafana-plugin/e2e-tests/", "./grafana-plugin/node_modules/"],
|
2023-09-28 11:57:49 +08:00
|
|
|
child_context=".",
|
|
|
|
|
target="dev",
|
|
|
|
|
extra_cmds=["ADD ./grafana-plugin/src/plugin.json /etc/grafana-plugin/src/plugin.json"],
|
|
|
|
|
live_update=[
|
|
|
|
|
sync("./engine/", "/etc/app"),
|
|
|
|
|
run(
|
2024-02-20 14:44:15 -03:00
|
|
|
"cd /etc/app && pip install pip-tools && pip-sync",
|
2023-09-28 11:57:49 +08:00
|
|
|
trigger="./engine/requirements.txt",
|
|
|
|
|
),
|
|
|
|
|
],
|
2023-09-07 05:38:19 -06:00
|
|
|
)
|
|
|
|
|
|
2024-05-06 07:02:32 +02:00
|
|
|
# On CI dependencies are installed separately so we just build prod bundle to be consumed by Grafana dev server
|
|
|
|
|
if is_ci:
|
|
|
|
|
local_resource(
|
|
|
|
|
"build-ui",
|
|
|
|
|
labels=["OnCallUI"],
|
|
|
|
|
dir="grafana-plugin",
|
|
|
|
|
cmd="yarn build",
|
|
|
|
|
allow_parallel=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Locally we install dependencies and we run watch mode
|
|
|
|
|
if not is_ci:
|
|
|
|
|
local_resource(
|
|
|
|
|
"build-ui",
|
|
|
|
|
labels=["OnCallUI"],
|
|
|
|
|
dir="grafana-plugin",
|
|
|
|
|
cmd="yarn install",
|
|
|
|
|
serve_dir="grafana-plugin",
|
|
|
|
|
serve_cmd="yarn watch",
|
|
|
|
|
allow_parallel=True,
|
|
|
|
|
)
|
2023-09-07 05:38:19 -06:00
|
|
|
|
2023-12-15 09:58:25 +01:00
|
|
|
local_resource(
|
|
|
|
|
"e2e-tests",
|
|
|
|
|
labels=["E2eTests"],
|
2024-03-22 13:29:22 +01:00
|
|
|
cmd=e2e_tests_cmd,
|
2023-12-15 09:58:25 +01:00
|
|
|
trigger_mode=TRIGGER_MODE_MANUAL,
|
2024-03-22 13:29:22 +01:00
|
|
|
auto_init=is_ci,
|
|
|
|
|
resource_deps=["build-ui", "grafana", "grafana-oncall-app-provisioning-configmap", "engine", "celery"]
|
2023-12-15 09:58:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd_button(
|
|
|
|
|
name="E2E Tests - headless run",
|
2024-02-01 13:30:57 +01:00
|
|
|
argv=["sh", "-c", "yarn --cwd ./grafana-plugin test:e2e $STOP_ON_FIRST_FAILURE $TESTS_FILTER"],
|
2023-12-15 09:58:25 +01:00
|
|
|
text="Restart headless run",
|
|
|
|
|
resource="e2e-tests",
|
|
|
|
|
icon_name="replay",
|
|
|
|
|
inputs=[
|
2024-02-01 13:30:57 +01:00
|
|
|
text_input("BROWSERS", "Browsers (e.g. \"chromium,firefox,webkit\")", "chromium", "chromium,firefox,webkit"),
|
|
|
|
|
text_input("TESTS_FILTER", "Test filter (e.g. \"timezones.test quality.test\")", "", "Test file names to run"),
|
2023-12-15 09:58:25 +01:00
|
|
|
bool_input("STOP_ON_FIRST_FAILURE", "Stop on first failure", True, "-x", ""),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd_button(
|
|
|
|
|
name="E2E Tests - open watch mode",
|
|
|
|
|
argv=["sh", "-c", "yarn --cwd grafana-plugin test:e2e:watch"],
|
|
|
|
|
text="Open watch mode",
|
|
|
|
|
resource="e2e-tests",
|
|
|
|
|
icon_name="visibility",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd_button(
|
|
|
|
|
name="E2E Tests - show report",
|
|
|
|
|
argv=["sh", "-c", "yarn --cwd grafana-plugin playwright show-report"],
|
|
|
|
|
text="Show last HTML report",
|
|
|
|
|
resource="e2e-tests",
|
|
|
|
|
icon_name="assignment",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cmd_button(
|
|
|
|
|
name="E2E Tests - stop current run",
|
|
|
|
|
argv=["sh", "-c", "kill -9 $(pgrep -f test:e2e)"],
|
|
|
|
|
text="Stop",
|
|
|
|
|
resource="e2e-tests",
|
|
|
|
|
icon_name="dangerous",
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-25 08:25:59 +02:00
|
|
|
helm_oncall_values = ["./dev/helm-local.yml", "./dev/helm-local.dev.yml"]
|
|
|
|
|
if is_ci:
|
|
|
|
|
helm_oncall_values = helm_oncall_values + ["./.github/helm-ci.yml"]
|
|
|
|
|
yaml = helm("helm/oncall", name=HELM_PREFIX, values=helm_oncall_values, set=twilio_values)
|
2023-09-07 05:38:19 -06:00
|
|
|
|
|
|
|
|
k8s_yaml(yaml)
|
|
|
|
|
|
|
|
|
|
# Generate and load the grafana deploy yaml
|
2023-09-28 11:57:49 +08:00
|
|
|
configmap_create(
|
|
|
|
|
"grafana-oncall-app-provisioning",
|
|
|
|
|
namespace="default",
|
|
|
|
|
from_file="dev/grafana/provisioning/plugins/grafana-oncall-app-provisioning.yaml",
|
|
|
|
|
)
|
2023-09-07 05:38:19 -06:00
|
|
|
|
2023-09-28 11:57:49 +08:00
|
|
|
k8s_resource(
|
|
|
|
|
objects=["grafana-oncall-app-provisioning:configmap"],
|
|
|
|
|
new_name="grafana-oncall-app-provisioning-configmap",
|
2024-05-06 07:02:32 +02:00
|
|
|
resource_deps=["build-ui"],
|
2023-09-28 11:57:49 +08:00
|
|
|
labels=["Grafana"],
|
|
|
|
|
)
|
2023-09-07 05:38:19 -06:00
|
|
|
|
|
|
|
|
# Use separate grafana helm chart
|
|
|
|
|
if not running_under_parent_tiltfile:
|
2023-09-28 11:57:49 +08:00
|
|
|
grafana(
|
2024-04-25 08:25:59 +02:00
|
|
|
grafana_version=grafana_version,
|
2023-09-28 11:57:49 +08:00
|
|
|
context="grafana-plugin",
|
|
|
|
|
plugin_files=["grafana-plugin/src/plugin.json"],
|
|
|
|
|
namespace="default",
|
2024-05-06 07:02:32 +02:00
|
|
|
deps=["grafana-oncall-app-provisioning-configmap", "build-ui"],
|
2023-09-28 11:57:49 +08:00
|
|
|
extra_env={
|
|
|
|
|
"GF_SECURITY_ADMIN_PASSWORD": "oncall",
|
|
|
|
|
"GF_SECURITY_ADMIN_USER": "oncall",
|
|
|
|
|
"GF_AUTH_ANONYMOUS_ENABLED": "false",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
k8s_resource(
|
|
|
|
|
workload="celery",
|
|
|
|
|
resource_deps=["mariadb", "redis-master"],
|
|
|
|
|
labels=["OnCallBackend"],
|
|
|
|
|
)
|
|
|
|
|
k8s_resource(
|
|
|
|
|
workload="engine",
|
|
|
|
|
port_forwards=8080,
|
|
|
|
|
resource_deps=["mariadb", "redis-master"],
|
|
|
|
|
labels=["OnCallBackend"],
|
|
|
|
|
)
|
|
|
|
|
k8s_resource(workload="redis-master", labels=["OnCallDeps"])
|
2023-12-11 10:20:01 -05:00
|
|
|
k8s_resource(
|
|
|
|
|
workload="mariadb",
|
|
|
|
|
port_forwards='3307:3306', # <host_port>:<container_port>
|
|
|
|
|
labels=["OnCallDeps"],
|
|
|
|
|
)
|
2023-09-28 11:57:49 +08:00
|
|
|
|
2023-09-07 05:38:19 -06:00
|
|
|
|
|
|
|
|
# name all tilt resources after the k8s object namespace + name
|
|
|
|
|
def resource_name(id):
|
2023-09-28 11:57:49 +08:00
|
|
|
return id.name.replace(HELM_PREFIX + "-", "")
|
|
|
|
|
|
2023-09-07 05:38:19 -06:00
|
|
|
workload_to_resource_function(resource_name)
|