This repository has been archived by the owner on Feb 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-docker-compose.sh
executable file
·187 lines (162 loc) · 5.68 KB
/
generate-docker-compose.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
source .env
# Check with the user
echo "These are the ACTIVE_NODES specified in the .env file: $ACTIVE_NODES"
echo -n "Are they correct? (y/n): "
read user_input
if [[ $user_input != 'y' ]]; then
echo "Edit the .env file to change the ACTIVE_NODES"
exit 1
fi
DOCKER_COMPOSE_FILE="docker-compose.yml"
PROMETHEUS_CONFIG_FILE="monitoring/prometheus/prometheus.yml"
generate_node_service() {
local NODE_NUMBER=$1
cat <<-EOF
node-${NODE_NUMBER}:
<<: *node-template
environment:
<<: *node-env
CHARON_PRIVATE_KEY_FILE: /opt/charon/.charon/cluster/node${NODE_NUMBER}/charon-enr-private-key
CHARON_LOCK_FILE: /opt/charon/.charon/cluster/node${NODE_NUMBER}/cluster-lock.json
CHARON_JAEGER_SERVICE: node-${NODE_NUMBER}
CHARON_P2P_EXTERNAL_HOSTNAME: node-${NODE_NUMBER}
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:\${CHARON_${NODE_NUMBER}_P2P_TCP_ADDRESS_PORT}
CHARON_BUILDER_API: ${BUILDER_API_ENABLED:-false}
ports:
- \${CHARON_${NODE_NUMBER}_P2P_TCP_ADDRESS_PORT}:\${CHARON_${NODE_NUMBER}_P2P_TCP_ADDRESS_PORT}/tcp
vc-${NODE_NUMBER}:
image: consensys/teku:\${TEKU_VERSION:-23.10.0}
networks: [cluster]
restart: unless-stopped
command: |
validator-client
--data-base-path="/opt/data"
--beacon-node-api-endpoint="http://node-${NODE_NUMBER}:3600"
--metrics-enabled=true
--metrics-host-allowlist="*"
--metrics-interface="0.0.0.0"
--metrics-port="8008"
--validators-keystore-locking-enabled=false
--network="\${NETWORK}"
--validator-keys="/opt/charon/validator_keys:/opt/charon/validator_keys"
--validators-graffiti="\${GRAFFITI}"
--validators-proposer-blinded-blocks-enabled=${BUILDER_API_ENABLED:-false}
--validators-proposer-config="http://node-${NODE_NUMBER}:3600/teku_proposer_config"
depends_on: [node-${NODE_NUMBER}]
volumes:
- ./vc-clients/teku:/opt/data
- ./vc-clients/teku/run_validator.sh:/scripts/run_validator.sh
- .charon/cluster/node${NODE_NUMBER}/validator_keys:/opt/charon/validator_keys
EOF
}
generate_prometheus_config() {
local NODE_NUMBER=$1
cat <<-EOF
- job_name: "node-${NODE_NUMBER}"
static_configs:
- targets: ["node-${NODE_NUMBER}:3620"]
- job_name: "vc-${NODE_NUMBER}"
static_configs:
- targets: ["vc-${NODE_NUMBER}:8008"]
EOF
}
cat <<-'EOF' > $DOCKER_COMPOSE_FILE
version: "3.8"
x-node-base: &node-base
image: obolnetwork/charon:${CHARON_VERSION:-v0.18.0}
restart: unless-stopped
networks: [cluster]
depends_on: [relay]
volumes:
- ./.charon:/opt/charon/.charon/
x-node-env: &node-env
CHARON_BEACON_NODE_ENDPOINTS: ${CHARON_BEACON_NODE_ENDPOINTS}
CHARON_LOG_LEVEL: ${CHARON_LOG_LEVEL:-info}
CHARON_LOG_FORMAT: ${CHARON_LOG_FORMAT:-console}
CHARON_VALIDATOR_API_ADDRESS: 0.0.0.0:3600
CHARON_MONITORING_ADDRESS: 0.0.0.0:3620
CHARON_JAEGER_ADDRESS: 0.0.0.0:6831
x-node-template: &node-template
<<: *node-base
environment:
<<: *node-env
CHARON_P2P_RELAYS: ${CHARON_P2P_RELAYS}
services:
relay:
<<: *node-base
command: relay
depends_on: []
environment:
<<: *node-env
CHARON_HTTP_ADDRESS: 0.0.0.0:${CHARON_RELAY_PORT}
CHARON_DATA_DIR: /opt/charon/relay
CHARON_P2P_EXTERNAL_HOSTNAME: ${CHARON_P2P_EXTERNAL_HOSTNAME}
CHARON_P2P_TCP_ADDRESS: 0.0.0.0:${CHARON_RELAY_P2P_TCP_ADDRESS_PORT}
volumes:
- ./relay:/opt/charon/relay:rw
ports:
- ${CHARON_RELAY_P2P_TCP_ADDRESS_PORT}:${CHARON_RELAY_P2P_TCP_ADDRESS_PORT}/tcp
- ${CHARON_RELAY_PORT}:${CHARON_RELAY_PORT}/tcp
EOF
IFS=',' read -ra NODES <<< "$ACTIVE_NODES"
for NODE_NUMBER in "${NODES[@]}"; do
generate_node_service $NODE_NUMBER >> $DOCKER_COMPOSE_FILE
done
cat <<-'EOF' >> $DOCKER_COMPOSE_FILE
prometheus:
image: prom/prometheus:${PROMETHEUS_VERSION:-v2.44.0}
volumes:
- ./monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
networks: [cluster]
restart: unless-stopped
grafana:
image: grafana/grafana:${GRAFANA_VERSION:-9.5.3}
depends_on: [prometheus]
volumes:
- ./monitoring/grafana/datasource.yml:/etc/grafana/provisioning/datasources/datasource.yml
- ./monitoring/grafana/dashboards.yml:/etc/grafana/provisioning/dashboards/datasource.yml
- ./monitoring/grafana/grafana.ini:/etc/grafana/grafana.ini:ro
- ./monitoring/grafana/dashboards:/etc/dashboards
networks: [cluster]
restart: unless-stopped
ports:
- "${MONITORING_PORT_GRAFANA}:3000"
node-exporter:
image: prom/node-exporter:${NODE_EXPORTER_VERSION:-v1.6.0}
networks: [cluster]
restart: unless-stopped
jaeger:
image: jaegertracing/all-in-one:${JAEGAR_VERSION:-1.46.0}
networks: [cluster]
restart: unless-stopped
networks:
cluster:
EOF
# Write the beginning part of the Prometheus config file
cat <<-'EOF' > $PROMETHEUS_CONFIG_FILE
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
EOF
# Generate the dynamic Prometheus config
for NODE_NUMBER in "${NODES[@]}"; do
generate_prometheus_config $NODE_NUMBER >> $PROMETHEUS_CONFIG_FILE
done
# Write the remaining static part of the Prometheus config file
cat <<-'EOF' >> $PROMETHEUS_CONFIG_FILE
- job_name: "node-exporter"
static_configs:
- targets: ["node-exporter:9100"]
EOF
# Check if PROMETHEUS_CREDENTIALS and PROMETHEUS_REMOTE_WRITE_URL are set and then append the remote_write section
if [[ -n $PROMETHEUS_CREDENTIALS && -n $PROMETHEUS_REMOTE_WRITE_URL ]]; then
cat <<-EOF >> $PROMETHEUS_CONFIG_FILE
remote_write:
- url: $PROMETHEUS_REMOTE_WRITE_URL
authorization:
credentials: $PROMETHEUS_CREDENTIALS
EOF
fi
echo "Success! The docker-compose.yml and monitoring/prometheus/prometheus.yml files have been generated."