chore: initial commit of docker-tools

This commit is contained in:
sapient
2026-03-22 00:54:34 -07:00
commit b9f096a090
17 changed files with 4916 additions and 0 deletions

5
test-stack/.dockerignore Executable file
View File

@@ -0,0 +1,5 @@
README.md
*.md
.git
.gitignore

197
test-stack/README.md Executable file
View File

@@ -0,0 +1,197 @@
# DocWell Test Stack
A simple HTTP server stack for testing DocWell features.
## Overview
This is a minimal Docker Compose stack that runs an Nginx web server. It's designed to be used for testing all DocWell features including:
- Backup and restore operations
- Stack management (start/stop/restart)
- Image updates
- Service migration
- Volume management
- Health checks
## Quick Start
### 1. Install the Stack
```bash
# Copy to stacks directory (default: /opt/stacks)
sudo cp -r test-stack /opt/stacks/
# Or use your configured stacks directory
sudo cp -r test-stack /path/to/your/stacks/dir/
```
### 2. Start the Stack
```bash
cd /opt/stacks/test-stack
docker compose up -d
```
Or use DocWell:
```bash
./docwell --stack-start test-stack
```
### 3. Verify It's Running
```bash
# Check status
docker compose ps
# Or use DocWell
./docwell --stack-status test-stack
# Access the web interface
curl http://localhost:8080
# Or open in browser: http://localhost:8080
```
## Testing DocWell Features
### Backup Operations
```bash
# Backup this stack
./docwell --backup-stack test-stack
# Or backup all stacks
./docwell --backup
```
### Stack Management
```bash
# List all stacks
./docwell --stack-list
# Start stack
./docwell --stack-start test-stack
# Stop stack
./docwell --stack-stop test-stack
# Restart stack
./docwell --stack-restart test-stack
# View logs
./docwell --stack-logs test-stack
```
### Update Operations
```bash
# Check for updates
./docwell --update-check
# Update this stack
./docwell --update-stack test-stack
# Update all stacks
./docwell --update-all
```
### Migration Testing
```bash
# Migrate to another server
./docwell --migrate \
--migrate-service test-stack \
--migrate-source local \
--migrate-dest user@remote-host \
--migrate-method rsync
```
## Stack Details
- **Service**: Nginx web server
- **Image**: `nginx:alpine` (lightweight)
- **Port**: 8080 (host) → 80 (container)
- **Volume**: `web_data` (persistent cache storage)
- **Health Check**: Enabled (checks every 30s)
## Files
- `compose.yaml` - Docker Compose configuration
- `html/index.html` - Web interface served by Nginx
- `README.md` - This file
## Customization
### Change Port
Edit `compose.yaml`:
```yaml
ports:
- "9090:80" # Change 8080 to your desired port
```
### Change Image Version
Edit `compose.yaml`:
```yaml
image: nginx:latest # or nginx:1.25, etc.
```
### Add More Services
You can add additional services to test more complex scenarios:
```yaml
services:
web:
# ... existing config ...
db:
image: postgres:alpine
# ... database config ...
```
## Cleanup
To remove the test stack:
```bash
# Stop and remove
cd /opt/stacks/test-stack
docker compose down -v
# Remove directory
sudo rm -rf /opt/stacks/test-stack
```
## Troubleshooting
### Port Already in Use
If port 8080 is already in use, change it in `compose.yaml`:
```yaml
ports:
- "8081:80" # Use different port
```
### Permission Issues
Ensure the stacks directory is accessible:
```bash
sudo chown -R $USER:$USER /opt/stacks/test-stack
```
### Container Won't Start
Check logs:
```bash
docker compose logs
# Or
./docwell --stack-logs test-stack
```
## Notes
- This stack uses a named volume (`web_data`) to test volume migration features
- The health check ensures the service is actually running, not just started
- The web interface shows real-time information about the stack

263
test-stack/TESTING.md Executable file
View File

