Skip to content

Commit 510465e

Browse files
committed
fixes
1 parent a7dfd2d commit 510465e

6 files changed

Lines changed: 107 additions & 25 deletions

File tree

Makefile

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,41 +1736,61 @@ postgres_status: ## Check PostgreSQL cluster status. Usage: make postgres_status
17361736
# ------------------------------------------------------------------------------
17371737

17381738
.PHONY: gateway_deploy
1739-
gateway_deploy: ## Deploy Gateway & Poller on both servers. Usage: make gateway_deploy ENV=hoodi
1739+
gateway_deploy: ## Deploy Gateway & Poller on both servers. Usage: make gateway_deploy ENV=hoodi [FORCE_REBUILD=true]
17401740
@if [ -z "$(ENV)" ]; then \
17411741
echo "Error: ENV must be set (hoodi or mainnet)"; \
17421742
exit 1; \
17431743
fi
1744-
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1744+
@EXTRA_VARS=""; \
1745+
if [ -n "$(FORCE_REBUILD)" ]; then \
1746+
EXTRA_VARS="-e force_rebuild=true"; \
1747+
fi; \
1748+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
17451749
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
17461750
-e "host=gateway_primary" \
1747-
-e "env=$(ENV)"
1748-
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1751+
-e "env=$(ENV)" \
1752+
$$EXTRA_VARS
1753+
@EXTRA_VARS=""; \
1754+
if [ -n "$(FORCE_REBUILD)" ]; then \
1755+
EXTRA_VARS="-e force_rebuild=true"; \
1756+
fi; \
1757+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
17491758
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
17501759
-e "host=gateway_secondary" \
1751-
-e "env=$(ENV)"
1760+
-e "env=$(ENV)" \
1761+
$$EXTRA_VARS
17521762

17531763
.PHONY: gateway_primary_deploy
1754-
gateway_primary_deploy: ## Deploy Gateway & Poller on primary only. Usage: make gateway_primary_deploy ENV=hoodi
1764+
gateway_primary_deploy: ## Deploy Gateway & Poller on primary only. Usage: make gateway_primary_deploy ENV=hoodi [FORCE_REBUILD=true]
17551765
@if [ -z "$(ENV)" ]; then \
17561766
echo "Error: ENV must be set (hoodi or mainnet)"; \
17571767
exit 1; \
17581768
fi
1759-
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1769+
@EXTRA_VARS=""; \
1770+
if [ -n "$(FORCE_REBUILD)" ]; then \
1771+
EXTRA_VARS="-e force_rebuild=true"; \
1772+
fi; \
1773+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
17601774
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
17611775
-e "host=gateway_primary" \
1762-
-e "env=$(ENV)"
1776+
-e "env=$(ENV)" \
1777+
$$EXTRA_VARS
17631778

17641779
.PHONY: gateway_secondary_deploy
1765-
gateway_secondary_deploy: ## Deploy Gateway & Poller on secondary only. Usage: make gateway_secondary_deploy ENV=hoodi
1780+
gateway_secondary_deploy: ## Deploy Gateway & Poller on secondary only. Usage: make gateway_secondary_deploy ENV=hoodi [FORCE_REBUILD=true]
17661781
@if [ -z "$(ENV)" ]; then \
17671782
echo "Error: ENV must be set (hoodi or mainnet)"; \
17681783
exit 1; \
17691784
fi
1770-
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1785+
@EXTRA_VARS=""; \
1786+
if [ -n "$(FORCE_REBUILD)" ]; then \
1787+
EXTRA_VARS="-e force_rebuild=true"; \
1788+
fi; \
1789+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
17711790
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
17721791
-e "host=gateway_secondary" \
1773-
-e "env=$(ENV)"
1792+
-e "env=$(ENV)" \
1793+
$$EXTRA_VARS
17741794

17751795
# ------------------------------------------------------------------------------
17761796
# Metrics Deployment

