Skip to content

Commit eb720d4

Browse files
author
5u6r054
committed
feat: improve startup feedback and add Docker Hub sync
- Add detailed progress reporting to start.sh - Show elapsed time and service counts - Add registration status monitoring - Create workflow to sync DOCKER.md with Docker Hub
1 parent e28de83 commit eb720d4

File tree

2 files changed

+148
-30
lines changed

2 files changed

+148
-30
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Update Docker Hub Description
2+
3+
on:
4+
push:
5+
branches:
6+
- feature-docker-compose
7+
- main
8+
paths:
9+
- 'DOCKER.md'
10+
- '.github/workflows/docker-hub-description.yml'
11+
12+
jobs:
13+
docker-hub-description:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Update Docker Hub Description
20+
uses: peter-evans/dockerhub-description@v3
21+
with:
22+
username: ${{ secrets.DOCKER_USERNAME }}
23+
password: ${{ secrets.DOCKER_PASSWORD }}
24+
repository: masaengineering/masa-bittensor
25+
short-description: "MASA Bittensor miners and validators in Docker"
26+
readme-filepath: ./DOCKER.md

start.sh

Lines changed: 122 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ RED='\033[0;31m'
88
NC='\033[0m' # No Color
99
BOLD='\033[1m'
1010

11+
# Determine network details
12+
NETWORK=${NETWORK:-test}
13+
if [ "$NETWORK" = "finney" ]; then
14+
NETWORK_DISPLAY="${RED}MAIN NETWORK (FINNEY)${NC}"
15+
NETUID="42"
16+
echo -e "\n${RED}⚠️ WARNING: You are connecting to the MAIN NETWORK${NC}"
17+
echo -e "${RED} This will use real TAO. Are you sure? (y/N)${NC}"
18+
read -r response
19+
if [[ ! "$response" =~ ^[Yy]$ ]]; then
20+
echo -e "${YELLOW}Aborting. Set NETWORK=test in .env to use the test network${NC}"
21+
exit 1
22+
fi
23+
else
24+
NETWORK_DISPLAY="${GREEN}TEST NETWORK${NC}"
25+
NETUID="165"
26+
fi
27+
1128
echo -e "\n${BLUE}=== 🚀 Starting MASA Bittensor Stack ===${NC}\n"
1229

1330
# Check if .env exists
@@ -24,9 +41,10 @@ source .env
2441
set +a
2542

2643
echo -e "${BLUE}Configuration:${NC}"
44+
echo -e "• Network: ${NETWORK_DISPLAY}"
45+
echo -e "• Subnet: ${GREEN}${NETUID}${NC}"
2746
echo -e "• Miners: ${GREEN}${MINER_COUNT:-1}${NC}"
2847
echo -e "• Validators: ${GREEN}${VALIDATOR_COUNT:-0}${NC}"
29-
echo -e "• Network: ${GREEN}${NETWORK:-finney}${NC}"
3048

3149
# Initialize swarm if needed
3250
if ! docker node ls > /dev/null 2>&1; then
@@ -44,71 +62,144 @@ fi
4462
wait_for_services() {
4563
local timeout=300 # 5 minutes timeout
4664
local start_time=$(date +%s)
65+
local last_status=""
4766

4867
echo -e "\n${BLUE}Waiting for services to start...${NC}"
68+
echo -e "${YELLOW}Target: ${MINER_COUNT} miners, ${VALIDATOR_COUNT} validators${NC}\n"
4969

5070
while true; do
5171
local current_time=$(date +%s)
5272
local elapsed=$((current_time - start_time))
73+
local elapsed_min=$((elapsed / 60))
74+
local elapsed_sec=$((elapsed % 60))
5375

5476
if [ $elapsed -gt $timeout ]; then
55-
echo -e "${RED}Timeout waiting for services${NC}"
77+
echo -e "\n${RED}Timeout waiting for services${NC}"
78+
echo -e "Check logs with: ${YELLOW}docker service logs masa_miner${NC}"
5679
exit 1
5780
fi
5881

5982
# Get service status
6083
local miner_status=$(docker service ls --format '{{.Name}} {{.Replicas}}' | grep masa_miner || echo "")
6184
local validator_status=$(docker service ls --format '{{.Name}} {{.Replicas}}' | grep masa_validator || echo "")
6285

86+
# Parse current counts
87+
local miner_current=$(echo $miner_status | grep -o '[0-9]*/[0-9]*' | cut -d/ -f1 || echo "0")
88+
local miner_target=$(echo $miner_status | grep -o '[0-9]*/[0-9]*' | cut -d/ -f2 || echo "0")
89+
local validator_current=$(echo $validator_status | grep -o '[0-9]*/[0-9]*' | cut -d/ -f1 || echo "0")
90+
local validator_target=$(echo $validator_status | grep -o '[0-9]*/[0-9]*' | cut -d/ -f2 || echo "0")
91+
92+
# Prepare status message
93+
local status_msg="[${elapsed_min}m${elapsed_sec}s] "
94+
status_msg+="Miners: ${miner_current}/${miner_target}, "
95+
status_msg+="Validators: ${validator_current}/${validator_target}"
96+
97+
# Only print if status changed
98+
if [ "$status_msg" != "$last_status" ]; then
99+
echo -e "\r\033[K${status_msg}" # Clear line and print new status
100+
last_status="$status_msg"
101+
fi
102+
63103
# Check if services are ready
64104
if [[ $miner_status == *"$MINER_COUNT/$MINER_COUNT"* ]] && \
65105
[[ $validator_status == *"$VALIDATOR_COUNT/$VALIDATOR_COUNT"* ]]; then
66-
echo -e "${GREEN}${NC} All services started"
106+
echo -e "\n${GREEN}${NC} All services started successfully"
67107
return 0
68108
fi
69109

70-
echo -n "."
71-
sleep 5
110+
sleep 2
111+
done
112+
}
113+
114+
# Monitor registration status
115+
monitor_registration() {
116+
echo -e "\n${BLUE}Monitoring registration status...${NC}"
117+
echo -e "${YELLOW}This may take a few minutes while nodes register with the network${NC}\n"
118+
119+
MAX_ATTEMPTS=30
120+
ATTEMPT=0
121+
REGISTERED=false
122+
local last_status=""
123+
124+
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
125+
# Run the report script
126+
OUTPUT=$(python startup/report.py 0)
127+
128+
# Extract registration info
129+
local miner_reg=$(echo "$OUTPUT" | grep -A2 "⛏️ Miner Status" | grep "Registration:" || echo "Unknown")
130+
local validator_reg=$(echo "$OUTPUT" | grep -A2 "🔍 Validator Status" | grep "Registration:" || echo "Unknown")
131+
132+
# Prepare status message
133+
local status_msg="[Attempt ${ATTEMPT}/${MAX_ATTEMPTS}] "
134+
status_msg+="Checking registrations..."
135+
136+
# Only print if status changed
137+
if [ "$status_msg" != "$last_status" ]; then
138+
echo -e "\r\033[K${status_msg}" # Clear line and print new status
139+
140+
# Show registration status if available
141+
if [[ $miner_reg == *"Registered"* ]]; then
142+
echo -e " Miners: ${GREEN}${NC} Registered"
143+
elif [[ $miner_reg == *"Not Registered"* ]]; then
144+
echo -e " Miners: ${YELLOW}${NC} Not registered yet"
145+
fi
146+
147+
if [[ $validator_reg == *"Registered"* ]]; then
148+
echo -e " Validators: ${GREEN}${NC} Registered"
149+
elif [[ $validator_reg == *"Not Registered"* ]]; then
150+
echo -e " Validators: ${YELLOW}${NC} Not registered yet"
151+
fi
152+
153+
last_status="$status_msg"
154+
fi
155+
156+
# Check if all services are registered
157+
if echo "$OUTPUT" | grep -q "✅ All services are running and registered successfully!"; then
158+
REGISTERED=true
159+
break
160+
fi
161+
162+
ATTEMPT=$((ATTEMPT + 1))
163+
sleep 10
72164
done
165+
166+
return 0
73167
}
74168

