@@ -56,8 +56,7 @@ localnet_config_defaults = {
5656 "enabled" : True ,
5757 },
5858
59- # TODO_CONSIDERATION: Consider using git submodules for all repos where we
60- # are dependent on a sibling directory.
59+ # NOTE: git submodule usage was explicityly avoided to reduce environment complexity.
6160
6261 # By default, we use the `helm_repo` function below to point to the remote repository
6362 # but can update it to the locally cloned repo for testing & development
@@ -398,115 +397,12 @@ if localnet_config["rest"]["enabled"]:
398397 k8s_resource ("rest" , labels = ["data_nodes" ], port_forwards = ["10000" ])
399398
400399### Pocketdex Shannon Indexer
401- pocketdex_root_path = localnet_config ["indexer" ]["repo_path" ]
402- pocketdex_tilt_path = os .path .join (pocketdex_root_path , "tiltfiles" , "pocketdex.tilt" )
403- postgres_values_path = os .path .join ("." , "localnet" , "kubernetes" , "values-pocketdex-postgres.yaml" )
404- pgadmin_values_path = os .path .join ("." , "localnet" , "kubernetes" , "values-pocketdex-pgadmin.yaml" )
405- indexer_values_path = os .path .join ("." , "localnet" , "kubernetes" , "values-pocketdex-indexer.yaml" )
406- gql_engine_values_path = os .path .join ("." , "localnet" , "kubernetes" , "values-pocketdex-gql-engine.yaml" )
407-
408-
409- # pocketdex_repo_exists returns true if the sibling pocketdex repo exists.
410- def pocketdex_repo_exists ():
411- return str (
412- local ("[ -d {} ] && echo 'true' || echo 'false'" .format (pocketdex_root_path ),
413- echo_off = True )
414- ).strip ()
415-
416-
417- # pocketdex_disabled_resource creates a tilt resource that prints a message indicating
418- # that the indexer is disabled and how to enable it.
419- def pocketdex_disabled_resource (reason ):
420- local_resource ("⚠️ Indexer Disabled" ,
421- "echo '{}'" .format (reason ),
422- labels = ["Pocketdex" ])
423-
424-
425- # fetch_pocketdex_main fetches the main branch from the remote from which the repo was cloned.
426- def fetch_pocketdex_main ():
427- local ("git fetch {} main" .format (main_branch_remote_name ()),
428- dir = pocketdex_root_path ,
429- echo_off = True )
430-
431-
432- # main_branch_remote_name returns the name of the remote from which the repo was cloned.
433- def main_branch_remote_name ():
434- return str (
435- local ("git rev-parse --abbrev-ref @{u} | cut -d '/' -f1" ,
436- dir = pocketdex_root_path ,
437- echo_off = True ),
438- ).strip ()
439-
440-
441- # pocketdex_changes returns a tuple of integers representing the number of local
442- # and remote changes, respectively.
443- def pocketdex_changes ():
444- all_changes = str (
445- local ("git rev-list --left-right --count HEAD...{}/main" .format (main_branch_remote_name ()),
446- dir = pocketdex_root_path ,
447- echo_off = True )
448- )
449-
450- # Split the output into local and remote changes and convert to integers.
451- num_local_changes , num_remote_changes = [int (x ) for x in all_changes .split ()]
452-
453- return (num_local_changes , num_remote_changes )
454-
455-
456- # pocketdex_main_is_outdated returns true if there's a diff between the local and remote main branches.
457- def pocketdex_main_is_outdated ():
458- fetch_pocketdex_main ()
459- _ , num_remote_changes = pocketdex_changes ()
460- return num_remote_changes != 0
461-
462-
463- # pocketdex_outdated_resource creates a tilt resource that prints a message indicating
464- # that the indexer is outdated and how many commits behind it is.
465- def pocketdex_outdated_resource ():
466- _ , num_remote_changes = pocketdex_changes ()
467- local_resource ("🔄 Updates Available" ,
468- """
469- echo 'Pocketdex main branch is outdated; {} commits behind. Please `git pull --ff-only` to update pocketdex.'
470- """ .format (num_remote_changes ),
471- labels = ["Pocketdex" ])
472-
473-
474- def load_pocketdex ():
475- if pocketdex_main_is_outdated ():
476- pocketdex_outdated_resource ()
477-
478- pocketdex_tilt = load_dynamic (pocketdex_tilt_path )
479- pocketdex_tilt ["pocketdex" ](pocketdex_root_path ,
480- genesis_file_name = "localnet.json" ,
481- postgres_values_path = postgres_values_path ,
482- pgadmin_values_path = pgadmin_values_path ,
483- indexer_values_path = indexer_values_path ,
484- gql_engine_values_path = gql_engine_values_path )
485-
400+ load ("./tiltfiles/pocketdex.tilt" , "check_and_load_pocketdex" )
486401
487402# Check if sibling pocketdex repo exists.
488403# If it does, load the pocketdex.tilt file from the sibling repo.
489- # Otherwise check the `indexer.clone_if_not_present` flag in `localnet_config.yaml` and EITHER:
404+ # Otherwise, check the `indexer.clone_if_not_present` flag in `localnet_config.yaml` and EITHER:
490405# 1. clone pocketdex to ../pocketdex
491406# -- OR --
492407# 2. Prints a message if true or false
493- if localnet_config ["indexer" ]["enabled" ]:
494- if pocketdex_repo_exists () == "false" :
495- if localnet_config ["indexer" ]["clone_if_not_present" ]:
496- print ("Cloning pocketdex repo" )
497- # TODO_IMPROVE: https://github.com/tilt-dev/tilt-extensions/tree/master/git_resource
498- local ("""
499- git clone https://github.com/pokt-network/pocketdex --branch main {}
500- """ .format (pocketdex_root_path ))
501- load_pocketdex ()
502- else :
503- pocketdex_disabled_resource ("""
504- Pocketdex repo not found at {}. Set `clone_if_not_present` to `true` in `localnet_config.yaml`.
505- """ .format (pocketdex_root_path ))
506- else :
507- print ("Using existing pocketdex repo" )
508- load_pocketdex ()
509- else :
510- pocketdex_disabled_resource ("""
511- Pocketdex indexer disabled. Set `indexer.enabled` to `true` in `localnet_config.yaml` to enable it.
512- """ )
408+ check_and_load_pocketdex (localnet_config ["indexer" ])
0 commit comments