infra/aggregation_mode/ansible/README.md

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,13 @@ make gateway_deploy ENV=hoodi
246246
# Or deploy individually
247247
make gateway_primary_deploy ENV=hoodi
248248
make gateway_secondary_deploy ENV=hoodi
249+
250+
# Force rebuild (always rebuild binaries from latest code)
251+
make gateway_deploy ENV=hoodi FORCE_REBUILD=true
249252
```
250253

254+
**Note:** By default, the deployment is idempotent and skips building if the binary already exists. Use `FORCE_REBUILD=true` to always rebuild from the latest code in the repository.
255+
251256
**Verify gateway is running:**
252257
```bash
253258
ssh app@agg-mode-hoodi-gateway-1 "sudo systemctl status gateway"
@@ -539,22 +544,49 @@ ansible-playbook infra/aggregation_mode/ansible/playbooks/gateway.yaml \
539544
-i infra/aggregation_mode/ansible/hoodi-inventory.yaml \
540545
-e "host=gateway_primary" \
541546
-e "env=hoodi"
547+
548+
# Deploy gateway with forced rebuild
549+
ansible-playbook infra/aggregation_mode/ansible/playbooks/gateway.yaml \
550+
-i infra/aggregation_mode/ansible/hoodi-inventory.yaml \
551+
-e "host=gateway_primary" \
552+
-e "env=hoodi" \
553+
-e "force_rebuild=true"
542554
```
543555

544556
### Updating Services
545557

546-
**Update gateway code:**
558+
**Update gateway and poller with latest code:**
559+
560+
The easiest way to update services is using the `FORCE_REBUILD` parameter:
561+
562+
```bash
563+
# Update both primary and secondary
564+
make gateway_deploy ENV=hoodi FORCE_REBUILD=true
565+
566+
# Or update individually
567+
make gateway_primary_deploy ENV=hoodi FORCE_REBUILD=true
568+
make gateway_secondary_deploy ENV=hoodi FORCE_REBUILD=true
569+
```
570+
571+
This will:
572+
1. Pull latest code from the configured branch (staging for hoodi, main for mainnet)
573+
2. Delete existing binaries
574+
3. Rebuild gateway and poller from source
575+
4. Restart the services
576+
577+
**Manual update (alternative):**
578+
579+
If you prefer to update manually:
580+
547581
```bash
582+
# Gateway
548583
ssh app@agg-mode-hoodi-gateway-1
549584
cd ~/repos/gateway/aligned_layer
550585
git pull origin staging
551586
cargo install --path aggregation_mode/gateway --bin gateway --features tls --locked
552587
sudo systemctl restart gateway
553-
```
554588

555-
**Update poller code:**
556-
```bash
557-
ssh app@agg-mode-hoodi-gateway-1
589+
# Poller
558590
cd ~/repos/poller/aligned_layer
559591
git pull origin staging
560592
cargo install --path aggregation_mode/payments_poller --bin payments_poller --locked
@@ -563,16 +595,21 @@ systemctl --user restart poller
563595

564596
### Redeploy with Latest Code
565597

566-
To redeploy with the latest code from git, simply run the deployment again:
598+
**Idempotent deployment (skip if binary exists):**
567599

568600
```bash
569601
make gateway_deploy ENV=hoodi
570602
```
571603

572-
The playbooks will:
573-
1. Pull latest code from the configured branch
574-
2. Rebuild the binaries
575-
3. Restart the services
604+
This pulls the latest code but skips building if the binary already exists. Use this when you only want to update configuration files.
605+
606+
**Force rebuild (always rebuild binaries):**
607+
608+
```bash
609+
make gateway_deploy ENV=hoodi FORCE_REBUILD=true
610+
```
611+
612+
This always rebuilds binaries from the latest code, even if they already exist. Use this when you want to deploy code changes.
576613

577614
### Changing Configuration
578615

infra/aggregation_mode/ansible/playbooks/gateway.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
version: "{{ git_branch }}"
8686
update: yes
8787

88+
- name: Remove existing gateway binary (if force rebuild)
89+
file:
90+
path: /home/{{ ansible_user }}/.cargo/bin/gateway
91+
state: absent
92+
when: force_rebuild | default(false) | bool
93+
8894
- name: Build gateway with TLS
8995
shell: |
9096
export PATH=$HOME/.cargo/bin:$PATH

infra/aggregation_mode/ansible/playbooks/ini/config-mainnet.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ gateway_tls_key_path=/home/app/.ssl/key.pem
5959

6060
# Poller Service Settings (same for all pollers)
6161
poller_last_block_fetched_filepath=/home/app/config/proof-aggregator.last_block_fetched.json
62-
last_block_fetched_initial_value=0
62+
last_block_fetched_initial_value=24235289
6363

6464
# ============================================
6565
# TLS Certificate Management

infra/aggregation_mode/ansible/playbooks/pg_node.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@
126126
register: is_writable
127127
changed_when: false
128128

129+
- name: Set password for autoctl_node user in agg_mode database
130+
become: true
131+
become_user: postgres
132+
shell: |
133+
psql -d {{ db_name }} -c "ALTER USER {{ db_user }} PASSWORD '{{ db_password }}';"
134+
when: is_writable.stdout == 't'
135+
no_log: true
136+
129137
- name: Set password for pgautofailover_replicator user
130138
become: true
131139
become_user: postgres

infra/aggregation_mode/ansible/playbooks/poller.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
version: "{{ git_branch }}"
5656
update: yes
5757

58+
- name: Remove existing poller binary (if force rebuild)
59+
file:
60+
path: /home/{{ ansible_user }}/.cargo/bin/payments_poller
61+
state: absent
62+
when: force_rebuild | default(false) | bool
63+
5864
- name: Build poller
5965
shell: |
6066
export PATH=$HOME/.cargo/bin:$PATH
@@ -70,14 +76,19 @@
7076
owner: "{{ ansible_user }}"
7177
group: "{{ ansible_user }}"
7278

73-
- name: Create last_block_fetched file
79+
- name: Check if last_block_fetched file exists and get size
80+
stat:
81+
path: "{{ poller_last_block_fetched_filepath }}"
82+
register: last_block_file
83+
84+
- name: Create or fix last_block_fetched file if empty or missing
7485
copy:
75-
content: '{"last_block_fetched":{{ last_block_fetched_initial_value }}}'
86+
content: '{"last_block_fetched": {{ last_block_fetched_initial_value }}}'
7687
dest: "{{ poller_last_block_fetched_filepath }}"
7788
mode: '0644'
7889
owner: "{{ ansible_user }}"
7990
group: "{{ ansible_user }}"
80-
force: no
91+
when: not last_block_file.stat.exists or last_block_file.stat.size == 0
8192

8293
- name: Template poller config file
8394
template:

0 commit comments

Comments
 (0)