75169
# Deploy the stack
76170
echo -e "\n${BLUE}Deploying stack...${NC}"
77171

78172
if [ -n "$DOCKER_IMAGE" ]; then
79173
echo -e "Using image: ${GREEN}${DOCKER_IMAGE}${NC}"
174+
IMAGE_TO_USE=$DOCKER_IMAGE
175+
else
176+
IMAGE_TO_USE="masaengineering/masa-bittensor:latest"
177+
echo -e "Using image: ${GREEN}${IMAGE_TO_USE}${NC}"
178+
fi
179+
180+
# Try to pull the image first
181+
echo -e "\n${BLUE}Pulling image...${NC}"
182+
if docker pull $IMAGE_TO_USE; then
183+
echo -e "${GREEN}${NC} Image pulled successfully"
80184
else
81-
echo -e "Using image: ${GREEN}masaengineering/masa-bittensor:latest${NC}"
185+
echo -e "${YELLOW}⚠️ Could not pull image. Trying to build locally...${NC}"
186+
if docker compose build; then
187+
echo -e "${GREEN}${NC} Local build successful"
188+
IMAGE_TO_USE="masa-bittensor:latest"
189+
else
190+
echo -e "${RED}Error: Failed to pull or build image${NC}"
191+
exit 1
192+
fi
82193
fi
83194

84-
docker stack deploy -c docker-compose.yml masa
195+
# Deploy with the image we got
196+
DOCKER_IMAGE=$IMAGE_TO_USE docker stack deploy -c docker-compose.yml masa
85197

86198
# Wait for services to start
87199
wait_for_services
88200

89-
# Monitor registration status
90-
echo -e "\n${BLUE}Monitoring registration status...${NC}"
91-
echo -e "${YELLOW}This may take a few minutes...${NC}\n"
92-
93-
MAX_ATTEMPTS=30
94-
ATTEMPT=0
95-
REGISTERED=false
96-
97-
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
98-
# Run the report script
99-
OUTPUT=$(python startup/report.py 0)
100-
101-
# Check if all services are registered
102-
if echo "$OUTPUT" | grep -q "✅ All services are running and registered successfully!"; then
103-
REGISTERED=true
104-
break
105-
fi
106-
107-
# Show progress
108-
echo -n "."
109-
ATTEMPT=$((ATTEMPT + 1))
110-
sleep 10
111-
done
201+
# Monitor registration
202+
monitor_registration
112203

113204
echo -e "\n\n${BLUE}=== Final Status ===${NC}\n"
114205
python startup/report.py 0
@@ -121,4 +212,5 @@ if [ "$REGISTERED" = true ]; then
121212
else
122213
echo -e "\n${YELLOW}⚠️ Setup completed but some services may still be initializing${NC}"
123214
echo -e "Run ${YELLOW}python startup/report.py${NC} later to check the status"
215+
echo -e "View logs with: ${YELLOW}docker service logs masa_miner -f${NC}"
124216
fi

0 commit comments

Comments
 (0)