Local development and testing environment for sbconfig.
sbconfig development uses a Development Mode with localhost for testing. This allows you to:
- Develop on macOS and cross-compile for Linux
- Test the TUI without a real VPS
- Generate test configurations that work locally
- Validate all features before production deployment
┌─────────────────────────────────────────────────────────────────────────┐
│ Development Workflow │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ Mac (Development) Linux (Testing) │
│ ───────────────── ─────────────── │
│ ├── Write Rust code ├── Docker container OR │
│ ├── cargo build (native) ├── Linux VM OR │
│ ├── cross build (Linux) └── Real VPS │
│ └── Run tests │
│ │
│ Development Mode Production Mode │
│ ──────────────── ─────────────── │
│ ├── Server: localhost ├── Server: domain/IP │
│ ├── SSH port: any ├── SSH port: custom (e.g., 7344) │
│ └── Local testing only └── Real deployment │
│ │
└─────────────────────────────────────────────────────────────────────────┘
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install cross for cross-compilation
cargo install cross
# Install Docker (required for cross)
# Download from https://www.docker.com/products/docker-desktop/For integration testing with actual SSH and systemd:
Option A: Docker Container
# Run Ubuntu container with systemd (requires privileged mode)
docker run -d --name sbconfig-test \
--privileged \
-v /sys/fs/cgroup:/sys/fs/cgroup:rw \
ubuntu:22.04 /sbin/initOption B: Linux VM (UTM/Parallels)
- Create Ubuntu 22.04 VM
- Snapshot clean state for easy reset
Option C: Real VPS
- Use for final testing before release
- Test production mode with real domain
When running sbconfig in development mode:
| Setting | Development | Production |
|---|---|---|
| Server Address | localhost or 127.0.0.1 |
Domain or public IP |
| SSH Port | Any available port | Custom port (10000-60000) |
| Config Output | Works for local testing | Works for real clients |
Generated client config in development mode:
{
"outbounds": [
{
"type": "ssh",
"tag": "ssh-out",
"server": "localhost",
"server_port": 2222,
"user": "test_user",
"private_key": "..."
}
]
}macOS has built-in SSH server:
# Enable Remote Login in System Preferences > Sharing
# Or via command line:
sudo systemsetup -setremotelogin on
# Create test user (optional, can use your own user)
sudo dscl . -create /Users/testuser
sudo dscl . -create /Users/testuser UserShell /bin/bash
sudo dscl . -create /Users/testuser UniqueID 1001
sudo dscl . -create /Users/testuser PrimaryGroupID 80
sudo dscl . -create /Users/testuser NFSHomeDirectory /Users/testuser
sudo mkdir /Users/testuser
sudo chown testuser:staff /Users/testuser# Build and run
cargo run
# On first run, select:
# - Mode: Development
# - Server: localhost
# - SSH Port: 22 (or custom)# Install sing-box on macOS
brew install sing-box
# Run with generated config
sing-box run -c /path/to/generated/config.json
# Test proxy
curl -x socks5://127.0.0.1:10808 https://httpbin.org/ip# Using cross (recommended)
cross build --release --target x86_64-unknown-linux-musl
# Binary location
ls target/x86_64-unknown-linux-musl/release/sbconfigcross build --release --target aarch64-unknown-linux-musl# Copy binary to VPS
scp target/x86_64-unknown-linux-musl/release/sbconfig user@your-vps:/tmp/
# SSH to VPS and install
ssh user@your-vps
sudo mv /tmp/sbconfig /usr/local/bin/
sudo chmod +x /usr/local/bin/sbconfig
# Run (requires root for user management)
sudo sbconfig# Run all tests
cargo test
# Run with logging
RUST_LOG=debug cargo test -- --nocaptureThese tests require a Linux environment:
- First-run wizard completes successfully
- sing-box detection works
- SSH port configuration saves correctly
- User creation creates system user
- SSH key generation produces valid keys
- Generated configs are valid JSON
- Generated configs work with sing-box
-
Start fresh
# Remove existing database sudo rm -rf /var/lib/sbconfig/ # Run sbconfig sudo sbconfig
-
Complete first-run wizard
- Verify sing-box detection
- Configure SSH port
- Set to Development mode
-
Create test user
- Navigate to User Management
- Add new user
- Verify system user created:
id username
-
Generate config
- Select the test user
- Generate JSON config
- Verify config is valid JSON
-
Test config (if sing-box installed)
sing-box check -c /path/to/config.json sing-box run -c /path/to/config.json
# Dockerfile.test
FROM ubuntu:22.04
# Install dependencies
RUN apt-get update && apt-get install -y \
openssh-server \
curl \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Set up SSH
RUN mkdir /var/run/sshd
RUN echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
# Install sing-box
RUN bash <(curl -fsSL https://sing-box.app/deb-install.sh)
# Create data directory
RUN mkdir -p /var/lib/sbconfig
# Copy binary (build first with cross)
COPY target/x86_64-unknown-linux-musl/release/sbconfig /usr/local/bin/
EXPOSE 22 2222
CMD ["/usr/sbin/sshd", "-D"]# Build Linux binary first
cross build --release --target x86_64-unknown-linux-musl
# Build test image
docker build -f Dockerfile.test -t sbconfig-test .
# Run container
docker run -d --name sbconfig-lab \
-p 2222:22 \
sbconfig-test
# Access container
docker exec -it sbconfig-lab bash
# Run sbconfig inside container
sbconfig# Make sure Docker is running
docker ps
# Pull the cross image manually
docker pull ghcr.io/cross-rs/x86_64-unknown-linux-musl:latest# Check SSH is running
sudo lsof -i :22
# Check firewall
sudo pfctl -s rules# Install sing-box on macOS
brew install sing-box
# Or download manually
# https://github.com/SagerNet/sing-box/releases- Development - Full development setup
- Architecture - System design
- Features - Feature specifications
- Routing - Traffic routing configuration