@@ -8,7 +8,89 @@ on-chain details of the API3 DAO, including:
8
8
- All events from the smart contracts of the API3 DAO
9
9
- DAO Treasuries status
10
10
11
- ## Local Installation
11
+ ## Architecture
12
+
13
+ The app relies on Terraform to configure a generic Linux EC2 instance.
14
+ The EC2 instance in-turn hosts Docker, and app-services are orchestrated by Docker directly (eg. ` restart=always ` ).
15
+
16
+ The services are:
17
+
18
+ ```
19
+ (end user) -> Cloudflare -> EC2 IP -> traefik (load balancer) -> api3-tracker (container)
20
+ ```
21
+
22
+ Containers:
23
+ - api3tracker: The FE and BE-service
24
+ - postgres: The database the FE and BE rely on
25
+ - traefik: A load balancer that encrypts HTTP responses (using the CF origin server key pair)
26
+ - postgres-exporter: a service that exports the database as a backup on an interval
27
+
28
+ Host services:
29
+ The host OS also runs some cron services, these are:
30
+ ``` bash
31
+ * /10 * * * * root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && ./bin/job_logs_download.sh >> /var/log/api3-logs-download.log 2>&1
32
+ 15,45 * * * * root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && ./bin/job_supply_download.sh >> /var/log/api3-supply-download.log 2>&1
33
+ 0 * * * * root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && ./bin/job_treasuries_download.sh >> /var/log/api3-treasuries-download.log 2>&1
34
+ 2,12,22,32,42,52 * * * * root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && ./bin/job_state_update.sh >> /var/log/api3-state-update.log 2>&1
35
+ 10 0 * * * root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && ./bin/job_shares_download.sh --tag . > /var/log/api3-shares-download.log 2>&1
36
+ 24 4 * * * /3 root cd /home/ubuntu/src/github.com/api3dao/api3-tracker/terraform/workspaces/api3tracker-prod && bash ./bin/postgres-backup.sh >> /var/log/postgres-backups.log 2>&1
37
+ ```
38
+
39
+ ## Local developement using Docker
40
+ Developers can run some or all services locally using Docker Swarm, or even bare-bones, without containerisation.
41
+
42
+ One combination is running just postgres locally using Docker, eg:
43
+ ``` bash
44
+ docker run --rm -ti -p 5432:5432 postgres:15
45
+ ```
46
+ and then running the FE and BE services directly (refer to Cron jobs below and ` yarn next dev ` in ` package.json ` ).
47
+
48
+ Alternatively, one can run services using Docker Swarm, but this lacks hot-reloading.
49
+
50
+ ### Local development using Docker Swarm
51
+ If you haven't already enabled Swarm mode on your Docker instance, do so now (only has to be done once):
52
+ ``` bash
53
+ docker swarm init
54
+ ```
55
+ The result of the above command can be ignored.
56
+
57
+ Build the FE/BE image:
58
+ ``` bash
59
+ docker build -t api3dao/api3-tracker:latest .
60
+ ```
61
+
62
+ Run the stack:
63
+ ``` bash
64
+ docker stack deploy -c dev-tools/docker-compose.yml tracker-stack
65
+ ```
66
+
67
+ If all goes well the application will be served at http://localhost:3000
68
+
69
+ Some commands for visualising the services:
70
+ ``` bash
71
+ docker ps # all docker containers
72
+ docker service ls # all swarm services
73
+ docker service ps tracker-stack_postgres --no-trunc # show status of postgres
74
+ docker stack rm tracker-stack # tear down the stack
75
+ ```
76
+
77
+ Initialise the DB:
78
+ ``` bash
79
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" yarn prisma migrate deploy
80
+ ```
81
+
82
+ Cron jobs (unwrapped versions of cronjobs):
83
+ ``` bash
84
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" TS_NODE_PROJECT=./tsconfig.cli.json yarn ts-node cli.ts logs download
85
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" TS_NODE_PROJECT=./tsconfig.cli.json yarn ts-node cli.ts supply download
86
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" TS_NODE_PROJECT=./tsconfig.cli.json yarn ts-node cli.ts treasuries download
87
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" TS_NODE_PROJECT=./tsconfig.cli.json yarn ts-node cli.ts shares download
88
+ DATABASE_URL=
" postgres://postgres:[email protected] :5432/postgres?sslmode=disable" API3TRACKER_ENDPOINT=
" ARCHIVE RPC URL" TS_NODE_PROJECT=./tsconfig.cli.json yarn ts-node cli.ts state update --rps-limit
89
+ ```
90
+
91
+ Keep in mind that the Postgres DB in the docker-compose file is not configured with a volume by default, so changes will be lost on service restart.
92
+
93
+ ## Local Installation and Deployment (Terraform only)
12
94
13
95
The only requirements for installation are [ Docker] ( https://docs.docker.com/get-docker/ )
14
96
and [ Terraform] ( https://learn.hashicorp.com/tutorials/terraform/install-cli ) .
0 commit comments