Skip to content

Commit 341efd7

Browse files
authored
infra(aggregation mode): deploy services with ansible (#2262)
1 parent 3bac894 commit 341efd7

37 files changed

+7359
-2881
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ docs/dead_links_report.txt
4646
terraform.tfstate
4747
terraform.tfstate.backup
4848

49+
50+
# Aggregation Mode Ansible INI files (track config-*.ini templates, ignore others)
51+
infra/aggregation_mode/ansible/playbooks/ini/*.ini
52+
!infra/aggregation_mode/ansible/playbooks/ini/config-*.ini

Makefile

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,3 +1658,220 @@ __NODE_EXPORTER_:
16581658

16591659
install_node_exporter:
16601660
@./scripts/install_node_exporter.sh
1661+
1662+
# ==============================================================================
1663+
# Aggregation Mode Ansible Deployment
1664+
# ==============================================================================
1665+
1666+
AGG_MODE_ANSIBLE_DIR = infra/aggregation_mode/ansible
1667+
AGG_MODE_PLAYBOOKS_DIR = $(AGG_MODE_ANSIBLE_DIR)/playbooks
1668+
AGG_MODE_INI_DIR = $(AGG_MODE_PLAYBOOKS_DIR)/ini
1669+
1670+
# TODO: Check and add targets to install gateway, poller and cli binaries locally
1671+
1672+
# ------------------------------------------------------------------------------
1673+
# PostgreSQL Cluster Deployment
1674+
# ------------------------------------------------------------------------------
1675+
1676+
.PHONY: postgres_deploy
1677+
postgres_deploy: ## Deploy PostgreSQL Auto-Failover Cluster. Usage: make postgres_deploy ENV=hoodi
1678+
@if [ -z "$(ENV)" ]; then \
1679+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1680+
exit 1; \
1681+
fi
1682+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/postgres_cluster.yaml \
1683+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1684+
-e "env=$(ENV)"
1685+
1686+
.PHONY: postgres_monitor_deploy
1687+
postgres_monitor_deploy: ## Deploy PostgreSQL Monitor only. Usage: make postgres_monitor_deploy ENV=hoodi
1688+
@if [ -z "$(ENV)" ]; then \
1689+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1690+
exit 1; \
1691+
fi
1692+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/pg_monitor.yaml \
1693+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1694+
-e "host=postgres_monitor" \
1695+
-e "env=$(ENV)"
1696+
1697+
.PHONY: postgres_nodes_deploy
1698+
postgres_nodes_deploy: ## Deploy PostgreSQL Primary & Secondary. Usage: make postgres_nodes_deploy ENV=hoodi
1699+
@if [ -z "$(ENV)" ]; then \
1700+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1701+
exit 1; \
1702+
fi
1703+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/pg_node.yaml \
1704+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1705+
-e "host=postgres_1" \
1706+
-e "env=$(ENV)"
1707+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/pg_node.yaml \
1708+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1709+
-e "host=postgres_2" \
1710+
-e "env=$(ENV)"
1711+
1712+
.PHONY: postgres_migrations
1713+
postgres_migrations: ## Run database migrations. Usage: make postgres_migrations ENV=hoodi
1714+
@if [ -z "$(ENV)" ]; then \
1715+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1716+
exit 1; \
1717+
fi
1718+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/postgres_migrations.yaml \
1719+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1720+
-e "host=postgres_1" \
1721+
-e "env=$(ENV)"
1722+
1723+
.PHONY: postgres_status
1724+
postgres_status: ## Check PostgreSQL cluster status. Usage: make postgres_status ENV=hoodi
1725+
@if [ -z "$(ENV)" ]; then \
1726+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1727+
exit 1; \
1728+
fi
1729+
@ansible postgres_monitor -i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1730+
-m shell -a "sudo -u postgres pg_autoctl show state --monitor postgres://autoctl_node@localhost:5432/pg_auto_failover" --become
1731+
1732+
# ------------------------------------------------------------------------------
1733+
# Gateway & Poller Deployment
1734+
# ------------------------------------------------------------------------------
1735+
1736+
.PHONY: gateway_deploy
1737+
gateway_deploy: ## Deploy Gateway & Poller on both servers. Usage: make gateway_deploy ENV=hoodi [FORCE_REBUILD=true]
1738+
@if [ -z "$(ENV)" ]; then \
1739+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1740+
exit 1; \
1741+
fi
1742+
@EXTRA_VARS=""; \
1743+
if [ -n "$(FORCE_REBUILD)" ]; then \
1744+
EXTRA_VARS="-e force_rebuild=true"; \
1745+
fi; \
1746+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1747+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1748+
-e "host=gateway_1" \
1749+
-e "env=$(ENV)" \
1750+
$$EXTRA_VARS
1751+
@EXTRA_VARS=""; \
1752+
if [ -n "$(FORCE_REBUILD)" ]; then \
1753+
EXTRA_VARS="-e force_rebuild=true"; \
1754+
fi; \
1755+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1756+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1757+
-e "host=gateway_2" \
1758+
-e "env=$(ENV)" \
1759+
$$EXTRA_VARS
1760+
1761+
.PHONY: gateway_1_deploy
1762+
gateway_1_deploy: ## Deploy Gateway & Poller on gateway 1 only. Usage: make gateway_1_deploy ENV=hoodi [FORCE_REBUILD=true]
1763+
@if [ -z "$(ENV)" ]; then \
1764+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1765+
exit 1; \
1766+
fi
1767+
@EXTRA_VARS=""; \
1768+
if [ -n "$(FORCE_REBUILD)" ]; then \
1769+
EXTRA_VARS="-e force_rebuild=true"; \
1770+
fi; \
1771+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1772+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1773+
-e "host=gateway_1" \
1774+
-e "env=$(ENV)" \
1775+
$$EXTRA_VARS
1776+
1777+
.PHONY: gateway_2_deploy
1778+
gateway_2_deploy: ## Deploy Gateway & Poller on gateway 2 only. Usage: make gateway_2_deploy ENV=hoodi [FORCE_REBUILD=true]
1779+
@if [ -z "$(ENV)" ]; then \
1780+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1781+
exit 1; \
1782+
fi
1783+
@EXTRA_VARS=""; \
1784+
if [ -n "$(FORCE_REBUILD)" ]; then \
1785+
EXTRA_VARS="-e force_rebuild=true"; \
1786+
fi; \
1787+
ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/gateway_stack.yaml \
1788+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1789+
-e "host=gateway_2" \
1790+
-e "env=$(ENV)" \
1791+
$$EXTRA_VARS
1792+
1793+
# ------------------------------------------------------------------------------
1794+
# Metrics Deployment
1795+
# ------------------------------------------------------------------------------
1796+
1797+
.PHONY: metrics_deploy
1798+
metrics_deploy: ## Deploy Prometheus & Grafana. Usage: make metrics_deploy ENV=hoodi
1799+
@if [ -z "$(ENV)" ]; then \
1800+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1801+
exit 1; \
1802+
fi
1803+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/metrics_stack.yaml \
1804+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1805+
-e "host=metrics" \
1806+
-e "env=$(ENV)"
1807+
1808+
.PHONY: prometheus_deploy
1809+
prometheus_deploy: ## Deploy Prometheus only. Usage: make prometheus_deploy ENV=hoodi
1810+
@if [ -z "$(ENV)" ]; then \
1811+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1812+
exit 1; \
1813+
fi
1814+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/prometheus_agg_mode.yaml \
1815+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1816+
-e "host=metrics" \
1817+
-e "env=$(ENV)"
1818+
1819+
.PHONY: grafana_deploy
1820+
grafana_deploy: ## Deploy Grafana only. Usage: make grafana_deploy ENV=hoodi
1821+
@if [ -z "$(ENV)" ]; then \
1822+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1823+
exit 1; \
1824+
fi
1825+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/grafana_agg_mode.yaml \
1826+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1827+
-e "host=metrics" \
1828+
-e "env=$(ENV)"
1829+
1830+
# ------------------------------------------------------------------------------
1831+
# Task Sender Deployment
1832+
# ------------------------------------------------------------------------------
1833+
1834+
.PHONY: task_sender_deploy
1835+
task_sender_deploy: ## Deploy task sender. Usage: make task_sender_deploy ENV=hoodi
1836+
@if [ -z "$(ENV)" ]; then \
1837+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1838+
exit 1; \
1839+
fi
1840+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/task_sender.yaml \
1841+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1842+
-e "host=task_sender" \
1843+
-e "env=$(ENV)"
1844+
1845+
.PHONY: task_sender_status
1846+
task_sender_status: ## Check task sender status. Usage: make task_sender_status ENV=hoodi
1847+
@if [ -z "$(ENV)" ]; then \
1848+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1849+
exit 1; \
1850+
fi
1851+
@echo "Checking task sender tmux session..."
1852+
@ansible -i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml task_sender \
1853+
-m shell \
1854+
-a "tmux has-session -t task_sender && echo 'Task sender is running' || echo 'Task sender is not running'"
1855+
1856+
.PHONY: task_sender_logs
1857+
task_sender_logs: ## View task sender logs. Usage: make task_sender_logs ENV=hoodi
1858+
@if [ -z "$(ENV)" ]; then \
1859+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1860+
exit 1; \
1861+
fi
1862+
@echo "Use: ssh app@agg-mode-$(ENV)-task-sender 'tmux attach -t task_sender'"
1863+
@echo "Or: ssh app@agg-mode-$(ENV)-task-sender 'tmux capture-pane -t task_sender -p'"
1864+
1865+
# ------------------------------------------------------------------------------
1866+
# Full Deployment
1867+
# ------------------------------------------------------------------------------
1868+
1869+
.PHONY: agg_mode_deploy_all
1870+
agg_mode_deploy_all: ## Deploy entire aggregation mode stack. Usage: make agg_mode_deploy_all ENV=hoodi
1871+
@if [ -z "$(ENV)" ]; then \
1872+
echo "Error: ENV must be set (hoodi or mainnet)"; \
1873+
exit 1; \
1874+
fi
1875+
@ansible-playbook $(AGG_MODE_PLAYBOOKS_DIR)/deploy_all.yaml \
1876+
-i $(AGG_MODE_ANSIBLE_DIR)/$(ENV)-inventory.yaml \
1877+
-e "env=$(ENV)"

0 commit comments

Comments
 (0)