fixes in docker and go files

This commit is contained in:
KM-DB 2025-09-25 12:51:56 +03:00
parent a539b6ff2d
commit 52adbf75e3
6 changed files with 77 additions and 308 deletions

View File

@ -16,22 +16,37 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
### Fixed ### Fixed
## [0.50.0] - 2025-09-23 ## [0.51.0] - 2025-01-25
### Added ### Added
- Comprehensive Docker support with multi-container orchestration
- Docker Compose configuration for 4-node network (bootstrap + 3 nodes + gateway)
- Individual YAML configuration files for each Docker container
- Windows Docker setup documentation (WINDOWS_DOCKER_SETUP.md)
- Environment variable support for CLI bootstrap peer configuration
- Support for BOOTSTRAP_PEERS and DEBROS_BOOTSTRAP_PEERS environment variables
### Changed ### Changed
### Deprecated - Updated docker-compose.yml to use YAML config files instead of environment variables
- Enhanced CLI bootstrap flag to respect proper configuration precedence
- Improved node configuration loading with YAML file support restoration
- Updated gateway configuration to use proper bootstrap peer multiaddr format
### Removed ### Fixed
- Fixed critical CLI bootstrap flag bug where --bootstrap flag was parsed but ignored
- Corrected configuration precedence order: YAML < Environment Variables < Flags
- Fixed Docker container networking and peer discovery
- Resolved CLI bootstrap peer override logic to only apply when explicitly set
## [0.50.1] - 2025-09-23
### Fixed ### Fixed
- Fixed wrong URL /v1/db to /v1/rqlite - Fixed wrong URL /v1/db to /v1/rqlite
### Security
## [0.50.0] - 2025-09-23 ## [0.50.0] - 2025-09-23
### Added ### Added

View File

@ -27,7 +27,7 @@ COPY . .
# Build only node and gateway executables (CLI is built separately on host) # Build only node and gateway executables (CLI is built separately on host)
RUN mkdir -p bin && \ RUN mkdir -p bin && \
go build -ldflags "-X 'main.version=0.50.1-beta' -X 'main.commit=unknown' -X 'main.date=2025-09-23T15:40:00Z'" -o bin/node ./cmd/node && \ go build -ldflags "-X 'main.version=0.50.1-beta' -X 'main.commit=unknown' -X 'main.date=2025-09-23T15:40:00Z'" -o bin/node ./cmd/node && \
go build -ldflags "-X 'main.version=0.50.1-beta' -X 'main.commit=unknown' -X 'main.date=2025-09-23T15:40:00Z' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=0.50.1-beta' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=unknown' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=2025-09-23T15:40:00Z'" -o bin/gateway ./cmd/gateway go build -ldflags "-X 'main.version=0.50.1-beta' -X 'main.commit=unknown' -X 'main.date=2025-09-23T15:40:00Z' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildVersion=0.51.1-beta' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildCommit=unknown' -X 'github.com/DeBrosOfficial/network/pkg/gateway.BuildTime=2025-09-23T15:40:00Z'" -o bin/gateway ./cmd/gateway
# Stage 2: Runtime stage # Stage 2: Runtime stage
FROM alpine:latest FROM alpine:latest

View File