@@ -0,0 +1,263 @@
# DocWell Testing Guide
This document provides specific test scenarios for using the test-stack with DocWell.
## Prerequisites
1. Install the test stack:
```bash
cd test-stack
./setup.sh
```
2. Ensure DocWell is built:
```bash
cd go
go build -o docwell docwell.go
```
## Test Scenarios
### 1. Stack Management Tests
#### Test: List Stacks
```bash
./docwell --stack-list
```
**Expected**: Should show `test-stack` with status (running/stopped)
#### Test: Start Stack
```bash
./docwell --stack-start test-stack
```
**Expected**: Stack starts, container runs, web interface accessible at http://localhost:8080
#### Test: Check Status
```bash
./docwell --stack-status test-stack
```
**Expected**: Outputs "running" or "stopped"
#### Test: View Logs
```bash
./docwell --stack-logs test-stack
```
**Expected**: Shows Nginx logs
#### Test: Restart Stack
```bash
./docwell --stack-restart test-stack
```
**Expected**: Stack restarts, service remains available
#### Test: Stop Stack
```bash
./docwell --stack-stop test-stack
```
**Expected**: Stack stops, container removed, port 8080 no longer accessible
### 2. Backup Tests
#### Test: Backup Single Stack
```bash
./docwell --backup-stack test-stack
```
**Expected**:
- Creates backup in configured backup directory
- Backup file: `docker-<hostname>/<date>/docker-test-stack.tar.zst`
- Stack restarts if it was running
#### Test: List Stacks for Backup
```bash
./docwell --backup-list
```
**Expected**: Lists all stacks with their status
#### Test: Backup All Stacks
```bash
./docwell --backup
```
**Expected**: Backs up all stacks including test-stack
### 3. Update Tests
#### Test: Check for Updates
```bash
./docwell --update-check
```
**Expected**: Shows update status for nginx:alpine image
#### Test: Update Single Stack
```bash
./docwell --update-stack test-stack
```
**Expected**:
- Pulls latest nginx:alpine image
- Recreates container if stack was running
- Service continues to work
#### Test: Update All Stacks
```bash
./docwell --update-all
```
**Expected**: Updates all stacks including test-stack
### 4. Cleanup Tests
#### Test: Cleanup Containers
```bash
# Stop the stack first
./docwell --stack-stop test-stack
./docwell --cleanup-containers
```
**Expected**: Removes stopped containers
#### Test: Cleanup Images
```bash
./docwell --cleanup-images
```
**Expected**: Removes unused images (may remove old nginx images)
#### Test: Cleanup Volumes
```bash
./docwell --cleanup-volumes
```
**Expected**: Removes unused volumes (be careful - this removes data!)
### 5. Migration Tests
#### Test: Migrate to Another Server (Clone Mode)
```bash
./docwell --migrate \
--migrate-service test-stack \
--migrate-source local \
--migrate-dest user@remote-host \
--migrate-method rsync
```
**Expected**:
- Creates backup of config and volumes
- Transfers to destination
- Starts service on destination
- Original service keeps running
#### Test: Migrate (Transfer Mode)
```bash
./docwell --migrate \
--migrate-service test-stack \
--migrate-source local \
--migrate-dest user@remote-host \
--migrate-method rsync \
--migrate-transfer
```
**Expected**:
- Stops service on source
- Transfers everything
- Starts on destination
- Source service is stopped
### 6. Interactive Mode Tests
#### Test: Interactive Backup
```bash
./docwell
# Select option 1 (Backup Stacks)
# Select test-stack
```
**Expected**: Interactive menu works, backup completes
#### Test: Interactive Stack Manager
```bash
./docwell
# Select option 4 (Stack Manager)
# Select test-stack
# Try start/stop/restart/update/logs
```
**Expected**: All operations work through interactive menu
## Verification Steps
After each test, verify:
1. **Service Status**:
```bash
docker compose -f /opt/stacks/test-stack/compose.yaml ps
```
2. **Web Interface**:
```bash
curl http://localhost:8080
# Should return HTML content
```
3. **Volume Exists**:
```bash
docker volume ls | grep test-stack
```
4. **Backup Created**:
```bash
ls -lh /storage/backups/docker-*/$(date +%Y-%m-%d)/
```
## Troubleshooting
### Port Already in Use
If port 8080 is in use, edit `compose.yaml`:
```yaml
ports:
- "8081:80" # Change port
```
### Permission Denied
```bash
sudo chown -R $USER:$USER /opt/stacks/test-stack
```
### Container Won't Start
```bash
cd /opt/stacks/test-stack
docker compose logs
docker compose up -d
```
### Backup Fails
- Check backup directory permissions
- Ensure enough disk space
- Check logs: `tail -f /var/log/docwell.log`
## Test Checklist
- [ ] Stack listing works
- [ ] Start/stop/restart operations work
- [ ] Status checking works
- [ ] Log viewing works
- [ ] Backup creates valid archive
- [ ] Update pulls new images
- [ ] Cleanup removes unused resources
- [ ] Migration transfers correctly
- [ ] Interactive mode works
- [ ] Web interface accessible after operations
## Performance Testing
For stress testing:
1. **Multiple Stacks**: Create several test stacks
2. **Parallel Operations**: Run multiple operations simultaneously
3. **Large Volumes**: Add data to volumes to test transfer speeds
4. **Network Testing**: Test migration over slow networks
## Cleanup After Testing
```bash
# Stop and remove stack
cd /opt/stacks/test-stack
docker compose down -v
# Remove directory
sudo rm -rf /opt/stacks/test-stack
# Clean up backups (optional)
rm -rf /storage/backups/docker-*/$(date +%Y-%m-%d)/docker-test-stack.tar.zst
```

