|
16 | 16 | help="Number of replicas. This is the number of copies of each chunk that will be stored on different shards.", |
17 | 17 | default=2, |
18 | 18 | ) |
19 | | -parser.add_argument( |
20 | | - "--public-port", |
21 | | - type=int, |
22 | | - help="Public port for the frontend service. This is the port that will be exposed to the outside world.", |
23 | | - default=80, |
24 | | -) |
25 | 19 | parser.add_argument( |
26 | 20 | "--dev-shards", |
27 | 21 | type=int, |
|
32 | 26 |
|
33 | 27 | PG_PASSWORD = os.urandom(16).hex() |
34 | 28 | CONNECTION_SECRET = os.urandom(16) |
| 29 | +while "/" in base64.b64encode(CONNECTION_SECRET).decode().strip("="): |
| 30 | + CONNECTION_SECRET = os.urandom(16) |
35 | 31 |
|
36 | 32 | base = { |
37 | 33 | "services": { |
38 | 34 | "frontend": { |
39 | 35 | "build": {"context": "./frontend"}, |
40 | | - "container_name": "frontend", |
41 | 36 | "networks": ["shard_net"], |
42 | 37 | "restart": "unless-stopped", |
43 | 38 | }, |
44 | 39 | "server": { |
45 | 40 | "build": {"context": "./server"}, |
46 | | - "container_name": "sharder-server", |
47 | 41 | "depends_on": ["postgres"], |
48 | 42 | "networks": ["shard_net"], |
49 | 43 | "restart": "unless-stopped", |
|
54 | 48 | "CONNECTION_SECRET": CONNECTION_SECRET.hex(), |
55 | 49 | "DB_URL": f"postgresql://shard:{PG_PASSWORD}@postgres/shard", |
56 | 50 | }, |
| 51 | + "volumes": ["./prometheus/file_sd:/file_sd"], |
57 | 52 | }, |
58 | 53 | "nginx": { |
59 | 54 | "image": "nginx:latest", |
60 | | - "ports": [f"{args.public_port}:80"], |
61 | 55 | "depends_on": ["frontend", "server"], |
62 | 56 | "networks": ["shard_net"], |
63 | 57 | "restart": "unless-stopped", |
64 | 58 | "volumes": ["./default.conf:/etc/nginx/conf.d/default.conf"], |
65 | 59 | }, |
| 60 | + "nginx-exporter": { |
| 61 | + "image": "nginx/nginx-prometheus-exporter:latest", |
| 62 | + "command": "--nginx.scrape-uri=http://nginx:9113/nginx_status --web.listen-address=:9113", |
| 63 | + "depends_on": ["nginx"], |
| 64 | + "networks": ["shard_net"], |
| 65 | + }, |
66 | 66 | "postgres": { |
67 | 67 | "image": "postgres:latest", |
68 | 68 | "networks": ["shard_net"], |
|
74 | 74 | "POSTGRES_PASSWORD": PG_PASSWORD, |
75 | 75 | }, |
76 | 76 | }, |
| 77 | + "prometheus": { |
| 78 | + "image": "prom/prometheus:latest", |
| 79 | + "volumes": [ |
| 80 | + "./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro", |
| 81 | + "./prometheus/file_sd:/etc/prometheus/file_sd", |
| 82 | + ], |
| 83 | + "networks": ["shard_net"], |
| 84 | + }, |
| 85 | + "grafana": { |
| 86 | + "image": "grafana/grafana:latest", |
| 87 | + "environment": { |
| 88 | + "GF_SECURITY_ADMIN_PASSWORD": os.urandom(16).hex(), |
| 89 | + "GF_INSTALL_PLUGINS": "grafana-piechart-panel,grafana-clock-panel", |
| 90 | + }, |
| 91 | + "volumes": [ |
| 92 | + "grafana-data:/var/lib/grafana", |
| 93 | + "./grafana/provisioning:/etc/grafana/provisioning:ro", |
| 94 | + ], |
| 95 | + "depends_on": ["prometheus"], |
| 96 | + "networks": ["shard_net"], |
| 97 | + }, |
| 98 | + "socket-proxy": { |
| 99 | + "image": "docker.io/alpine/socat", |
| 100 | + "volumes": ["./socks:/socks", "./socat-entrypoint.sh:/socat-entrypoint.sh"], |
| 101 | + "entrypoint": ["/bin/sh"], |
| 102 | + "command": "/socat-entrypoint.sh", |
| 103 | + "depends_on": ["grafana", "nginx", "prometheus"], |
| 104 | + "networks": ["shard_net"], |
| 105 | + }, |
77 | 106 | }, |
78 | 107 | "volumes": { |
79 | 108 | "postgres-storage": {}, |
| 109 | + "grafana-data": {}, |
80 | 110 | }, |
81 | 111 | "networks": {"shard_net": {}}, |
82 | 112 | } |
83 | 113 |
|
84 | 114 | for i in range(args.dev_shards): |
| 115 | + token = base64.b64encode(CONNECTION_SECRET).decode().strip("=") |
85 | 116 | base["services"][f"shard-{i}"] = { |
86 | 117 | "build": {"context": "./shard"}, |
87 | | - "container_name": f"shard-{i}", |
88 | 118 | "networks": ["shard_net"], |
89 | 119 | "restart": "unless-stopped", |
90 | 120 | "depends_on": ["server"], |
91 | | - "environment": { |
92 | | - "SHARD_TOKEN": base64.b64encode(CONNECTION_SECRET).decode().strip("=") |
93 | | - }, |
94 | 121 | "volumes": [ |
95 | 122 | f"shard-{i}-storage:/opt/shard/.data", |
96 | 123 | ], |
| 124 | + "command": f"sh -c 'export SHARD_PUBLIC_IP=$(hostname -i) && ./shard \"http://nginx/api/connect/{token}\" --dry'", |
97 | 125 | } |
98 | 126 | base["volumes"][f"shard-{i}-storage"] = {} |
99 | 127 |
|
|
0 commit comments