Compare commits
10 Commits
c6663af810
...
f936c5bcde
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f936c5bcde | ||
![]() |
8e32807361 | ||
![]() |
e01bd81e1a | ||
![]() |
2c11acaeca | ||
![]() |
bc66822c8b | ||
![]() |
f81171c2fe | ||
![]() |
84de28793d | ||
![]() |
e9f9e53fd9 | ||
![]() |
7709c95c3a | ||
![]() |
c31e683b8f |
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ radata/
|
||||
dist/
|
||||
blockstore/
|
||||
orbitdb/
|
||||
keys/
|
||||
swarm.key
|
||||
.DS_Store
|
||||
bin/
|
||||
|
34
README.md
34
README.md
@ -1,13 +1,35 @@
|
||||
# Installation
|
||||
|
||||
## Run this script:
|
||||
## Production Installation
|
||||
|
||||
Run this script for production deployment:
|
||||
|
||||
```bash
|
||||
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)
|
||||
|
||||
### Production
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
|
||||
@ -15,3 +37,13 @@ sudo systemctl stop debros-node
|
||||
sudo rm -rf /opt/debros-node
|
||||
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
|
||||
```
|
||||
|
@ -10,10 +10,13 @@ services:
|
||||
volumes:
|
||||
- ./orbitdb:/app/orbitdb
|
||||
- ./blockstore:/app/blockstore
|
||||
- ./keys:/app/keys
|
||||
- ./.env:/app/.env
|
||||
- ./terms-agreement:/app/terms-agreement
|
||||
- ./logs:/app/logs
|
||||
environment:
|
||||
- PORT=7777
|
||||
- NODE_ENV=development
|
||||
# Add other environment variables if needed
|
||||
networks:
|
||||
- debros-network
|
||||
|
@ -14,6 +14,7 @@ services:
|
||||
- ./.env:/app/.env
|
||||
- ./terms-agreement:/app/terms-agreement
|
||||
- /var/lib/debros/keys:/var/lib/debros/keys
|
||||
- ./logs:/app/logs
|
||||
environment:
|
||||
- PORT=7777
|
||||
networks:
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@debros/node",
|
||||
"type": "module",
|
||||
"version": "0.0.12-alpha",
|
||||
"version": "0.0.20-alpha",
|
||||
"description": "DeBros Node",
|
||||
"main": "dist/index.js",
|
||||
"bin": "dist/cli.js",
|
||||
@ -17,7 +17,7 @@
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npx tsx ./src/server.ts",
|
||||
"dev": "./scripts/start-dev.sh",
|
||||
"dev:with-anyone": "npx tsx ./src/server.ts",
|
||||
"start": "NODE_ENV=production node dist/server.js",
|
||||
"lint": "npx eslint src",
|
||||
@ -32,7 +32,7 @@
|
||||
"dependencies": {
|
||||
"@anyone-protocol/anyone-client": "^0.4.4",
|
||||
"@debros/cli": "^0.0.11-alpha",
|
||||
"@debros/network": "^0.0.16-alpha",
|
||||
"@debros/network": "^0.0.22-alpha",
|
||||
"@helia/unixfs": "^4.0.3",
|
||||
"@libp2p/bootstrap": "^11.0.32",
|
||||
"@libp2p/crypto": "^5.0.15",
|
||||
|
732
pnpm-lock.yaml
generated
732
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,3 @@
|
||||
packages:
|
||||
- 'packages/**'
|
||||
# - 'packages/**'
|
||||
- '../network'
|
||||
|
74
scripts/generate-dev-env.sh
Executable file
74
scripts/generate-dev-env.sh
Executable 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}"
|
@ -175,19 +175,25 @@ else
|
||||
sudo apt-get install -y ufw
|
||||
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 7778
|
||||
|
||||
if [[ $(sudo ufw status) =~ "inactive" ]]; then
|
||||
log "${GREEN}Enabling firewall...${NOCOLOR}"
|
||||
# Only enable ufw if it was already active
|
||||
if [[ "$UFW_INITIAL_STATUS" == "active" ]]; then
|
||||
log "${GREEN}Ensuring firewall remains enabled...${NOCOLOR}"
|
||||
echo "y" | sudo ufw enable
|
||||
else
|
||||
log "${GREEN}Firewall rules added, but not enabling UFW as it was initially inactive.${NOCOLOR}"
|
||||
fi
|
||||
|
||||
log "${GREEN}Firewall configured successfully.${NOCOLOR}"
|
||||
log "${GREEN}Firewall configuration completed.${NOCOLOR}"
|
||||
fi
|
||||
|
||||
KEY_DIR="/var/lib/debros/keys"
|
||||
KEY_DIR="/opt/debros/keys"
|
||||
KEY_NAME="debros_key"
|
||||
if [ ! -d "$KEY_DIR" ]; then
|
||||
log "${CYAN}Creating folder $KEY_DIR...${NOCOLOR}"
|
||||
@ -269,6 +275,62 @@ EOF
|
||||
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
|
||||
if ! command -v k3s &> /dev/null; then
|
||||
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 "${BLUE}==================================================${NOCOLOR}"
|
||||
|
||||
# Information about the DeBros CLI
|
||||
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 "${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}"
|
||||
|
10
scripts/start-dev.sh
Executable file
10
scripts/start-dev.sh
Executable 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
|
@ -9,7 +9,7 @@ export const registerHealthEndpoints = (app: express.Application) => {
|
||||
// Health check endpoint that also reports node load and peers
|
||||
app.get('/health', (req, res) => {
|
||||
const connectedPeers = getConnectedPeers();
|
||||
const peerCount = connectedPeers.length;
|
||||
const peerCount = connectedPeers.size;
|
||||
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
@ -28,7 +28,7 @@ export const startStatusReporting = (interval = 600000) => {
|
||||
// Schedule a status report every 10 minutes
|
||||
return setInterval(() => {
|
||||
const connectedPeers = getConnectedPeers();
|
||||
const peerCount = connectedPeers.length;
|
||||
const peerCount = connectedPeers.size;
|
||||
|
||||
console.log('==== DEBROS STATUS REPORT ====');
|
||||
console.log(`📊 Fingerprint: ${config.env.fingerprint}`);
|
||||
@ -42,7 +42,7 @@ export const startStatusReporting = (interval = 600000) => {
|
||||
console.log('CONNECTED PEERS:');
|
||||
connectedPeers.forEach((peer, i) => {
|
||||
// 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';
|
||||
console.log(`${i + 1}. ${peerId.substring(0, 15)}... - Load: ${load}%`);
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import express from 'express';
|
||||
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 { applyMiddleware } from './middleware';
|
||||
import { registerHealthEndpoints, startStatusReporting } from './healthService';
|
||||
@ -34,10 +34,9 @@ export const startServer = async () => {
|
||||
anonInstance = anon;
|
||||
|
||||
// Initialize IPFS with the new package
|
||||
await initIpfs();
|
||||
|
||||
// Initialize OrbitDB with the new package
|
||||
orbitdbInstance = await initOrbitDB();
|
||||
orbitdbInstance = await network.db.init()
|
||||
|
||||
// Create and configure Express app
|
||||
const app = createApp();
|
||||
@ -103,15 +102,10 @@ function setupShutdownHandler(
|
||||
clearInterval(intervals.statusReportInterval);
|
||||
clearInterval(intervals.peerStatusInterval);
|
||||
|
||||
// Stop OrbitDB
|
||||
serverLogger.info('Stopping OrbitDB...');
|
||||
await orbitdbInstance.stop();
|
||||
serverLogger.info('OrbitDB stopped.');
|
||||
|
||||
// Stop IPFS
|
||||
serverLogger.info('Stopping IPFS...');
|
||||
await stopIpfs();
|
||||
serverLogger.info('IPFS stopped.');
|
||||
serverLogger.info('Stopping Network...');
|
||||
await network.db.stop();
|
||||
serverLogger.info('Network stopped.');
|
||||
|
||||
// Stop Anyone
|
||||
if (anonInstance) {
|
||||
|
@ -1,4 +1,7 @@
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export const config = {
|
||||
env: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user