diff --git a/dev/BUCK b/dev/BUCK index d9a3465fc8..fd9471b9b2 100644 --- a/dev/BUCK +++ b/dev/BUCK @@ -103,13 +103,13 @@ sh_binary( ) sh_binary( - name = "add-test-users-with-usernames", - main = "bin/add-test-users-with-usernames.sh", + name = "init-test-users-with-usernames", + main = "bin/init-test-users-with-usernames.sh", ) sh_binary( - name = "fund-user", - main = "bin/fund-user.sh", + name = "init-user-funds", + main = "bin/init-user-funds.sh", ) sh_binary( diff --git a/dev/Tiltfile b/dev/Tiltfile index 440a3defa1..984503536d 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -1,30 +1,3 @@ -config.define_string_list("test") -config.define_bool("bats") -cfg = config.parse() - -CORE_TEST_LABEL = "core" -CONSENT_TEST_LABEL = "consent" -DASHBOARD_TEST_LABEL = "dashboard" -PAY_TEST_LABEL = "pay" -ADMIN_PANEL_TEST_LABEL = "admin-panel" -MAP_TEST_LABEL = "map" -VOUCHER_TEST_LABEL = "voucher" -MIGRATE_MONGO_TEST_LABEL = "mongodb-migrate" - -TEST_RESOURCES = { - CORE_TEST_LABEL: "test-api", - CONSENT_TEST_LABEL: "test-consent", - DASHBOARD_TEST_LABEL: "test-dashboard", - PAY_TEST_LABEL: "test-pay", - ADMIN_PANEL_TEST_LABEL: "test-admin-panel", - MAP_TEST_LABEL: "test-map", - VOUCHER_TEST_LABEL: "test-voucher", - MIGRATE_MONGO_TEST_LABEL: "test-mongodb-migrate", -} - -is_ci=("ci" in sys.argv) or cfg.get("bats", False) -run_apps=not cfg.get("bats", False) - # From the Tilt docs: # # > By default, Tilt will not let you develop against a remote cluster. @@ -38,735 +11,6 @@ run_apps=not cfg.get("bats", False) # - https://docs.tilt.dev/api.html#api.allow_k8s_contexts allow_k8s_contexts(k8s_context()) -def _buck2_dep_inputs(target): - cmd = [ - "buck2", - "uquery", - "\"inputs(deps('{}'))\"".format(target), - ] - abs_file_paths = str(local(" ".join(cmd))).splitlines() - - repo_root = str(local("git rev-parse --show-toplevel")).strip() - rel_file_paths = ["{}/{}".format(repo_root, path) for path in abs_file_paths] - - return rel_file_paths - -def merge_env_file(file_path_str, env_vars={}): - repo_root = str(local("git rev-parse --show-toplevel")).strip() - env_file_path = "{}/{}".format(repo_root, file_path_str) - - file_blob = read_file(env_file_path, "") - lines = str(file_blob).split('\n') - for raw_line in lines: - line_without_comments = raw_line.strip() - if '#' in raw_line: - line_without_comments = raw_line.split('#')[0].strip() - - if line_without_comments == '': - continue - - line = line_without_comments - if line_without_comments.startswith('export '): - line = line_without_comments[len('export '):].strip() - - key_value = line.split('=', 1) - if len(key_value) == 2: - key, value = key_value[0], key_value[1].strip('"') - env_vars[key] = value - - return env_vars - -dashboard_target = "//apps/dashboard:dev" -if is_ci: - dashboard_target = '//apps/dashboard:dashboard' -local_resource( - "dashboard", - labels = ["apps"], - cmd = "buck2 build {}".format(dashboard_target), - serve_cmd = ". .envs/dashboard.env && buck2 run {}".format(dashboard_target), - serve_env = { - "NEXTAUTH_URL": "http://localhost:3001", - "NEXTAUTH_SECRET": "secret", - "PORT": "3001", - }, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/", - port = 3001, - ), - ), - deps = _buck2_dep_inputs(dashboard_target), - allow_parallel = True, - auto_init = run_apps, - resource_deps = [ - "hydra-dashboard", - "api-keys", - "svix", - "svix-pg", - "add-test-users-with-usernames", - "fund-user", - "api", - ], - links = [ - link("http://localhost:3001", "dashboard"), - ], -) - -pay_target = "//apps/pay:dev" -if is_ci: - pay_target = '//apps/pay:pay-ci' -pay_env = { - "PORT": "3002", - "CORE_GQL_URL_INTRANET": "http://localhost:4455/graphql", - "NEXT_PUBLIC_CORE_GQL_URL": "http://localhost:4455/graphql", - "NEXT_PUBLIC_CORE_GQL_WEB_SOCKET_URL": "ws://localhost:4455/graphqlws", - "NEXT_PUBLIC_PAY_DOMAIN": "localhost:3002", - "NEXTAUTH_URL":"http://localhost:3002" -} -local_resource( - "pay", - labels = ["apps"], - cmd = "buck2 build {}".format(pay_target), - serve_cmd = ". .envs/pay.env && buck2 run {}".format(pay_target), - env = pay_env, - serve_env = pay_env, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/", - port = 3002, - ), - ), - deps = _buck2_dep_inputs(pay_target), - allow_parallel = True, - resource_deps = [ - "api", - "api-ws-server", - "hydra-pay" - ], - links = [ - link("http://localhost:3002", "pay"), - ], -) - -admin_panel_target = "//apps/admin-panel:dev" -if is_ci: - admin_panel_target = '//apps/admin-panel:admin-panel' -admin_panel_env = { - "PORT": "3004", - "ADMIN_CORE_API" : "http://localhost:4455/admin/graphql", - "NEXTAUTH_URL" : "http://localhost:3004", - "NEXTAUTH_SECRET" : "nextAuthSecret", -} -local_resource( - "admin-panel", - labels = ["apps"], - cmd = "buck2 build {}".format(admin_panel_target), - serve_cmd = "buck2 run {}".format(admin_panel_target), - env = admin_panel_env, - serve_env = admin_panel_env, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/", - port = 3004, - ), - ), - deps = _buck2_dep_inputs(admin_panel_target), - allow_parallel = True, - resource_deps = [ - "api", - "apollo-router", - ], - links = [ - link("http://localhost:3004", "admin-panel"), - ], -) - -map_target = "//apps/map:dev" -if is_ci: - map_target = '//apps/map:map' -map_env = { - "PORT": "3005", - "CORE_URL" : "http://localhost:4455/graphql", -} -local_resource( - "map", - labels = ["apps"], - cmd = "buck2 build {}".format(map_target), - serve_cmd = "buck2 run {}".format(map_target), - env = map_env, - serve_env = map_env, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/api/health", - port = 3005, - ), - ), - deps = _buck2_dep_inputs(map_target), - allow_parallel = True, - resource_deps = [ - "api", - "apollo-router", - ], - links = [ - link("http://localhost:3005", "map"), - ], -) - -voucher_target = "//apps/voucher:dev" -if is_ci: - voucher_target = '//apps/voucher:voucher' -voucher_env = { - "PORT": "3006", - "NEXTAUTH_URL":"http://localhost:3006", - "NEXTAUTH_SECRET":"secret" -} -local_resource( - "voucher", - labels = ["apps"], - cmd = "buck2 build {}".format(voucher_target), - serve_cmd = ". .envs/voucher.env && buck2 run {}".format(voucher_target), - env = voucher_env, - serve_env = voucher_env, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/", - port = 3006, - ), - ), - deps = _buck2_dep_inputs(voucher_target), - allow_parallel = True, - resource_deps = [ - "api", - "apollo-router", - "hydra-voucher", - "setup-voucher" - ], - links = [ - link("http://localhost:3006", "voucher"), - ], -) - -local_resource( - name='hydra-voucher', - labels = ['apps'], - cmd=[ - 'buck2', - 'run', - '//dev:setup-hydra-client', - '--', - 'voucher', - 'authorization_code,refresh_token', - 'http://localhost:3006/api/auth/callback/blink', - ], - allow_parallel = True, - resource_deps = [ - "hydra", - "api", - ] -) - -local_resource( - name='hydra-dashboard', - labels = ['apps'], - cmd=[ - 'buck2', - 'run', - '//dev:setup-hydra-client', - '--', - 'dashboard', - 'authorization_code,refresh_token', - 'http://localhost:3001/api/auth/callback/blink', - ], - allow_parallel = True, - auto_init = run_apps, - resource_deps = [ - "hydra", - "api", - ] -) - -local_resource( - name='hydra-pay', - labels = ['apps'], - cmd=[ - 'buck2', - 'run', - '//dev:setup-hydra-client', - '--', - 'pay', - 'authorization_code,refresh_token', - 'http://localhost:3002/api/auth/callback/blink', - ], - allow_parallel = True, - resource_deps = [ - "hydra", - "api", - ] -) - -local_resource( - name='hydra-consent-test-client', - labels = ['auth'], - cmd=[ - 'buck2', - 'run', - '//dev:setup-hydra-client', - '--', - 'consent-test', - 'authorization_code,refresh_token', - 'http://localhost:3000', - ], - allow_parallel = True, - auto_init = run_apps, - resource_deps = [ - "hydra", - "api", - ] -) - -consent_test_target = "//apps/consent:test-integration" -local_resource( - "test-consent", - labels = ["test"], - auto_init = is_ci and CONSENT_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(consent_test_target), - allow_parallel = True, - resource_deps = [ - "consent", - "init-test-user", - ], -) - -dashboard_test_target = "//apps/dashboard:test-integration" -local_resource( - "test-dashboard", - labels = ["test"], - auto_init = is_ci and DASHBOARD_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(dashboard_test_target), - resource_deps = [ - "consent", - "dashboard", - "init-test-user", - ], -) - -pay_test_target = "//apps/pay:test-integration" -local_resource( - "test-pay", - labels = ["test"], - auto_init = is_ci and PAY_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(pay_test_target), - resource_deps = [ - "pay", - "add-test-users-with-usernames", - "fund-user", - ], -) - -admin_panel_test_target = "//apps/admin-panel:test-integration" -local_resource( - "test-admin-panel", - labels = ["test"], - auto_init = is_ci and ADMIN_PANEL_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(admin_panel_test_target), - resource_deps = [ - "admin-panel", - ], -) - -voucher_test_target = "//apps/voucher:test-integration" -local_resource( - "test-voucher", - labels = ["test"], - auto_init = is_ci and VOUCHER_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(voucher_test_target), - resource_deps = [ - "voucher", - "consent", - "init-test-user", - "fund-user", - ], -) - - -map_test_target = "//apps/map:test-integration" -local_resource( - "test-map", - labels = ["test"], - auto_init = is_ci and MAP_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(map_test_target), - resource_deps = [ - "map", - ], -) - -local_resource( - name='init-test-user', - labels = ['test'], - cmd='buck2 run //dev:init-test-user', - allow_parallel = True, - resource_deps = [ - "oathkeeper", - "kratos", - "api", - ] -) - -local_resource( - name='add-test-users-with-usernames', - labels = ['test'], - cmd='buck2 run //dev:add-test-users-with-usernames', - allow_parallel = True, - resource_deps = [ - "oathkeeper", - "kratos", - "api", - ] -) - -local_resource( - name='fund-user', - labels = ['test'], - cmd='buck2 run //dev:fund-user', - allow_parallel = True, - resource_deps = [ - "oathkeeper", - "kratos", - "api", - "init-onchain", - "init-test-user", - "api-trigger", - "stablesats", - "price", - ] -) - - -consent_target = "//apps/consent:dev" -if is_ci: - consent_target = '//apps/consent:consent' -local_resource( - "consent", - labels = ["auth"], - cmd = "buck2 build {}".format(consent_target), - serve_cmd = "buck2 run {}".format(consent_target), - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "/", - port = 3000, - ), - ), - deps = _buck2_dep_inputs(consent_target), - allow_parallel = True, - auto_init = run_apps, - resource_deps = [ - "apollo-router", - "hydra", - "api", - "hydra-consent-test-client", - ], - links = [ - link("http://localhost:3000", "consent"), - ], -) - -env_json = _buck2_dep_inputs("//dev:serve_env")[0] -core_serve_env_from_json = read_json(env_json) -local_env_file = ".env.local" -core_serve_env = merge_env_file(local_env_file, core_serve_env_from_json) - -callback_target = "//bats/helpers/callback:run" -local_resource( - "callback", - labels = ["test"], - serve_cmd = "buck2 run {}".format(callback_target), - allow_parallel = True, - deps = _buck2_dep_inputs(callback_target), -) - -api_target = "//core/api:dev" -if is_ci: - api_target = "//core/api:api" -local_resource( - "api", - labels = ["core"], - cmd = "buck2 build {}".format(api_target), - serve_cmd = "buck2 run {}".format(api_target), - serve_env = core_serve_env, - allow_parallel = True, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "healthz", - port = 4012, - ), - ), - deps = _buck2_dep_inputs(api_target), - resource_deps = [ - "price", - "init-onchain", - "init-lightning", - "lnd1", - "lnd2", - "redis", - "mongodb", - "oathkeeper", - "svix", - "notifications", - ] -) - -api_trigger_target = "//core/api-trigger:dev" -if is_ci: - api_trigger_target = "//core/api-trigger:api-trigger" -local_resource( - "api-trigger", - labels = ["core"], - cmd = "buck2 build {}".format(api_trigger_target), - serve_cmd = "buck2 run //dev:stoppable-trigger {}".format(api_trigger_target), - serve_env = core_serve_env, - allow_parallel = True, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "healthz", - port = 8888, - ), - ), - deps = _buck2_dep_inputs(api_trigger_target), - resource_deps = [ - "price", - "init-onchain", - "lnd1", - "lnd2", - "redis", - "mongodb", - "oathkeeper", - ] -) - -api_exporter_target = "//core/api-exporter:dev" -if is_ci: - api_exporter_target = "//core/api-exporter:api-exporter" -local_resource( - "api-exporter", - labels = ["core"], - cmd = "buck2 build {}".format(api_exporter_target), - serve_cmd = "buck2 run {}".format(api_exporter_target), - serve_env = core_serve_env, - allow_parallel = True, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "healthz", - port = 3003, - ), - ), - deps = _buck2_dep_inputs(api_exporter_target), - resource_deps = [ - "price", - "init-onchain", - "lnd1", - "lnd2", - "redis", - "mongodb", - "oathkeeper", - ] -) - -api_ws_server_target = "//core/api-ws-server:dev" -if is_ci: - api_ws_server_target = "//core/api-ws-server:api-ws-server" -local_resource( - "api-ws-server", - labels = ["core"], - cmd = "buck2 build {}".format(api_ws_server_target), - serve_cmd = "buck2 run {}".format(api_ws_server_target), - serve_env = core_serve_env, - allow_parallel = True, - readiness_probe = probe( - period_secs = 5, - http_get = http_get_action( - path = "healthz", - port = 4012, - ), - ), - deps = _buck2_dep_inputs(api_ws_server_target), - resource_deps = [ - "price", - "init-onchain", - "lnd1", - "lnd2", - "redis", - "mongodb", - "oathkeeper", - ] -) - -notifications_target = "//core/notifications:notifications" -local_resource( - "notifications", - labels = ["core"], - cmd = "buck2 build {}".format(notifications_target), - serve_cmd = "buck2 run {}".format(notifications_target), - serve_env = { - "PG_CON": "postgres://user:password@localhost:5433/pg", - "PG_READ_CON": "postgres://user:password@localhost:5433/pg", - "NOTIFICATIONS_CONFIG": "./config/notifications/notifications.yml", - "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", - }, - deps = _buck2_dep_inputs(notifications_target), - resource_deps = [ - "notifications-pg" - ] -) - -local_resource( - name='init-onchain', - labels = ['bitcoin'], - cmd='buck2 run //dev:init-onchain', - allow_parallel = True, - resource_deps = [ - "bitcoind", - "bria", - ] -) - -local_resource( - name='init-lightning', - labels = ['bitcoin'], - cmd='buck2 run //dev:init-lightning', - allow_parallel = True, - resource_deps = [ - "init-onchain", - "lnd1", - "lnd-outside-1", - "lnd-outside-2", - ] -) - -local_resource( - name="setup-voucher", - cmd="buck2 run //dev:setup-voucher-escrow", - allow_parallel=False, - auto_init=run_apps, - resource_deps=["voucher-pg", "api-keys"] -) - -api_keys_target = "//core/api-keys:api-keys" -local_resource( - "api-keys", - labels = ["auth"], - cmd = "buck2 build {}".format(api_keys_target), - serve_cmd = "buck2 run {}".format(api_keys_target), - serve_env = { - "PG_CON": "postgres://user:password@localhost:5431/pg", - "API_KEYS_CONFIG": "../core/api-keys/api-keys.yml", - "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", - }, - deps = _buck2_dep_inputs(api_keys_target), - allow_parallel = True, - resource_deps = [ - "api", - "api-keys-pg" - ] -) - -docker_groups = { - "auth": [ - "api-keys-pg", - "oathkeeper", - "hydra", - "hydra-migrate", - "hydra-pg", - "kratos", - "kratos-pg", - ], - "core": [ - "apollo-router", - "mongodb", - "notifications-pg", - "oathkeeper", - "redis", - "stablesats", - "svix-pg", - "svix", - ], - "bitcoin": [ - "lnd1", - "lnd2", - "bria", - "bria-pg", - "bitcoind", - ], - "integration": [ - "lnd-outside-1", - "lnd-outside-2", - ], - "price": [ - "price", - "price-history", - "price-history-migrate", - "price-history-pg" - ], - "tracing": [ - "otel-agent", - ], -} - -to_run = cfg.get("to-run", []) -if to_run != []: - enabled_resources = [] - for svc in to_run: - enabled_resources.append(svc) - config.set_enabled_resources(enabled_resources) - -to_test = cfg.get("test", []) -if to_test != []: - enabled_resources = [] - for label in to_test: - svc = TEST_RESOURCES.get(label) - if svc: - enabled_resources.append(svc) - config.set_enabled_resources(enabled_resources) - -docker_compose("./docker-compose.deps.yml", project_name = "galoy-dev") - -for service in docker_groups["bitcoin"]: - dc_resource(service, labels = ["bitcoin"]) -for service in docker_groups["tracing"]: - dc_resource(service, labels = ["tracing"]) -for service in docker_groups["core"]: - dc_resource(service, labels = ["core"]) -for service in docker_groups["auth"]: - dc_resource(service, labels = ["auth"]) -for service in docker_groups["price"]: - dc_resource(service, labels = ["price"]) -for service in docker_groups["integration"]: - dc_resource(service, labels = ["integration"]) - -api_test_target = "//core/api:test-integration" -local_resource( - "test-api", - labels = ["test"], - auto_init = is_ci and CORE_TEST_LABEL in cfg.get("test", []), - cmd = "buck2 test {}".format(api_test_target), - resource_deps = [res for sublist in docker_groups.values() for res in sublist] + ["notifications"] -) - -local_resource( - "test-mongodb-migrate", - labels = ["test"], - auto_init = is_ci and MIGRATE_MONGO_TEST_LABEL in cfg.get("test", []), - cmd='buck2 run //core/api:mongodb-migrate', - allow_parallel = True, - resource_deps = [ - "mongodb", - ] -) +include('./tilt/init.tiltfile') +include('./tilt/services.tiltfile') +include('./tilt/tests.tiltfile') diff --git a/dev/bin/init-onchain.sh b/dev/bin/init-onchain.sh index c10cd6eee6..2c84e7b748 100755 --- a/dev/bin/init-onchain.sh +++ b/dev/bin/init-onchain.sh @@ -11,7 +11,7 @@ bitcoin_cli createwallet "outside" || true bitcoin_cli -generate 200 > /dev/null 2>&1 bitcoin_signer_cli createwallet "dev" || true -bitcoin_signer_cli -rpcwallet=dev importdescriptors "$(cat ./config/bitcoind/bitcoind_signer_descriptors.json)" +bitcoin_signer_cli -rpcwallet=dev importdescriptors "$(cat ${DEV_DIR}/config/bitcoind/bitcoind_signer_descriptors.json)" echo "Checking that bria is running..." diff --git a/dev/bin/add-test-users-with-usernames.sh b/dev/bin/init-test-users-with-usernames.sh similarity index 100% rename from dev/bin/add-test-users-with-usernames.sh rename to dev/bin/init-test-users-with-usernames.sh diff --git a/dev/bin/fund-user.sh b/dev/bin/init-user-funds.sh similarity index 100% rename from dev/bin/fund-user.sh rename to dev/bin/init-user-funds.sh diff --git a/dev/bin/tilt-ci.sh b/dev/bin/tilt-ci.sh index ae3b539c6f..97734215e5 100755 --- a/dev/bin/tilt-ci.sh +++ b/dev/bin/tilt-ci.sh @@ -10,7 +10,7 @@ IFS=' ' read -r -a ARGS <<< "$ARGS_STRING" tilt --file "${REPO_ROOT}/dev/Tiltfile" ci -- "${ARGS[@]}" \ | tee "${REPO_ROOT}/dev/.e2e-tilt.log" \ - | grep -- '^\s*test-.* │' + | grep -E -- '^\s*test-.* │|^\s*init-.* │' status=${PIPESTATUS[0]} if [[ $status -eq 0 ]]; then diff --git a/dev/config/notifications/notifications.yml b/dev/config/notifications/notifications.yml index 98f8f49871..21e2d461c4 100644 --- a/dev/config/notifications/notifications.yml +++ b/dev/config/notifications/notifications.yml @@ -1,6 +1,6 @@ app: push_executor: fcm: - google_application_credentials_path: "./config/notifications/fake_service_account.json" + google_application_credentials_path: "../config/notifications/fake_service_account.json" jobs: enabled: true diff --git a/dev/tilt/common.tiltfile b/dev/tilt/common.tiltfile new file mode 100644 index 0000000000..de7cb839d0 --- /dev/null +++ b/dev/tilt/common.tiltfile @@ -0,0 +1,37 @@ +def buck2_dep_inputs(target): + cmd = [ + "buck2", + "uquery", + "\"inputs(deps('{}'))\"".format(target), + ] + abs_file_paths = str(local(" ".join(cmd))).splitlines() + + repo_root = str(local("git rev-parse --show-toplevel")).strip() + rel_file_paths = ["{}/{}".format(repo_root, path) for path in abs_file_paths] + + return rel_file_paths + +def merge_env_file(file_path_str, env_vars={}): + repo_root = str(local("git rev-parse --show-toplevel")).strip() + env_file_path = "{}/{}".format(repo_root, file_path_str) + + file_blob = read_file(env_file_path, "") + lines = str(file_blob).split('\n') + for raw_line in lines: + line_without_comments = raw_line.strip() + if '#' in raw_line: + line_without_comments = raw_line.split('#')[0].strip() + + if line_without_comments == '': + continue + + line = line_without_comments + if line_without_comments.startswith('export '): + line = line_without_comments[len('export '):].strip() + + key_value = line.split('=', 1) + if len(key_value) == 2: + key, value = key_value[0], key_value[1].strip('"') + env_vars[key] = value + + return env_vars diff --git a/dev/tilt/config.tiltfile b/dev/tilt/config.tiltfile new file mode 100644 index 0000000000..e3c26f350f --- /dev/null +++ b/dev/tilt/config.tiltfile @@ -0,0 +1,16 @@ +load('./common.tiltfile', 'buck2_dep_inputs', 'merge_env_file') + +config.define_string_list("test") +config.define_bool("bats") +cfg = config.parse() + +is_ci = ("ci" in sys.argv) or cfg.get("bats", False) + +run_apps = not cfg.get("bats", False) + +tests_to_run = cfg.get("test", []) + +env_json = buck2_dep_inputs("//dev:serve_env")[0] +core_serve_env_from_json = read_json(env_json) +local_env_file = ".env.local" +core_serve_env = merge_env_file(local_env_file, core_serve_env_from_json) diff --git a/dev/tilt/docker.tiltfile b/dev/tilt/docker.tiltfile new file mode 100644 index 0000000000..4c73690c13 --- /dev/null +++ b/dev/tilt/docker.tiltfile @@ -0,0 +1,51 @@ +docker_groups = { + "apps": [ + "voucher-pg", + ], + "auth": [ + "api-keys-pg", + "oathkeeper", + "hydra", + "hydra-migrate", + "hydra-pg", + "kratos", + "kratos-pg", + ], + "core": [ + "apollo-router", + "mongodb", + "notifications-pg", + "oathkeeper", + "redis", + "stablesats", + "svix-pg", + "svix", + ], + "bitcoin": [ + "lnd1", + "lnd2", + "bria", + "bria-pg", + "bitcoind", + "bitcoind-signer", + "fulcrum", + ], + "integration": [ + "lnd-outside-1", + "lnd-outside-2", + ], + "price": [ + "price", + "price-history", + "price-history-migrate", + "price-history-pg" + ], + "tracing": [ + "otel-agent", + ], +} + +docker_compose("../docker-compose.deps.yml", project_name = "galoy-dev") +for (label, services) in docker_groups.items(): + for service in services: + dc_resource(service, labels = [label]) diff --git a/dev/tilt/init.tiltfile b/dev/tilt/init.tiltfile new file mode 100644 index 0000000000..ac5e98d528 --- /dev/null +++ b/dev/tilt/init.tiltfile @@ -0,0 +1,114 @@ +load('./config.tiltfile', 'run_apps') + +local_resource( + name='init-onchain', + labels = ['init'], + cmd='buck2 run //dev:init-onchain', + allow_parallel = True, + resource_deps = [ + "bitcoind", + "bria", + ] +) + +local_resource( + name='init-lightning', + labels = ['init'], + cmd='buck2 run //dev:init-lightning', + allow_parallel = True, + resource_deps = [ + "init-onchain", + "lnd1", + "lnd-outside-1", + "lnd-outside-2", + ] +) + +local_resource( + name='init-test-user', + labels = ['init'], + cmd='buck2 run //dev:init-test-user', + allow_parallel = True, + resource_deps = [ + "oathkeeper", + "kratos", + "api", + ] +) + +local_resource( + name='init-test-users-with-usernames', + labels = ['init'], + cmd='buck2 run //dev:init-test-users-with-usernames', + allow_parallel = True, + resource_deps = [ + "oathkeeper", + "kratos", + "api", + ] +) + +local_resource( + name='init-voucher-hydra-client', + labels = ['init'], + cmd=[ + 'buck2', + 'run', + '//dev:setup-hydra-client', + '--', + 'voucher', + 'authorization_code,refresh_token', + 'http://localhost:3006/api/auth/callback/blink', + ], + allow_parallel = True, + resource_deps = [ + "hydra", + "api", + ] +) + +local_resource( + name='init-consent-hydra-client', + labels = ['init'], + cmd=[ + 'buck2', + 'run', + '//dev:setup-hydra-client', + '--', + 'consent-test', + 'authorization_code,refresh_token', + 'http://localhost:3000', + ], + allow_parallel = True, + auto_init = run_apps, + resource_deps = [ + "hydra", + "api", + ] +) + +local_resource( + name='init-user-funds', + labels = ['init'], + cmd='buck2 run //dev:init-user-funds', + allow_parallel = True, + resource_deps = [ + "oathkeeper", + "kratos", + "api", + "init-onchain", + "init-test-user", + "api-trigger", + "stablesats", + "price", + ] +) + +local_resource( + name="init-voucher-escrow", + labels = ['init'], + cmd="buck2 run //dev:setup-voucher-escrow", + allow_parallel=False, + auto_init=run_apps, + resource_deps=["voucher-pg", "api-keys"] +) diff --git a/dev/tilt/services.tiltfile b/dev/tilt/services.tiltfile new file mode 100644 index 0000000000..4a67323a2b --- /dev/null +++ b/dev/tilt/services.tiltfile @@ -0,0 +1,375 @@ +load('./common.tiltfile', 'buck2_dep_inputs') +load('./config.tiltfile', 'is_ci', 'run_apps', 'core_serve_env') + +dashboard_target = "//apps/dashboard:dev" +if is_ci: + dashboard_target = '//apps/dashboard:dashboard' +local_resource( + "dashboard", + labels = ["apps"], + cmd = "buck2 build {}".format(dashboard_target), + serve_cmd = ". ../.envs/dashboard.env && buck2 run {}".format(dashboard_target), + serve_env = { + "NEXTAUTH_URL": "http://localhost:3001", + "NEXTAUTH_SECRET": "secret", + "PORT": "3001", + }, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/", + port = 3001, + ), + ), + deps = buck2_dep_inputs(dashboard_target), + allow_parallel = True, + auto_init = run_apps, + resource_deps = [ + "hydra-dashboard", + "api-keys", + "svix", + "svix-pg", + "init-test-users-with-usernames", + "init-user-funds", + "api", + ], + links = [ + link("http://localhost:3001", "dashboard"), + ], +) + +local_resource( + name='hydra-dashboard', + labels = ['apps'], + cmd=[ + 'buck2', + 'run', + '//dev:setup-hydra-client', + '--', + 'dashboard', + 'authorization_code,refresh_token', + 'http://localhost:3001/api/auth/callback/blink', + ], + allow_parallel = True, + auto_init = run_apps, + resource_deps = [ + "hydra", + "api", + ] +) + + +pay_target = "//apps/pay:dev" +if is_ci: + pay_target = '//apps/pay:pay-ci' +pay_env = { + "PORT": "3002", + "CORE_GQL_URL_INTRANET": "http://localhost:4455/graphql", + "NEXT_PUBLIC_CORE_GQL_URL": "http://localhost:4455/graphql", + "NEXT_PUBLIC_CORE_GQL_WEB_SOCKET_URL": "ws://localhost:4455/graphqlws", + "NEXT_PUBLIC_PAY_DOMAIN": "localhost:3002", + "NEXTAUTH_URL":"http://localhost:3002" +} +local_resource( + "pay", + labels = ["apps"], + cmd = "buck2 build {}".format(pay_target), + serve_cmd = ". ../.envs/pay.env && buck2 run {}".format(pay_target), + env = pay_env, + serve_env = pay_env, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/", + port = 3002, + ), + ), + deps = buck2_dep_inputs(pay_target), + allow_parallel = True, + resource_deps = [ + "api", + "api-ws-server", + "hydra-pay" + ], + links = [ + link("http://localhost:3002", "pay"), + ], +) + +local_resource( + name='hydra-pay', + labels = ['apps'], + cmd=[ + 'buck2', + 'run', + '//dev:setup-hydra-client', + '--', + 'pay', + 'authorization_code,refresh_token', + 'http://localhost:3002/api/auth/callback/blink', + ], + allow_parallel = True, + resource_deps = [ + "hydra", + "api", + ] +) + + +admin_panel_target = "//apps/admin-panel:dev" +if is_ci: + admin_panel_target = '//apps/admin-panel:admin-panel' +admin_panel_env = { + "PORT": "3004", + "ADMIN_CORE_API" : "http://localhost:4455/admin/graphql", + "NEXTAUTH_URL" : "http://localhost:3004", + "NEXTAUTH_SECRET" : "nextAuthSecret", +} +local_resource( + "admin-panel", + labels = ["apps"], + cmd = "buck2 build {}".format(admin_panel_target), + serve_cmd = "buck2 run {}".format(admin_panel_target), + env = admin_panel_env, + serve_env = admin_panel_env, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/", + port = 3004, + ), + ), + deps = buck2_dep_inputs(admin_panel_target), + allow_parallel = True, + resource_deps = [ + "api", + "apollo-router", + ], + links = [ + link("http://localhost:3004", "admin-panel"), + ], +) + +map_target = "//apps/map:dev" +if is_ci: + map_target = '//apps/map:map' +map_env = { + "PORT": "3005", + "CORE_URL" : "http://localhost:4455/graphql", +} +local_resource( + "map", + labels = ["apps"], + cmd = "buck2 build {}".format(map_target), + serve_cmd = "buck2 run {}".format(map_target), + env = map_env, + serve_env = map_env, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/api/health", + port = 3005, + ), + ), + deps = buck2_dep_inputs(map_target), + allow_parallel = True, + resource_deps = [ + "api", + "apollo-router", + ], + links = [ + link("http://localhost:3005", "map"), + ], +) + +voucher_target = "//apps/voucher:dev" +if is_ci: + voucher_target = '//apps/voucher:voucher' +voucher_env = { + "PORT": "3006", + "NEXTAUTH_URL":"http://localhost:3006", + "NEXTAUTH_SECRET":"secret" +} +local_resource( + "voucher", + labels = ["apps"], + cmd = "buck2 build {}".format(voucher_target), + serve_cmd = ". ../.envs/voucher.env && buck2 run {}".format(voucher_target), + env = voucher_env, + serve_env = voucher_env, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/", + port = 3006, + ), + ), + deps = buck2_dep_inputs(voucher_target), + allow_parallel = True, + resource_deps = [ + "api", + "apollo-router", + "init-voucher-hydra-client", + "init-voucher-escrow" + ], + links = [ + link("http://localhost:3006", "voucher"), + ], +) + +api_target = "//core/api:dev" +if is_ci: + api_target = "//core/api:api" +local_resource( + "api", + labels = ["core"], + cmd = "buck2 build {}".format(api_target), + serve_cmd = "buck2 run {}".format(api_target), + serve_env = core_serve_env, + allow_parallel = True, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "healthz", + port = 4012, + ), + ), + deps = buck2_dep_inputs(api_target), + resource_deps = [ + "price", + "init-onchain", + "init-lightning", + "lnd1", + "lnd2", + "redis", + "mongodb", + "oathkeeper", + "svix", + "notifications", + ] +) + +api_trigger_target = "//core/api-trigger:dev" +if is_ci: + api_trigger_target = "//core/api-trigger:api-trigger" +local_resource( + "api-trigger", + labels = ["core"], + cmd = "buck2 build {}".format(api_trigger_target), + serve_cmd = "buck2 run //dev:stoppable-trigger {}".format(api_trigger_target), + serve_env = core_serve_env, + allow_parallel = True, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "healthz", + port = 8888, + ), + ), + deps = buck2_dep_inputs(api_trigger_target), + resource_deps = [ + "price", + "init-onchain", + "lnd1", + "lnd2", + "redis", + "mongodb", + "oathkeeper", + ] +) + +api_exporter_target = "//core/api-exporter:dev" +if is_ci: + api_exporter_target = "//core/api-exporter:api-exporter" +local_resource( + "api-exporter", + labels = ["core"], + cmd = "buck2 build {}".format(api_exporter_target), + serve_cmd = "buck2 run {}".format(api_exporter_target), + serve_env = core_serve_env, + allow_parallel = True, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "healthz", + port = 3003, + ), + ), + deps = buck2_dep_inputs(api_exporter_target), + resource_deps = [ + "price", + "init-onchain", + "lnd1", + "lnd2", + "redis", + "mongodb", + "oathkeeper", + ] +) + +api_ws_server_target = "//core/api-ws-server:dev" +if is_ci: + api_ws_server_target = "//core/api-ws-server:api-ws-server" +local_resource( + "api-ws-server", + labels = ["core"], + cmd = "buck2 build {}".format(api_ws_server_target), + serve_cmd = "buck2 run {}".format(api_ws_server_target), + serve_env = core_serve_env, + allow_parallel = True, + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "healthz", + port = 4012, + ), + ), + deps = buck2_dep_inputs(api_ws_server_target), + resource_deps = [ + "price", + "init-onchain", + "lnd1", + "lnd2", + "redis", + "mongodb", + "oathkeeper", + ] +) + +api_keys_target = "//core/api-keys:api-keys" +local_resource( + "api-keys", + labels = ["auth"], + cmd = "buck2 build {}".format(api_keys_target), + serve_cmd = "buck2 run {}".format(api_keys_target), + serve_env = { + "PG_CON": "postgres://user:password@localhost:5431/pg", + "API_KEYS_CONFIG": "../../core/api-keys/api-keys.yml", + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", + }, + deps = buck2_dep_inputs(api_keys_target), + allow_parallel = True, + resource_deps = [ + "api", + "api-keys-pg" + ] +) + +notifications_target = "//core/notifications:notifications" +local_resource( + "notifications", + labels = ["core"], + cmd = "buck2 build {}".format(notifications_target), + serve_cmd = "buck2 run {}".format(notifications_target), + serve_env = { + "PG_CON": "postgres://user:password@localhost:5433/pg", + "PG_READ_CON": "postgres://user:password@localhost:5433/pg", + "NOTIFICATIONS_CONFIG": "../config/notifications/notifications.yml", + "OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317", + }, + deps = buck2_dep_inputs(notifications_target), + resource_deps = [ + "notifications-pg" + ] +) + diff --git a/dev/tilt/tests.tiltfile b/dev/tilt/tests.tiltfile new file mode 100644 index 0000000000..f0baa8ee85 --- /dev/null +++ b/dev/tilt/tests.tiltfile @@ -0,0 +1,165 @@ +load('./common.tiltfile', 'buck2_dep_inputs') +load('./config.tiltfile', 'is_ci', 'run_apps', 'tests_to_run') +load('./docker.tiltfile', 'docker_groups') + +CORE_TEST_LABEL = "core" +CONSENT_TEST_LABEL = "consent" +DASHBOARD_TEST_LABEL = "dashboard" +PAY_TEST_LABEL = "pay" +ADMIN_PANEL_TEST_LABEL = "admin-panel" +MAP_TEST_LABEL = "map" +VOUCHER_TEST_LABEL = "voucher" +MIGRATE_MONGO_TEST_LABEL = "mongodb-migrate" + +TEST_RESOURCES = { + CORE_TEST_LABEL: "test-api", + CONSENT_TEST_LABEL: "test-consent", + DASHBOARD_TEST_LABEL: "test-dashboard", + PAY_TEST_LABEL: "test-pay", + ADMIN_PANEL_TEST_LABEL: "test-admin-panel", + MAP_TEST_LABEL: "test-map", + VOUCHER_TEST_LABEL: "test-voucher", + MIGRATE_MONGO_TEST_LABEL: "test-mongodb-migrate", +} + +if tests_to_run != []: + enabled_resources = [] + for label in tests_to_run: + svc = TEST_RESOURCES.get(label) + if svc: + enabled_resources.append(svc) + config.set_enabled_resources(enabled_resources) + +callback_target = "//bats/helpers/callback:run" +local_resource( + "callback", + labels = ["test"], + serve_cmd = "buck2 run {}".format(callback_target), + allow_parallel = True, + deps = buck2_dep_inputs(callback_target), +) + +local_resource( + "test-mongodb-migrate", + labels = ["test"], + auto_init = is_ci and MIGRATE_MONGO_TEST_LABEL in tests_to_run, + cmd='buck2 run //core/api:mongodb-migrate', + allow_parallel = True, + resource_deps = [ + "mongodb", + ] +) + +api_test_target = "//core/api:test-integration" +local_resource( + "test-api", + labels = ["test"], + auto_init = is_ci and CORE_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(api_test_target), + resource_deps = [res for sublist in docker_groups.values() for res in sublist] + ["notifications"] +) + +consent_test_target = "//apps/consent:test-integration" +local_resource( + "test-consent", + labels = ["test"], + auto_init = is_ci and CONSENT_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(consent_test_target), + allow_parallel = True, + resource_deps = [ + "consent", + "init-test-user", + ], +) + +dashboard_test_target = "//apps/dashboard:test-integration" +local_resource( + "test-dashboard", + labels = ["test"], + auto_init = is_ci and DASHBOARD_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(dashboard_test_target), + resource_deps = [ + "consent", + "dashboard", + "init-test-user", + ], +) + +pay_test_target = "//apps/pay:test-integration" +local_resource( + "test-pay", + labels = ["test"], + auto_init = is_ci and PAY_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(pay_test_target), + resource_deps = [ + "pay", + "init-test-users-with-usernames", + "init-user-funds", + ], +) + +admin_panel_test_target = "//apps/admin-panel:test-integration" +local_resource( + "test-admin-panel", + labels = ["test"], + auto_init = is_ci and ADMIN_PANEL_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(admin_panel_test_target), + resource_deps = [ + "admin-panel", + ], +) + +voucher_test_target = "//apps/voucher:test-integration" +local_resource( + "test-voucher", + labels = ["test"], + auto_init = is_ci and VOUCHER_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(voucher_test_target), + resource_deps = [ + "voucher", + "consent", + "init-test-user", + "init-user-funds", + ], +) + +consent_target = "//apps/consent:dev" +if is_ci: + consent_target = '//apps/consent:consent' +local_resource( + "consent", + labels = ["auth"], + cmd = "buck2 build {}".format(consent_target), + serve_cmd = "buck2 run {}".format(consent_target), + readiness_probe = probe( + period_secs = 5, + http_get = http_get_action( + path = "/", + port = 3000, + ), + ), + deps = buck2_dep_inputs(consent_target), + allow_parallel = True, + auto_init = run_apps, + resource_deps = [ + "apollo-router", + "hydra", + "api", + "init-consent-hydra-client", + ], + links = [ + link("http://localhost:3000", "consent"), + ], +) + + +map_test_target = "//apps/map:test-integration" +local_resource( + "test-map", + labels = ["test"], + auto_init = is_ci and MAP_TEST_LABEL in tests_to_run, + cmd = "buck2 test {}".format(map_test_target), + resource_deps = [ + "map", + ], +)