Compare commits

...

10 Commits

Author SHA1 Message Date
anonpenguin
f936c5bcde bug fixes
Some checks failed
Publish Alpha Package to npm / publish (push) Has been cancelled
2025-04-09 01:42:07 +03:00
anonpenguin
8e32807361 fixed script keys error 2025-04-08 14:43:01 +03:00
anonpenguin
e01bd81e1a updated docker compose 2025-04-08 14:39:01 +03:00
anonpenguin
2c11acaeca updated script and healthService error 2025-04-08 14:32:04 +03:00
anonpenguin
bc66822c8b updated install script 2025-04-08 14:28:19 +03:00
anonpenguin
f81171c2fe updated network version and bug fixes 2025-04-08 14:22:23 +03:00
anonpenguin
84de28793d updated install script bootstrap nodes 2025-04-08 13:37:19 +03:00
anonpenguin
e9f9e53fd9 updated installed script ufw settings 2025-04-08 11:21:14 +03:00
anonpenguin
7709c95c3a updated script to check of cgroup 2025-04-08 11:00:55 +03:00
anonpenguin
c31e683b8f updated version 2025-04-08 10:35:18 +03:00
13 changed files with 936 additions and 32 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ radata/
dist/ dist/
blockstore/ blockstore/
orbitdb/ orbitdb/
keys/
swarm.key swarm.key
.DS_Store .DS_Store
bin/ bin/

View File

@ -1,13 +1,35 @@
# Installation # Installation
## Run this script: ## Production Installation
Run this script for production deployment:
```bash ```bash
sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/DeBrosOfficial/node/refs/heads/main/scripts/install.sh)" sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/DeBrosOfficial/node/refs/heads/main/scripts/install.sh)"
``` ```
## Local Development
For local development, we have a streamlined workflow:
```bash
# Clone the repository
git clone https://github.com/DeBrosOfficial/node.git
cd node
# Start the development environment
./scripts/start-dev.sh
```
This will:
1. Automatically generate a `.env` file if it doesn't exist
2. Create development keys in the `keys/` directory
3. Start the Docker Compose development environment
## Stop and Clean (optional for debugging) ## Stop and Clean (optional for debugging)
### Production
```bash ```bash
#!/bin/bash #!/bin/bash
@ -15,3 +37,13 @@ sudo systemctl stop debros-node
sudo rm -rf /opt/debros-node sudo rm -rf /opt/debros-node
docker system prune -a docker system prune -a
``` ```
### Development
```bash
# Stop containers
docker-compose -f docker-compose.dev.yml down
# Clean environment (optional)
rm -rf ./keys ./.env ./orbitdb ./blockstore ./logs
```

View File

@ -10,10 +10,13 @@ services:
volumes: volumes:
- ./orbitdb:/app/orbitdb - ./orbitdb:/app/orbitdb
- ./blockstore:/app/blockstore - ./blockstore:/app/blockstore
- ./keys:/app/keys
- ./.env:/app/.env - ./.env:/app/.env
- ./terms-agreement:/app/terms-agreement - ./terms-agreement:/app/terms-agreement
- ./logs:/app/logs
environment: environment:
- PORT=7777 - PORT=7777
- NODE_ENV=development
# Add other environment variables if needed # Add other environment variables if needed
networks: networks:
- debros-network - debros-network

View File

@ -14,6 +14,7 @@ services:
- ./.env:/app/.env - ./.env:/app/.env
- ./terms-agreement:/app/terms-agreement - ./terms-agreement:/app/terms-agreement
- /var/lib/debros/keys:/var/lib/debros/keys - /var/lib/debros/keys:/var/lib/debros/keys
- ./logs:/app/logs
environment: environment:
- PORT=7777 - PORT=7777
networks: networks:

View File

