@@ -58,7 +58,6 @@ def __init__(self, name: str = SANDBOX_BASE_NAME, config_path: Path | None = Non
5858 self ._latest_yaml = get_docker_compose_yml (name = f"algokit_{ self .name } " )
5959 self ._latest_config_json = get_config_json ()
6060 self ._latest_algod_network_template = get_algod_network_template ()
61- self ._latest_proxy_config = get_proxy_config ()
6261
6362 @property
6463 def compose_file_path (self ) -> Path :
@@ -76,10 +75,6 @@ def algod_config_file_path(self) -> Path:
7675 def algod_network_template_file_path (self ) -> Path :
7776 return self .directory / "algod_network_template.json"
7877
79- @property
80- def proxy_config_file_path (self ) -> Path :
81- return self .directory / "nginx.conf"
82-
8378 @classmethod
8479 def from_environment (cls ) -> ComposeSandbox | None :
8580 try :
@@ -148,7 +143,6 @@ def compose_file_status(self) -> ComposeFileStatus:
148143 compose_content = self .compose_file_path .read_text ()
149144 config_content = self .algod_config_file_path .read_text ()
150145 algod_network_template_content = self .algod_network_template_file_path .read_text ()
151- proxy_config_content = self .proxy_config_file_path .read_text ()
152146
153147 except FileNotFoundError :
154148 # treat as out of date if compose file exists but algod config doesn't
@@ -157,32 +151,38 @@ def compose_file_status(self) -> ComposeFileStatus:
157151 return ComposeFileStatus .OUT_OF_DATE
158152 return ComposeFileStatus .MISSING
159153 else :
160- algod_network_json_content = json .loads (
161- algod_network_template_content .replace ("NUM_ROUNDS" , '"NUM_ROUNDS"' )
162- )
163- latest_algod_network_json_content = json .loads (
164- self ._latest_algod_network_template .replace ("NUM_ROUNDS" , '"NUM_ROUNDS"' )
165- )
166-
167- del algod_network_json_content ["Genesis" ]["DevMode" ]
168- del latest_algod_network_json_content ["Genesis" ]["DevMode" ]
169-
170- if (
171- compose_content == self ._latest_yaml
172- and config_content == self ._latest_config_json
173- and algod_network_json_content == latest_algod_network_json_content
174- and proxy_config_content == self ._latest_proxy_config
175- ):
176- return ComposeFileStatus .UP_TO_DATE
177- else :
154+ try :
155+ # Perform some content normalization to ensure we correctly detect up to date files
156+
157+ # Ensure the NUM_ROUNDS placeholder is the same in both files
158+ algod_network_json_content = json .loads (
159+ algod_network_template_content .replace ("NUM_ROUNDS" , '"NUM_ROUNDS"' )
160+ )
161+ latest_algod_network_json_content = json .loads (
162+ self ._latest_algod_network_template .replace ("NUM_ROUNDS" , '"NUM_ROUNDS"' )
163+ )
164+
165+ # Remove DevMode from comparison as the value is configurable via the `--dev` option
166+ del algod_network_json_content ["Genesis" ]["DevMode" ]
167+ del latest_algod_network_json_content ["Genesis" ]["DevMode" ]
168+
169+ if (
170+ compose_content == self ._latest_yaml
171+ and config_content == self ._latest_config_json
172+ and algod_network_json_content == latest_algod_network_json_content
173+ ):
174+ return ComposeFileStatus .UP_TO_DATE
175+ else :
176+ return ComposeFileStatus .OUT_OF_DATE
177+ except (json .JSONDecodeError , KeyError ):
178+ # If config files are corrupted or malformed, treat as out of date
178179 return ComposeFileStatus .OUT_OF_DATE
179180
180181 def write_compose_file (self ) -> None :
181182 self .conduit_file_path .write_text (self ._conduit_yaml )
182183 self .compose_file_path .write_text (self ._latest_yaml )
183184 self .algod_config_file_path .write_text (self ._latest_config_json )
184185 self .algod_network_template_file_path .write_text (self ._latest_algod_network_template )
185- self .proxy_config_file_path .write_text (self ._latest_proxy_config )
186186
187187 def _run_compose_command (
188188 self ,
@@ -328,7 +328,7 @@ def check_docker_compose_for_new_image_versions(self, *, force: bool = False) ->
328328INDEXER_HEALTH_URL = f"{ DEFAULT_INDEXER_SERVER } :{ DEFAULT_INDEXER_PORT } /health"
329329INDEXER_IMAGE = "algorand/indexer:latest"
330330ALGORAND_IMAGE = "algorand/algod:latest"
331- CONDUIT_IMAGE = "algorand /conduit:latest"
331+ CONDUIT_IMAGE = "algorandfoundation /conduit-localnet :latest"
332332IMAGE_VERSION_CHECK_INTERVAL = timedelta (weeks = 1 ).total_seconds ()
333333
334334
@@ -440,8 +440,9 @@ def _wait_for_indexer() -> bool:
440440
441441def get_config_json () -> str :
442442 return (
443- '{ "Version": 12, "GossipFanout": 1, "EndpointAddress": "0.0.0.0:8080", "DNSBootstrapID": "",'
444- ' "IncomingConnectionsLimit": 0, "Archival":true, "isIndexerActive":false, "EnableDeveloperAPI":true}'
443+ '{ "GossipFanout": 1, "EndpointAddress": "0.0.0.0:8080", "DNSBootstrapID": "",'
444+ ' "IncomingConnectionsLimit": 0, "Archival":true, "isIndexerActive":false, "EnableDeveloperAPI":true,'
445+ ' "EnablePrivateNetworkAccessHeader":true}'
445446 )
446447
447448
@@ -512,7 +513,7 @@ def get_conduit_yaml() -> str:
512513retry-count: 10
513514
514515# Time duration to wait between retry attempts.
515- retry-delay: "1s "
516+ retry-delay: "5s "
516517
517518# Optional filepath to use for pidfile.
518519#pid-filepath: /path/to/pidfile
@@ -528,20 +529,10 @@ def get_conduit_yaml() -> str:
528529
529530# The importer is typically an algod follower node.
530531importer:
531- name: algod
532+ name: localnet_algod
532533 config:
533- # The mode of operation, either "archival" or "follower".
534- # * archival mode allows you to start processing on any round but does not
535- # contain the ledger state delta objects required for the postgres writer.
536- # * follower mode allows you to use a lightweight non-archival node as the
537- # data source. In addition, it will provide ledger state delta objects to
538- # the processors and exporter.
539- mode: "follower"
540-
541- # Algod API address.
542- netaddr: "http://algod:8081"
543-
544- # Algod API token.
534+ lead-node-url: "http://algod:8080"
535+ follower-node-url: "http://algod:8081"
545536 token: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
546537
547538# Zero or more processors may be defined to manipulate what data
@@ -563,70 +554,6 @@ def get_conduit_yaml() -> str:
563554"""
564555
565556
566- def get_proxy_config (algod_port : int = DEFAULT_ALGOD_PORT , kmd_port : int = 4002 ) -> str :
567- return f"""worker_processes 1;
568-
569- events {{
570- worker_connections 1024;
571- }}
572-
573- http {{
574- access_log off;
575-
576- resolver 127.0.0.11 ipv6=off valid=10s;
577- resolver_timeout 5s;
578- client_max_body_size 0;
579-
580- map $request_method$http_access_control_request_private_network $cors_allow_private_network {{
581- "OPTIONStrue" "true";
582- default "";
583- }}
584-
585- add_header Access-Control-Allow-Private-Network $cors_allow_private_network;
586-
587- server {{
588- listen { algod_port } ;
589-
590- location / {{
591- proxy_http_version 1.1;
592- proxy_read_timeout 120s;
593- proxy_set_header Host $host;
594- proxy_set_header Connection "";
595- proxy_pass_header Server;
596- set $target http://algod:8080;
597- proxy_pass $target;
598- }}
599- }}
600-
601- server {{
602- listen { kmd_port } ;
603-
604- location / {{
605- proxy_http_version 1.1;
606- proxy_set_header Host $host;
607- proxy_set_header Connection "";
608- proxy_pass_header Server;
609- set $target http://algod:7833;
610- proxy_pass $target;
611- }}
612- }}
613-
614- server {{
615- listen 8980;
616-
617- location / {{
618- proxy_http_version 1.1;
619- proxy_set_header Host $host;
620- proxy_set_header Connection "";
621- proxy_pass_header Server;
622- set $target http://indexer:8980;
623- proxy_pass $target;
624- }}
625- }}
626- }}
627- """
628-
629-
630557def get_docker_compose_yml (
631558 name : str = "algokit_sandbox" ,
632559 algod_port : int = DEFAULT_ALGOD_PORT ,
@@ -640,7 +567,8 @@ def get_docker_compose_yml(
640567 container_name: "{ name } _algod"
641568 image: { ALGORAND_IMAGE }
642569 ports:
643- - 7833
570+ - { algod_port } :8080
571+ - { kmd_port } :7833
644572 - { tealdbg_port } :9392
645573 environment:
646574 START_KMD: 1
@@ -684,28 +612,14 @@ def get_docker_compose_yml(
684612 indexer:
685613 container_name: "{ name } _indexer"
686614 image: { INDEXER_IMAGE }
615+ ports:
616+ - 8980:8980
687617 restart: unless-stopped
688618 command: daemon --enable-all-parameters
689619 environment:
690620 INDEXER_POSTGRES_CONNECTION_STRING: "host=indexer-db port=5432 user=algorand password=algorand dbname=indexerdb sslmode=disable"
691621 depends_on:
692622 - conduit
693-
694- proxy:
695- container_name: "{ name } _proxy"
696- image: nginx:1.27.0-alpine
697- restart: unless-stopped
698- ports:
699- - { algod_port } :{ algod_port }
700- - { kmd_port } :{ kmd_port }
701- - 8980:8980
702- volumes:
703- - type: bind
704- source: ./nginx.conf
705- target: /etc/nginx/nginx.conf
706- depends_on:
707- - algod
708- - indexer
709623""" # noqa: E501
710624
711625
0 commit comments