27
test-stack/compose.yaml Executable file
View File

@@ -0,0 +1,27 @@
services:
web:
image: nginx:alpine
container_name: test-stack_web
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html:ro
- web_data:/var/cache/nginx
restart: unless-stopped
labels:
- "com.docker.compose.project=test-stack"
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
volumes:
web_data:
driver: local
networks:
default:
name: test-stack_network

115
test-stack/html/index.html Executable file
View File

@@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DocWell Test Stack</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.container {
background: rgba(255, 255, 255, 0.1);
padding: 30px;
border-radius: 10px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(10px);
}
h1 {
margin-top: 0;
text-align: center;
}
.info {
background: rgba(255, 255, 255, 0.2);
padding: 15px;
border-radius: 5px;
margin: 20px 0;
}
.status {
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
background: #4CAF50;
font-weight: bold;
}
code {
background: rgba(0, 0, 0, 0.3);
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
ul {
line-height: 1.8;
}
</style>
</head>
<body>
<div class="container">
<h1>🚀 DocWell Test Stack</h1>
<div class="info">
<p><span class="status">✓ Running</span></p>
<p>This is a test stack for DocWell Docker management tool.</p>
</div>
<div class="info">
<h2>Stack Information</h2>
<ul>
<li><strong>Stack Name:</strong> <code>test-stack</code></li>
<li><strong>Service:</strong> Nginx Web Server</li>
<li><strong>Image:</strong> nginx:alpine</li>
<li><strong>Port:</strong> 8080 (host) → 80 (container)</li>
<li><strong>Volume:</strong> <code>web_data</code> (persistent cache)</li>
</ul>
</div>
<div class="info">
<h2>Testing DocWell Features</h2>
<p>Use this stack to test:</p>
<ul>
<li>✅ Stack backup and restore</li>
<li>✅ Start/stop/restart operations</li>
<li>✅ Image updates</li>
<li>✅ Service migration</li>
<li>✅ Volume management</li>
<li>✅ Health checks</li>
</ul>
</div>
<div class="info">
<h2>Quick Commands</h2>
<pre style="background: rgba(0,0,0,0.3); padding: 15px; border-radius: 5px; overflow-x: auto;">
# View logs
docker compose logs -f
# Check status
docker compose ps
# Restart service
docker compose restart
# Stop service
docker compose down
# Start service
docker compose up -d
</pre>
</div>
<div class="info">
<p style="text-align: center; margin-bottom: 0;">
<small>Generated: <span id="timestamp"></span></small>
</p>
</div>
</div>
<script>
document.getElementById('timestamp').textContent = new Date().toLocaleString();
</script>
</body>
</html>

56
test-stack/setup.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/bash
# Setup script for DocWell test stack
set -e
# Default stacks directory
STACKS_DIR="${STACKS_DIR:-/opt/stacks}"
STACK_NAME="test-stack"
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}DocWell Test Stack Setup${NC}"
echo "================================"
echo ""
# Check if running as root or with sudo
if [ "$EUID" -ne 0 ]; then
echo -e "${YELLOW}Note: You may need sudo to copy to $STACKS_DIR${NC}"
echo ""
fi
# Get absolute path of test-stack directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Create stacks directory if it doesn't exist
if [ ! -d "$STACKS_DIR" ]; then
echo "Creating stacks directory: $STACKS_DIR"
sudo mkdir -p "$STACKS_DIR"
fi
# Copy test stack
echo "Copying test stack to $STACKS_DIR/$STACK_NAME..."
sudo cp -r "$SCRIPT_DIR" "$STACKS_DIR/$STACK_NAME"
# Set permissions
echo "Setting permissions..."
sudo chown -R "$USER:$USER" "$STACKS_DIR/$STACK_NAME"
echo ""
echo -e "${GREEN}✓ Setup complete!${NC}"
echo ""
echo "Next steps:"
echo " 1. Start the stack:"
echo " cd $STACKS_DIR/$STACK_NAME"
echo " docker compose up -d"
echo ""
echo " 2. Or use DocWell:"
echo " ./docwell --stack-start $STACK_NAME"
echo ""
echo " 3. Access the web interface:"
echo " http://localhost:8080"
echo ""