@ -1,7 +1,7 @@
{ {
"name": "@debros/node", "name": "@debros/node",
"type": "module", "type": "module",
"version": "0.0.12-alpha", "version": "0.0.20-alpha",
"description": "DeBros Node", "description": "DeBros Node",
"main": "dist/index.js", "main": "dist/index.js",
"bin": "dist/cli.js", "bin": "dist/cli.js",
@ -17,7 +17,7 @@
] ]
}, },
"scripts": { "scripts": {
"dev": "npx tsx ./src/server.ts", "dev": "./scripts/start-dev.sh",
"dev:with-anyone": "npx tsx ./src/server.ts", "dev:with-anyone": "npx tsx ./src/server.ts",
"start": "NODE_ENV=production node dist/server.js", "start": "NODE_ENV=production node dist/server.js",
"lint": "npx eslint src", "lint": "npx eslint src",
@ -32,7 +32,7 @@
"dependencies": { "dependencies": {
"@anyone-protocol/anyone-client": "^0.4.4", "@anyone-protocol/anyone-client": "^0.4.4",
"@debros/cli": "^0.0.11-alpha", "@debros/cli": "^0.0.11-alpha",
"@debros/network": "^0.0.16-alpha", "@debros/network": "^0.0.22-alpha",
"@helia/unixfs": "^4.0.3", "@helia/unixfs": "^4.0.3",
"@libp2p/bootstrap": "^11.0.32", "@libp2p/bootstrap": "^11.0.32",
"@libp2p/crypto": "^5.0.15", "@libp2p/crypto": "^5.0.15",

732
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,2 +1,3 @@
packages: packages:
- 'packages/**' # - 'packages/**'
- '../network'

74
scripts/generate-dev-env.sh Executable file
View File

@ -0,0 +1,74 @@
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NOCOLOR='\033[0m'
log() {
echo -e "${CYAN}[DEV SETUP]${NOCOLOR} $1"
}
# Base directory - the project root
BASE_DIR=$(dirname "$(dirname "$(readlink -f "$0")")")
KEY_DIR="$BASE_DIR/keys"
KEY_NAME="debros_key"
# Create .env file if it doesn't exist
if [ ! -f "$BASE_DIR/.env" ]; then
log "Generating .env file for development..."
# Create keys directory
mkdir -p "$KEY_DIR"
chmod 700 "$KEY_DIR"
# Generate keypair if it doesn't exist
if [ ! -f "$KEY_DIR/$KEY_NAME" ]; then
log "Creating new key pair..."
ssh-keygen -t ed25519 -f "$KEY_DIR/$KEY_NAME" -N "" -q
log "${GREEN}Keys created in $KEY_DIR${NOCOLOR}"
fi
# Calculate fingerprint
FINGERPRINT=$(ssh-keygen -l -f "$KEY_DIR/$KEY_NAME.pub" 2>/dev/null | awk '{print $2}' | sed 's/SHA256://' | base64 -d 2>/dev/null | xxd -p -u | tr -d '\n' | head -c 40)
# Default dev values
NICKNAME="dev_node"
ADMIN_WALLET="devWallet123456789"
# Create the .env file with development settings
cat > "$BASE_DIR/.env" << EOF
NICKNAME=$NICKNAME
FINGERPRINT=$FINGERPRINT
NODE_ENV=development
PORT=7777
ENABLE_ANYONE=true
HOSTNAME=localhost
ADMIN_WALLET=$ADMIN_WALLET
ENABLE_LOAD_BALANCING=true
SERVICE_DISCOVERY_TOPIC=debros-service-discovery
HEARTBEAT_INTERVAL=5000
STALE_PEER_TIMEOUT=30000
PEER_LOG_INTERVAL=60000
NODE_PUBLIC_ADDRESS=localhost
BOOTSTRAP_NODES=/ip4/188.166.113.190/tcp/7778/p2p/12D3KooWNWgs4WAUmE4CsxrL6uuyv1yuTzcRReMe5r7Psemsg2Z9,/ip4/82.208.21.140/tcp/7778/p2p/12D3KooWPUdpNX5N6dsuFAvgwfBMXUoFK2QS5sh8NpjxbfGpkSCi
MAX_CONNECTIONS=1000
LOAD_BALANCING_STRATEGY=least-loaded
ACCEPT_TERMS=true
KEY_PATH=./keys
LIBP2P_DEBUG=true
IPFS_DEBUG=true
LOG_LEVEL=debug
DEBUG=libp2p:*
EOF
log "${GREEN}Development .env file created successfully${NOCOLOR}"
log "Keys location: $KEY_DIR"
else
log "${GREEN}Development .env file already exists${NOCOLOR}"
fi
# Make the script executable
chmod +x "$0"
log "${GREEN}Development environment setup complete${NOCOLOR}"

View File

@ -175,19 +175,25 @@ else
sudo apt-get install -y ufw sudo apt-get install -y ufw
fi fi
log "${GREEN}Configuring firewall...${NOCOLOR}" # Capture the initial state of ufw
UFW_INITIAL_STATUS=$(sudo ufw status | grep -o "Status: [a-z]*" | awk '{print $2}')
log "${GREEN}Configuring firewall rules...${NOCOLOR}"
sudo ufw allow 7777 sudo ufw allow 7777
sudo ufw allow 7778 sudo ufw allow 7778
if [[ $(sudo ufw status) =~ "inactive" ]]; then # Only enable ufw if it was already active
log "${GREEN}Enabling firewall...${NOCOLOR}" if [[ "$UFW_INITIAL_STATUS" == "active" ]]; then
log "${GREEN}Ensuring firewall remains enabled...${NOCOLOR}"
echo "y" | sudo ufw enable echo "y" | sudo ufw enable
else
log "${GREEN}Firewall rules added, but not enabling UFW as it was initially inactive.${NOCOLOR}"
fi fi
log "${GREEN}Firewall configured successfully.${NOCOLOR}" log "${GREEN}Firewall configuration completed.${NOCOLOR}"
fi fi
KEY_DIR="/var/lib/debros/keys" KEY_DIR="/opt/debros/keys"
KEY_NAME="debros_key" KEY_NAME="debros_key"
if [ ! -d "$KEY_DIR" ]; then if [ ! -d "$KEY_DIR" ]; then
log "${CYAN}Creating folder $KEY_DIR...${NOCOLOR}" log "${CYAN}Creating folder $KEY_DIR...${NOCOLOR}"
@ -269,6 +275,62 @@ EOF
fi fi
fi fi
# Check if running on Raspberry Pi and enable cgroups if needed
check_and_enable_cgroups() {
# Detect Raspberry Pi by checking /proc/cpuinfo
if grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then
log "${CYAN}Detected Raspberry Pi hardware.${NOCOLOR}"
# Check if cmdline.txt exists in either location
CMDLINE_FILE=""
if [ -f "/boot/firmware/cmdline.txt" ]; then
CMDLINE_FILE="/boot/firmware/cmdline.txt"
elif [ -f "/boot/cmdline.txt" ]; then
CMDLINE_FILE="/boot/cmdline.txt"
else
log "${RED}Error: Could not locate cmdline.txt for Raspberry Pi.${NOCOLOR}"
exit 1
fi
# Check if cgroups are already enabled
if ! grep -q "cgroup_enable=memory" "$CMDLINE_FILE" || ! grep -q "cgroup_memory=1" "$CMDLINE_FILE"; then
log "${YELLOW}Memory cgroups not enabled. Updating $CMDLINE_FILE...${NOCOLOR}"
# Backup the original cmdline.txt
sudo cp "$CMDLINE_FILE" "$CMDLINE_FILE.backup" || {
log "${RED}Failed to backup $CMDLINE_FILE${NOCOLOR}"
exit 1
}
# Append cgroup parameters if not present
CURRENT_CMDLINE=$(cat "$CMDLINE_FILE")
NEW_CMDLINE="$CURRENT_CMDLINE cgroup_enable=memory cgroup_memory=1"
echo "$NEW_CMDLINE" | sudo tee "$CMDLINE_FILE" > /dev/null || {
log "${RED}Failed to update $CMDLINE_FILE${NOCOLOR}"
exit 1
}
log "${GREEN}Updated $CMDLINE_FILE with cgroup settings.${NOCOLOR}"
log "${YELLOW}A reboot is required to apply these changes.${NOCOLOR}"
read -rp "Reboot now? (yes/no) [Default: yes]: " REBOOT_CHOICE
REBOOT_CHOICE="${REBOOT_CHOICE:-yes}"
if [[ "$REBOOT_CHOICE" == "yes" ]]; then
log "${CYAN}Rebooting system...${NOCOLOR}"
sudo reboot
else
log "${CYAN}Please reboot manually to apply changes before continuing.${NOCOLOR}"
exit 0
fi
else
log "${GREEN}Memory cgroups already enabled in $CMDLINE_FILE.${NOCOLOR}"
fi
fi
}
# Call the function before K3s installation
check_and_enable_cgroups
# Ask about K3s installation # Ask about K3s installation
if ! command -v k3s &> /dev/null; then if ! command -v k3s &> /dev/null; then
log "${GREEN}- Would you like to install K3s for container orchestration?${NOCOLOR}" log "${GREEN}- Would you like to install K3s for container orchestration?${NOCOLOR}"
@ -353,8 +415,13 @@ log "${BLUE}==================================================${NOCOLOR}"
log "${GREEN}Installation directory: ${NOCOLOR}${CYAN}$INSTALL_DIR${NOCOLOR}" log "${GREEN}Installation directory: ${NOCOLOR}${CYAN}$INSTALL_DIR${NOCOLOR}"
log "${BLUE}==================================================${NOCOLOR}" log "${BLUE}==================================================${NOCOLOR}"
# Information about the DeBros CLI
log "${BLUE}==================================================${NOCOLOR}" log "${BLUE}==================================================${NOCOLOR}"
log "${GREEN}Installation Notes:${NOCOLOR}"
log "${CYAN}If you were prompted to reboot earlier (e.g., for Raspberry Pi cgroups),${NOCOLOR}"
log "${CYAN}please rerun this script after rebooting to finish the installation.${NOCOLOR}"
log "${BLUE}==================================================${NOCOLOR}"
# Information about the DeBros CLI
log "${GREEN}DeBros CLI Information:${NOCOLOR}" log "${GREEN}DeBros CLI Information:${NOCOLOR}"
log "${CYAN}The DeBros CLI is a tool that runs on your local development machine,${NOCOLOR}" log "${CYAN}The DeBros CLI is a tool that runs on your local development machine,${NOCOLOR}"
log "${CYAN}not on the node itself. To install it on your development machine, run:${NOCOLOR}" log "${CYAN}not on the node itself. To install it on your development machine, run:${NOCOLOR}"

10
scripts/start-dev.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# Navigate to project root
cd "$(dirname "$(dirname "$(readlink -f "$0")")")"
# Generate development environment if needed
./scripts/generate-dev-env.sh
# Start the development container
docker-compose -f docker-compose.dev.yml up --build

View File

@ -9,7 +9,7 @@ export const registerHealthEndpoints = (app: express.Application) => {
// Health check endpoint that also reports node load and peers // Health check endpoint that also reports node load and peers
app.get('/health', (req, res) => { app.get('/health', (req, res) => {
const connectedPeers = getConnectedPeers(); const connectedPeers = getConnectedPeers();
const peerCount = connectedPeers.length; const peerCount = connectedPeers.size;
res.json({ res.json({
status: 'healthy', status: 'healthy',
@ -28,7 +28,7 @@ export const startStatusReporting = (interval = 600000) => {
// Schedule a status report every 10 minutes // Schedule a status report every 10 minutes
return setInterval(() => { return setInterval(() => {
const connectedPeers = getConnectedPeers(); const connectedPeers = getConnectedPeers();
const peerCount = connectedPeers.length; const peerCount = connectedPeers.size;
console.log('==== DEBROS STATUS REPORT ===='); console.log('==== DEBROS STATUS REPORT ====');
console.log(`📊 Fingerprint: ${config.env.fingerprint}`); console.log(`📊 Fingerprint: ${config.env.fingerprint}`);
@ -42,7 +42,7 @@ export const startStatusReporting = (interval = 600000) => {
console.log('CONNECTED PEERS:'); console.log('CONNECTED PEERS:');
connectedPeers.forEach((peer, i) => { connectedPeers.forEach((peer, i) => {
// Adjust based on your peer structure from the new @debros/network // Adjust based on your peer structure from the new @debros/network
const peerId = peer.id || peer.toString(); const peerId = peer.fingerprint || peer.toString();
const load = peer.load || 'unknown'; const load = peer.load || 'unknown';
console.log(`${i + 1}. ${peerId.substring(0, 15)}... - Load: ${load}%`); console.log(`${i + 1}. ${peerId.substring(0, 15)}... - Load: ${load}%`);
}); });

View File

@ -1,6 +1,6 @@
import express from 'express'; import express from 'express';
import { createServer } from 'http'; import { createServer } from 'http';
import { initIpfs, stopIpfs, initOrbitDB, createServiceLogger, logPeersStatus } from '@debros/network'; // Import from the new package import network, { createServiceLogger, logPeersStatus } from '@debros/network'; // Import from the new package
import mainRouter from '../../routes/api'; import mainRouter from '../../routes/api';
import { applyMiddleware } from './middleware'; import { applyMiddleware } from './middleware';
import { registerHealthEndpoints, startStatusReporting } from './healthService'; import { registerHealthEndpoints, startStatusReporting } from './healthService';
@ -34,10 +34,9 @@ export const startServer = async () => {
anonInstance = anon; anonInstance = anon;
// Initialize IPFS with the new package // Initialize IPFS with the new package
await initIpfs();
// Initialize OrbitDB with the new package // Initialize OrbitDB with the new package
orbitdbInstance = await initOrbitDB(); orbitdbInstance = await network.db.init()
// Create and configure Express app // Create and configure Express app
const app = createApp(); const app = createApp();
@ -103,15 +102,10 @@ function setupShutdownHandler(
clearInterval(intervals.statusReportInterval); clearInterval(intervals.statusReportInterval);
clearInterval(intervals.peerStatusInterval); clearInterval(intervals.peerStatusInterval);
// Stop OrbitDB
serverLogger.info('Stopping OrbitDB...');
await orbitdbInstance.stop();
serverLogger.info('OrbitDB stopped.');
// Stop IPFS // Stop IPFS
serverLogger.info('Stopping IPFS...'); serverLogger.info('Stopping Network...');
await stopIpfs(); await network.db.stop();
serverLogger.info('IPFS stopped.'); serverLogger.info('Network stopped.');
// Stop Anyone // Stop Anyone
if (anonInstance) { if (anonInstance) {

View File

@ -1,4 +1,7 @@
import path from 'path'; import path from 'path';
import dotenv from 'dotenv'
dotenv.config();
export const config = { export const config = {
env: { env: {