@ -1,250 +0,0 @@
# DeBros Network - Windows Docker Setup Guide
Simple step-by-step guide to run the DeBros Network locally on Windows using Docker.
## Prerequisites
**Docker Desktop for Windows** - Must be installed and running
**PowerShell** - Comes with Windows
**Git** - For cloning the repository
## Step 1: Clone and Build
```powershell
# Clone the repository
git clone https://github.com/DeBrosOfficial/network.git
cd network
# Build the CLI for local testing
go build -ldflags "-X 'main.version=0.50.1-beta'" -o bin/network-cli.exe cmd/cli/main.go
```
## Step 2: Start the Docker Network
```powershell
# Start all services (this will take 1-2 minutes)
docker-compose up -d
# Check that all containers are running
docker-compose ps
```
**Expected output:** 4 containers running:
- `debros-bootstrap` (Bootstrap Node)
- `debros-node-2` (Node 2)
- `debros-node-3` (Node 3)
- `debros-gateway` (HTTP Gateway)
## Step 3: Wait for Network Initialization
```powershell
# Wait for all services to start up
Start-Sleep -Seconds 30
# Verify bootstrap node is running
docker logs debros-bootstrap --tail 5
```
**Look for:** `"current_peers": 2` (means node-2 and node-3 connected)
## Step 4: Setup CLI Environment
```powershell
# Set these environment variables (required for every new terminal)
$env:DEBROS_GATEWAY_URL="http://localhost:6001"
$BOOTSTRAP_PEER="/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr"
```
## Step 5: Test the Network
### Basic Health Check
```powershell
# Check if network is healthy
.\bin\network-cli.exe health --bootstrap $BOOTSTRAP_PEER
```
**Expected:** `Status: 🟢 healthy`
### View Connected Peers
```powershell
# List connected peers
.\bin\network-cli.exe peers --bootstrap $BOOTSTRAP_PEER
```
**Expected:** 2 peers (your CLI + bootstrap node) - **This is normal!**
### Test Messaging (Requires Authentication)
```powershell
# Send a message (first time will prompt for wallet authentication)
.\bin\network-cli.exe pubsub publish test-topic "Hello DeBros Network!" --bootstrap $BOOTSTRAP_PEER
# Listen for messages (in another terminal)
.\bin\network-cli.exe pubsub subscribe test-topic 10s --bootstrap $BOOTSTRAP_PEER
```
### Test Database (Requires Authentication)
```powershell
# Query the database
.\bin\network-cli.exe query "SELECT * FROM namespaces" --bootstrap $BOOTSTRAP_PEER
```
## Network Architecture
Your local network consists of:
```
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Bootstrap │◄──►│ Node-2 │◄──►│ Node-3 │
│ localhost:4001 │ │ localhost:4002 │ │ localhost:4003 │
│ localhost:5001 │ │ localhost:5002 │ │ localhost:5003 │
└─────────────────┘ └──────────────────┘ └─────────────────┘
┌─────────────────┐ ┌──────────────────┐
│ CLI Client │ │ Gateway │
│ (Your Terminal) │ │ localhost:6001 │
└─────────────────┘ └──────────────────┘
```
**Ports Used:**
- **4001-4003**: P2P communication between nodes
- **5001-5003**: Database HTTP API
- **6001**: Gateway HTTP API
- **7001-7003**: Database internal communication
## Daily Usage Commands
### Start Your Development Session
```powershell
# Start the network
docker-compose up -d
# Setup environment (run in every new terminal)
$env:DEBROS_GATEWAY_URL="http://localhost:6001"
$BOOTSTRAP_PEER="/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr"
# Quick health check
.\bin\network-cli.exe health --bootstrap $BOOTSTRAP_PEER
```
### Common CLI Commands
```powershell
# Network status
.\bin\network-cli.exe status --bootstrap $BOOTSTRAP_PEER
# Send message
.\bin\network-cli.exe pubsub publish my-topic "Hello Network!" --bootstrap $BOOTSTRAP_PEER
# Listen for messages
.\bin\network-cli.exe pubsub subscribe my-topic 15s --bootstrap $BOOTSTRAP_PEER
# Database query
.\bin\network-cli.exe query "SELECT datetime('now') as current_time" --bootstrap $BOOTSTRAP_PEER
# List all database tables
.\bin\network-cli.exe query "SELECT name FROM sqlite_master WHERE type='table'" --bootstrap $BOOTSTRAP_PEER
```
### End Your Development Session
```powershell
# Stop network (keeps all data)
docker-compose stop
# OR stop and remove all data (clean slate)
docker-compose down -v
```
## Troubleshooting
### Check Container Status
```powershell
# View all containers
docker-compose ps
# Check specific container logs
docker logs debros-bootstrap --tail 20
docker logs debros-gateway --tail 20
docker logs debros-node-2 --tail 20
```
### Common Issues and Solutions
**❌ "Connection refused" error**
```powershell
# Solution: Check containers are running and wait longer
docker-compose ps
Start-Sleep -Seconds 60
```
**❌ "Authentication failed"**
```powershell
# Solution: Check gateway is running
docker logs debros-gateway --tail 10
```
**❌ Only seeing 2 peers instead of 4**
```
✅ This is NORMAL! The CLI only sees itself + bootstrap node.
Node-2 and Node-3 are connected to bootstrap but not visible to CLI.
Your network is working correctly!
```
### Restart Services
```powershell
# Restart all services
docker-compose restart
# Restart specific service
docker-compose restart bootstrap-node
# Complete clean restart
docker-compose down -v
docker-compose up -d
```
### View Real-time Logs
```powershell
# Follow logs for all services
docker-compose logs -f
# Follow logs for specific service
docker-compose logs -f bootstrap-node
```
## Important Notes
### Authentication
- First CLI command will prompt you to connect your wallet
- You'll receive an API key for future commands
- API key is stored locally and reused automatically
### Network Isolation
- **Your Docker Network**: Completely isolated for development
- **Production Network**: Live DeBros Network (separate)
- **Default CLI**: Connects to production (without `--bootstrap` flag)
- **CLI with `--bootstrap`**: Connects to your local Docker network
### Data Persistence
- All data is stored in Docker volumes
- Survives container restarts
- Use `docker-compose down -v` to reset everything
## Quick Reference Card
```powershell
# Essential daily commands
docker-compose up -d # Start
$env:DEBROS_GATEWAY_URL="http://localhost:6001" # Setup
$BOOTSTRAP_PEER="/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr"
.\bin\network-cli.exe health --bootstrap $BOOTSTRAP_PEER # Test
docker-compose down # Stop
```
---
🎉 **Your local DeBros Network is ready for development and testing!**
The network is completely isolated from production and perfect for:
- Testing new features
- Learning the DeBros Network
- Developing applications
- Experimenting safely

