Skip to content

Commit aca216e

Browse files
authored
remove unwated software (#79)
* remove unwated software * log fix * log fix
1 parent 684d14c commit aca216e

File tree

5 files changed

+125
-6
lines changed

5 files changed

+125
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Inspired by https://github.com/AdityaGarg8/remove-unwanted-software
2+
# to free up disk space. Currently removes Dotnet, Android and Haskell.
3+
name: Remove unwanted software
4+
description: Default GitHub runners come with a lot of unnecessary software
5+
runs:
6+
using: "composite"
7+
steps:
8+
- name: Disk space report before modification
9+
shell: bash
10+
run: |
11+
echo "==> Available space before cleanup"
12+
echo
13+
df -h
14+
- name: Maximize build disk space
15+
shell: bash
16+
run: |
17+
set -euo pipefail
18+
sudo rm -rf /usr/share/dotnet
19+
sudo rm -rf /usr/local/lib/android
20+
sudo rm -rf /opt/ghc
21+
sudo rm -rf /usr/local/.ghcup
22+
- name: Disk space report after modification
23+
shell: bash
24+
run: |
25+
echo "==> Available space after cleanup"
26+
echo
27+
df -h

.github/workflows/test_common.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ jobs:
3636
tests:
3737
name: tests
3838
runs-on: ubuntu-latest
39-
timeout-minutes: 90
39+
timeout-minutes: 120
4040
steps:
4141

4242
- uses: actions/checkout@v4
4343

44+
- name: Remove unwanted software
45+
uses: ./.github/actions/prune-vm
46+
4447
- uses: actions/setup-python@v4
4548
with:
4649
python-version: '3.12'

pyrightconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"reportInvalidStringEscapeSequence": false,
77
"reportWildcardImportFromLibrary": false,
88
"venvPath": ".",
9-
"venv": ".venv"
9+
"venv": ".venv",
10+
"typeCheckingMode": "off"
1011
}

scripts/waku_network.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
printf "\nAssuming you already have a docker network called waku\n"
3+
# if not something like this should create it: docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 waku
4+
5+
cluster_id=4
6+
pubsub_topic="/waku/2/rs/$cluster_id/0"
7+
encoded_pubsub_topic=$(echo "$pubsub_topic" | sed 's:/:%2F:g')
8+
node_1=wakuorg/go-waku:latest
9+
node_2=wakuorg/go-waku:latest
10+
node_1_ip=172.18.45.95
11+
12+
printf "\nStarting Bootstrap Node\n"
13+
container_id1=$(docker run -d -i -t -p 12297:12297 -p 12298:12298 -p 12299:12299 -p 12300:12300 -p 12301:12301 $node_1 --listen-address=0.0.0.0 --rest=true --rest-admin=true --websocket-support=true --log-level=DEBUG --rest-relay-cache-capacity=100 --websocket-port=12299 --rest-port=12297 --tcp-port=12298 --discv5-udp-port=12300 --rest-address=0.0.0.0 --nat=extip:$node_1_ip --peer-exchange=true --discv5-discovery=true --cluster-id=$cluster_id --relay=true --store=true --nodekey=30348dd51465150e04a5d9d932c72864c8967f806cce60b5d26afeca1e77eb68)
14+
docker network connect --ip $node_1_ip waku $container_id1
15+
sleep 1
16+
17+
info1=$(curl -X GET "http://127.0.0.1:12297/debug/v1/info" -H "accept: application/json")
18+
enrUri=$(echo $info1 | jq -r '.enrUri')
19+
20+
printf "\nStarting Second Node\n"
21+
container_id2=$(docker run -d -i -t -p 8158:8158 -p 8159:8159 -p 8160:8160 -p 8161:8161 -p 8162:8162 $node_2 --listen-address=0.0.0.0 --rest=true --rest-admin=true --websocket-support=true --log-level=DEBUG --rest-relay-cache-capacity=100 --websocket-port=8160 --rest-port=8158 --tcp-port=8159 --discv5-udp-port=8161 --rest-address=0.0.0.0 --nat=extip:172.18.207.159 --peer-exchange=true --discv5-discovery=true --cluster-id=$cluster_id --relay=true --discv5-bootstrap-node=$enrUri)
22+
docker network connect --ip 172.18.207.159 waku $container_id2
23+
sleep 1
24+
25+
printf "\nSubscribe\n"
26+
curl -X POST "http://127.0.0.1:12297/relay/v1/subscriptions" -H "Content-Type: application/json" -d "[\"$pubsub_topic\"]"
27+
curl -X POST "http://127.0.0.1:8158/relay/v1/subscriptions" -H "Content-Type: application/json" -d "[\"$pubsub_topic\"]"
28+
sleep 0.1
29+
30+
printf "\nRelay from NODE1\n"
31+
curl -X POST "http://127.0.0.1:12297/relay/v1/messages/$encoded_pubsub_topic" -H "Content-Type: application/json" -d '{"payload": "UmVsYXkgd29ya3MhIQ==", "contentTopic": "/test/1/waku-relay/proto", "timestamp": '$(date +%s%N)'}'
32+
sleep 0.1
33+
34+
printf "\nCheck message in NODE2\n"
35+
response=$(curl -X GET "http://127.0.0.1:8158/relay/v1/messages/$encoded_pubsub_topic" -H "Content-Type: application/json")
36+
37+
printf "\nResponse: $response\n\n"
38+
39+
printf "NODE1 INFO: $info1\n\n"
40+
41+
printf "NODE1 ENR: $enrUri\n\n"
42+
43+
# Extract the first non-WebSocket address
44+
ws_address=$(echo $info1 | jq -r '.listenAddresses[] | select(contains("/ws") | not)')
45+
46+
# Check if we got an address, and construct the new address with it
47+
if [[ $ws_address != "" ]]; then
48+
identifier=$(echo $ws_address | awk -F'/p2p/' '{print $2}')
49+
if [[ $identifier != "" ]]; then
50+
multiaddr_with_id="/ip4/${node_1_ip}/tcp/${node_1_tcp}/p2p/${identifier}"
51+
printf "NODE1 MULTIADDRESS: $multiaddr_with_id\n\n"
52+
enrUri=$(echo $info1 | jq -r '.enrUri')
53+
else
54+
echo "No identifier found in the address."
55+
exit 1
56+
fi
57+
else
58+
echo "No non-WebSocket address found."
59+
exit 1
60+
fi
61+

src/node/docker_mananger.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
import re
3+
import time
34
from src.libs.custom_logger import get_custom_logger
45
import random
56
import threading
67
import docker
78
from src.env_vars import NETWORK_NAME, SUBNET, IP_RANGE, GATEWAY
89
from docker.types import IPAMConfig, IPAMPool
9-
from docker.errors import NotFound
10+
from docker.errors import NotFound, APIError
1011

1112
logger = get_custom_logger(__name__)
1213

@@ -63,9 +64,35 @@ def start_container(self, image_name, ports, args, log_path, container_ip, volum
6364

6465
def _log_container_output(self, container, log_path):
6566
os.makedirs(os.path.dirname(log_path), exist_ok=True)
66-
with open(log_path, "wb+") as log_file:
67-
for chunk in container.logs(stream=True):
68-
log_file.write(chunk)
67+
retry_count = 0
68+
start_time = time.time()
69+
try:
70+
with open(log_path, "wb+") as log_file:
71+
while True:
72+
if container.status in ["exited", "dead"]:
73+
logger.info(f"Container {container.short_id} has stopped. Exiting log stream.")
74+
return
75+
try:
76+
for chunk in container.logs(stream=True):
77+
if chunk:
78+
log_file.write(chunk)
79+
log_file.flush()
80+
start_time = time.time()
81+
retry_count = 0
82+
else:
83+
if time.time() - start_time > 5:
84+
logger.warning(f"Log stream timeout for container {container.short_id}")
85+
return
86+
except (APIError, IOError) as e:
87+
retry_count += 1
88+
if retry_count >= 5:
89+
logger.error(f"Max retries reached for container {container.short_id}. Exiting log stream.")
90+
return
91+
time.sleep(0.2)
92+
except Exception as e:
93+
return
94+
except Exception as e:
95+
logger.error(f"Failed to set up logging for container {container.short_id}: {e}")
6996

7097
def generate_ports(self, base_port=None, count=5):
7198
if base_port is None:

0 commit comments

Comments
 (0)