View File

@ -19,10 +19,11 @@ import (
) )
var ( var (
bootstrapPeer = "/ip4/127.0.0.1/tcp/4001" bootstrapPeer = "/ip4/127.0.0.1/tcp/4001"
timeout = 30 * time.Second bootstrapPeerSet = false // Track if bootstrap peer was explicitly set via flag
format = "table" timeout = 30 * time.Second
useProduction = false format = "table"
useProduction = false
) )
// version metadata populated via -ldflags at build time // version metadata populated via -ldflags at build time
@ -93,6 +94,7 @@ func parseGlobalFlags(args []string) {
case "-b", "--bootstrap": case "-b", "--bootstrap":
if i+1 < len(args) { if i+1 < len(args) {
bootstrapPeer = args[i+1] bootstrapPeer = args[i+1]
bootstrapPeerSet = true // Mark as explicitly set
} }
case "-f", "--format": case "-f", "--format":
if i+1 < len(args) { if i+1 < len(args) {
@ -412,10 +414,18 @@ func handlePeerID() {
} }
func createClient() (client.NetworkClient, error) { func createClient() (client.NetworkClient, error) {
// Start with default config (includes YAML/config defaults)
config := client.DefaultClientConfig("network-cli") config := client.DefaultClientConfig("network-cli")
// Override bootstrap peers if specified via flag // Apply environment variable overrides (precedence: YAML < Env < Flags)
if bootstrapPeer != "/ip4/127.0.0.1/tcp/4001" { if envPeers := os.Getenv("BOOTSTRAP_PEERS"); envPeers != "" {
config.BootstrapPeers = strings.Fields(strings.ReplaceAll(envPeers, ",", " "))
} else if envPeers := os.Getenv("DEBROS_BOOTSTRAP_PEERS"); envPeers != "" {
config.BootstrapPeers = strings.Fields(strings.ReplaceAll(envPeers, ",", " "))
}
// Apply flag overrides (highest precedence)
if bootstrapPeerSet {
config.BootstrapPeers = []string{bootstrapPeer} config.BootstrapPeers = []string{bootstrapPeer}
} }

View File

@ -49,8 +49,42 @@ func parse_and_return_network_flags() (configPath *string, dataDir, nodeID *stri
logger.Info("Successfully parsed all flags and arguments.") logger.Info("Successfully parsed all flags and arguments.")
// Always return the parsed command line flags if *configPath != "" {
// Config file loading will be handled separately in main() cfg, err := LoadConfigFromYAML(*configPath)
if err != nil {
logger.Error("Failed to load config from YAML", zap.Error(err))
os.Exit(1)
}
logger.ComponentInfo(logging.ComponentNode, "Configuration loaded from YAML file", zap.String("path", *configPath))
// Instead of returning flag values, return config values
// For ListenAddresses, extract port from multiaddr string if possible, else use default
var p2pPortVal int
if len(cfg.Node.ListenAddresses) > 0 {
// Try to parse port from multiaddr string
var port int
_, err := fmt.Sscanf(cfg.Node.ListenAddresses[0], "/ip4/0.0.0.0/tcp/%d", &port)
if err == nil {
p2pPortVal = port
} else {
p2pPortVal = 4001
}
} else {
p2pPortVal = 4001
}
return configPath,
&cfg.Node.DataDir,
&cfg.Node.ID,
&p2pPortVal,
&cfg.Database.RQLitePort,
&cfg.Database.RQLiteRaftPort,
&cfg.Database.RQLiteJoinAddress,
&cfg.Discovery.HttpAdvAddress,
&cfg.Discovery.HttpAdvAddress, // Using HttpAdvAddress for httpAdvAddr
&cfg.Discovery.RaftAdvAddress,
help
}
return return
} }
@ -150,13 +184,9 @@ func load_args_into_config(cfg *config.Config, p2pPort, rqlHTTP, rqlRaft *int, r
logger.ComponentInfo(logging.ComponentNode, "Setting RQLite join address", zap.String("address", *rqlJoinAddr)) logger.ComponentInfo(logging.ComponentNode, "Setting RQLite join address", zap.String("address", *rqlJoinAddr))
} }
// Only override advertise addresses if they're not already set in config and advAddr is not the default if *advAddr != "" {
if *advAddr != "" && *advAddr != "127.0.0.1" {
cfg.Discovery.HttpAdvAddress = fmt.Sprintf("%s:%d", *advAddr, *rqlHTTP) cfg.Discovery.HttpAdvAddress = fmt.Sprintf("%s:%d", *advAddr, *rqlHTTP)
cfg.Discovery.RaftAdvAddress = fmt.Sprintf("%s:%d", *advAddr, *rqlRaft) cfg.Discovery.RaftAdvAddress = fmt.Sprintf("%s:%d", *advAddr, *rqlRaft)
logger.ComponentInfo(logging.ComponentNode, "Overriding advertise addresses",
zap.String("http_adv_addr", cfg.Discovery.HttpAdvAddress),
zap.String("raft_adv_addr", cfg.Discovery.RaftAdvAddress))
} }
if *dataDir != "" { if *dataDir != "" {

View File

@ -15,13 +15,6 @@ services:
- bootstrap_data:/app/data - bootstrap_data:/app/data
- ./configs:/app/configs:ro - ./configs:/app/configs:ro
- bootstrap_logs:/app/logs - bootstrap_logs:/app/logs
environment:
- NODE_ID=bootstrap
- P2P_PORT=4001
- RQLITE_PORT=5001
- RQLITE_RAFT_PORT=7001
- DATA_DIR=/app/data/bootstrap
- LOG_LEVEL=info
networks: networks:
- debros-network - debros-network
restart: unless-stopped restart: unless-stopped
@ -37,7 +30,7 @@ services:
build: . build: .
container_name: debros-node-2 container_name: debros-node-2
hostname: node-2 hostname: node-2
command: ["./bin/node", "--config", "/app/configs/node.docker.yaml"] command: ["./bin/node", "--config", "/app/configs/node-2.docker.yaml"]
ports: ports:
- "4002:4001" # LibP2P P2P (mapped to different host port) - "4002:4001" # LibP2P P2P (mapped to different host port)
- "5002:5001" # RQLite HTTP API - "5002:5001" # RQLite HTTP API
@ -46,17 +39,6 @@ services:
- node2_data:/app/data - node2_data:/app/data
- ./configs:/app/configs:ro - ./configs:/app/configs:ro
- node2_logs:/app/logs - node2_logs:/app/logs
environment:
- NODE_ID=node-2
- P2P_PORT=4001
- RQLITE_PORT=5001
- RQLITE_RAFT_PORT=7001
- RQLITE_JOIN_ADDRESS=bootstrap-node:7001
- BOOTSTRAP_PEERS=/ip4/172.20.0.2/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr
- DATA_DIR=/app/data/node2
- LOG_LEVEL=info
- HTTP_ADV_ADDRESS=node-2:5001
- RAFT_ADV_ADDRESS=node-2:7001
networks: networks:
- debros-network - debros-network
depends_on: depends_on:
@ -75,7 +57,7 @@ services:
build: . build: .
container_name: debros-node-3 container_name: debros-node-3
hostname: node-3 hostname: node-3
command: ["./bin/node", "--config", "/app/configs/node.docker.yaml"] command: ["./bin/node", "--config", "/app/configs/node-3.docker.yaml"]
ports: ports:
- "4003:4001" # LibP2P P2P - "4003:4001" # LibP2P P2P
- "5003:5001" # RQLite HTTP API - "5003:5001" # RQLite HTTP API
@ -84,17 +66,6 @@ services:
- node3_data:/app/data - node3_data:/app/data
- ./configs:/app/configs:ro - ./configs:/app/configs:ro
- node3_logs:/app/logs - node3_logs:/app/logs
environment:
- NODE_ID=node-3
- P2P_PORT=4001
- RQLITE_PORT=5001
- RQLITE_RAFT_PORT=7001
- RQLITE_JOIN_ADDRESS=bootstrap-node:7001
- BOOTSTRAP_PEERS=/ip4/172.20.0.2/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr
- DATA_DIR=/app/data/node3
- LOG_LEVEL=info
- HTTP_ADV_ADDRESS=node-3:5001
- RAFT_ADV_ADDRESS=node-3:7001
networks: networks:
- debros-network - debros-network
depends_on: depends_on:
@ -113,19 +84,12 @@ services:
build: . build: .
container_name: debros-gateway container_name: debros-gateway
hostname: gateway hostname: gateway
command: ["./bin/gateway", "--addr", ":6001", "--namespace", "default", "--bootstrap-peers", "/ip4/bootstrap-node/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr"] command: ["./bin/gateway", "--config", "/app/configs/gateway.docker.yaml"]
ports: ports:
- "6001:6001" # Gateway HTTP/WebSocket - "6001:6001" # Gateway HTTP/WebSocket
volumes: volumes:
- ./configs:/app/configs:ro - ./configs:/app/configs:ro
- gateway_logs:/app/logs - gateway_logs:/app/logs
environment:
- GATEWAY_ADDR=:6001
- GATEWAY_NAMESPACE=default
- GATEWAY_BOOTSTRAP_PEERS=/ip4/bootstrap-node/tcp/4001/p2p/12D3KooWQX6jcPTVSsBuVuxdkbMbau3DAqZT4pc7UgGh2FvDxrKr
- RQLITE_NODES=http://bootstrap-node:5001
- RQLITE_DSN=http://bootstrap-node:5001
- LOG_LEVEL=info
networks: networks:
- debros-network - debros-network
depends_on: depends_on: