adding all files this time
This commit is contained in:
parent
06f09b28c1
commit
5f7b4b5696
25 changed files with 3176 additions and 0 deletions
138
scripts/README.md
Normal file
138
scripts/README.md
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
# apt-layer C Implementation - Testing Environment
|
||||
|
||||
This directory contains scripts and documentation for testing the apt-layer C implementation.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
apt-layer/
|
||||
├── build/ # Build artifacts (gitignored)
|
||||
├── docker/ # Docker testing environment (gitignored)
|
||||
├── scripts/ # Testing scripts and documentation
|
||||
├── src/ # C source code
|
||||
├── bin/ # Compiled binary
|
||||
└── ...
|
||||
```
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
|
||||
1. **Docker and Docker Compose** installed
|
||||
2. **apt-cache server** running
|
||||
3. **Git Bash** (for Windows users)
|
||||
|
||||
### Starting the Testing Environment
|
||||
|
||||
#### Windows (PowerShell)
|
||||
```powershell
|
||||
.\scripts\start-testing.ps1
|
||||
```
|
||||
|
||||
#### Linux/macOS (Bash)
|
||||
```bash
|
||||
./scripts/start-testing.sh
|
||||
```
|
||||
|
||||
The script will:
|
||||
1. Check for the existing apt-cache server (apt-cacher-ng on port 3142)
|
||||
2. Build and start the Ubuntu 24.04 testing container
|
||||
3. Connect to the existing apt-cache server for faster package downloads
|
||||
4. Attach you to an interactive shell inside the container
|
||||
|
||||
### Manual Container Management
|
||||
|
||||
```bash
|
||||
# Start container
|
||||
cd docker && docker-compose up -d
|
||||
|
||||
# Attach to container
|
||||
docker-compose exec apt-layer-test /bin/bash
|
||||
|
||||
# View logs
|
||||
docker-compose logs -f apt-layer-test
|
||||
|
||||
# Stop container
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
## Testing the C Implementation
|
||||
|
||||
### Basic Tests (Outside Container)
|
||||
```bash
|
||||
./scripts/test-apt-layer.sh
|
||||
```
|
||||
|
||||
### Advanced Tests (Inside Container)
|
||||
```bash
|
||||
# Build the C binary
|
||||
make clean && make
|
||||
|
||||
# Test basic functionality
|
||||
./bin/apt-layer --help
|
||||
./bin/apt-layer --version
|
||||
|
||||
# Test with actual OSTree operations
|
||||
./bin/apt-layer --list
|
||||
./bin/apt-layer --info particleos/base/plucky
|
||||
|
||||
# Test layer creation
|
||||
./bin/apt-layer particleos/base/plucky particleos/test/plucky
|
||||
```
|
||||
|
||||
## Environment Details
|
||||
|
||||
### Container Features
|
||||
- **Base Image**: Ubuntu 24.04 (Plucky)
|
||||
- **Build Tools**: gcc, make, git
|
||||
- **OSTree**: Full OSTree installation with development headers
|
||||
- **Container Tools**: Podman and Docker
|
||||
- **Package Cache**: Connected to existing apt-cacher-ng server
|
||||
|
||||
### Volume Mounts
|
||||
- **Workspace**: `/workspace` (project root)
|
||||
- **Cache**: `/cache` (persistent cache directory)
|
||||
|
||||
### Network
|
||||
- **apt-cache**: Connected to existing `particleos-network`
|
||||
- **Proxy**: Uses apt-cacher-ng for faster package downloads
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container Won't Start
|
||||
1. Check if Docker is running
|
||||
2. Ensure port 3142 is available for apt-cache
|
||||
3. Check Docker logs: `docker-compose logs apt-layer-test`
|
||||
|
||||
### apt-cache Connection Issues
|
||||
1. Verify apt-cacher-ng is running: `docker ps | grep apt-cacher-ng`
|
||||
2. Start it if needed: `docker start apt-cacher-ng`
|
||||
3. Check network connectivity: `curl http://localhost:3142/acng-report.html`
|
||||
|
||||
### Build Failures
|
||||
1. Ensure all dependencies are installed in container
|
||||
2. Check for sufficient disk space
|
||||
3. Verify OSTree repository permissions
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. **Edit C code** in `src/` directory
|
||||
2. **Build** with `make clean && make`
|
||||
3. **Test** with `./scripts/test-apt-layer.sh`
|
||||
4. **Advanced testing** in Docker container
|
||||
5. **Iterate** and repeat
|
||||
|
||||
## Integration with particleos-builder
|
||||
|
||||
This testing environment is designed to work alongside your existing particleos-builder setup:
|
||||
|
||||
- **Shared apt-cache**: Uses the same apt-cacher-ng server
|
||||
- **Shared network**: Connects to particleos-network
|
||||
- **Complementary**: Focuses on apt-layer development while particleos-builder handles OS builds
|
||||
|
||||
## Files
|
||||
|
||||
- `start-testing.sh` - Bash startup script
|
||||
- `start-testing.ps1` - PowerShell startup script
|
||||
- `test-apt-layer.sh` - Basic test suite
|
||||
- `SETUP-SUMMARY.md` - Detailed setup documentation
|
||||
165
scripts/SETUP-SUMMARY.md
Normal file
165
scripts/SETUP-SUMMARY.md
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
# apt-layer C Implementation - Setup Summary
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
apt-layer/
|
||||
├── build/ # Build artifacts (gitignored)
|
||||
├── docker/ # Docker testing environment (gitignored)
|
||||
│ ├── docker-compose.yml
|
||||
│ └── Dockerfile
|
||||
├── scripts/ # Testing scripts and documentation
|
||||
│ ├── start-testing.sh
|
||||
│ ├── start-testing.ps1
|
||||
│ ├── test-apt-layer.sh
|
||||
│ ├── README.md
|
||||
│ └── SETUP-SUMMARY.md
|
||||
├── src/ # C source code
|
||||
├── bin/ # Compiled binary
|
||||
├── Makefile
|
||||
├── .gitignore
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Key Changes Made
|
||||
|
||||
### 1. Directory Reorganization
|
||||
- **Moved** `testing/` → `docker/` (more descriptive)
|
||||
- **Created** `build/` directory for build artifacts
|
||||
- **Created** `scripts/` directory for all testing scripts
|
||||
- **Updated** `.gitignore` to exclude build and docker directories
|
||||
|
||||
### 2. apt-cache Integration
|
||||
- **Removed** duplicate apt-cacher-ng service
|
||||
- **Connected** to existing apt-cacher-ng from particleos-builder
|
||||
- **Uses** existing `particleos-network` for connectivity
|
||||
- **Configured** apt proxy settings in Dockerfile
|
||||
|
||||
### 3. Simplified Docker Setup
|
||||
- **Single container** instead of multiple services
|
||||
- **External network** dependency on particleos-network
|
||||
- **External volume** for apt-cache data
|
||||
- **Streamlined** startup process
|
||||
|
||||
## Docker Configuration
|
||||
|
||||
### docker-compose.yml
|
||||
```yaml
|
||||
name: apt-layer-testing
|
||||
|
||||
services:
|
||||
apt-layer-test:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
container_name: apt-layer-test
|
||||
depends_on:
|
||||
- apt-cacher-ng
|
||||
volumes:
|
||||
- ..:/workspace
|
||||
- apt-layer-cache:/cache
|
||||
environment:
|
||||
- http_proxy=http://apt-cacher-ng:3142
|
||||
- https_proxy=http://apt-cacher-ng:3142
|
||||
networks:
|
||||
- particleos-network
|
||||
|
||||
apt-cacher-ng:
|
||||
external: true
|
||||
name: apt-cacher-ng
|
||||
|
||||
networks:
|
||||
particleos-network:
|
||||
external: true
|
||||
name: particleos-network
|
||||
```
|
||||
|
||||
### Dockerfile Features
|
||||
- **Ubuntu 24.04** base image
|
||||
- **apt-cache proxy** configuration
|
||||
- **Build tools** (gcc, make, git)
|
||||
- **OSTree** with development headers
|
||||
- **Container tools** (podman, docker)
|
||||
- **Interactive entrypoint** with helpful information
|
||||
|
||||
## Startup Scripts
|
||||
|
||||
### Bash Script (`start-testing.sh`)
|
||||
- **Auto-detects** project and docker directories
|
||||
- **Checks** apt-cache server connectivity
|
||||
- **Builds** and starts container
|
||||
- **Attaches** to interactive shell
|
||||
|
||||
### PowerShell Script (`start-testing.ps1`)
|
||||
- **Windows-compatible** startup
|
||||
- **Same functionality** as bash script
|
||||
- **Error handling** for Windows environment
|
||||
|
||||
## Testing Workflow
|
||||
|
||||
### 1. Basic Testing (Outside Container)
|
||||
```bash
|
||||
./scripts/test-apt-layer.sh
|
||||
```
|
||||
- Builds C binary
|
||||
- Tests basic functionality
|
||||
- Checks dependencies
|
||||
- Validates OSTree operations
|
||||
|
||||
### 2. Advanced Testing (Inside Container)
|
||||
```bash
|
||||
# Start container
|
||||
./scripts/start-testing.sh
|
||||
|
||||
# Inside container
|
||||
make clean && make
|
||||
./bin/apt-layer --help
|
||||
./bin/apt-layer --list
|
||||
```
|
||||
|
||||
## Integration Benefits
|
||||
|
||||
### With particleos-builder
|
||||
- **Shared apt-cache**: Faster package downloads
|
||||
- **Shared network**: No port conflicts
|
||||
- **Complementary**: Different focus areas
|
||||
- **Resource efficient**: Reuses existing infrastructure
|
||||
|
||||
### Development Workflow
|
||||
- **Fast iteration**: Quick container restarts
|
||||
- **Isolated testing**: No host system impact
|
||||
- **Consistent environment**: Same setup everywhere
|
||||
- **Easy cleanup**: Docker volumes and containers
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
1. **apt-cache not found**: Start `apt-cacher-ng` container
|
||||
2. **Network issues**: Check `particleos-network` exists
|
||||
3. **Build failures**: Check container logs
|
||||
4. **Permission issues**: Verify volume mounts
|
||||
|
||||
### Commands
|
||||
```bash
|
||||
# Check apt-cache
|
||||
curl http://localhost:3142/acng-report.html
|
||||
|
||||
# Check network
|
||||
docker network ls | grep particleos
|
||||
|
||||
# Check container
|
||||
docker-compose -f docker/docker-compose.yml ps
|
||||
|
||||
# View logs
|
||||
docker-compose -f docker/docker-compose.yml logs apt-layer-test
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Test the setup** with basic commands
|
||||
2. **Verify apt-cache** integration works
|
||||
3. **Run full test suite** in container
|
||||
4. **Develop features** with confidence
|
||||
5. **Iterate** on C implementation
|
||||
|
||||
This setup provides a robust, integrated testing environment that leverages your existing infrastructure while maintaining isolation for apt-layer development.
|
||||
54
scripts/start-testing.ps1
Normal file
54
scripts/start-testing.ps1
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# apt-layer Testing Environment Startup Script (PowerShell)
|
||||
# Connects to existing apt-cache server
|
||||
|
||||
# Get the directory where this script is located
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$ProjectDir = Split-Path -Parent $ScriptDir
|
||||
$DockerDir = Join-Path $ProjectDir "docker"
|
||||
|
||||
Write-Host "=== apt-layer Testing Environment ===" -ForegroundColor Green
|
||||
Write-Host "Project directory: $ProjectDir" -ForegroundColor Cyan
|
||||
Write-Host "Docker directory: $DockerDir" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Check if we're connected to the existing apt-cache server
|
||||
Write-Host "Checking apt-cache server connection..." -ForegroundColor Blue
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri "http://localhost:3142/acng-report.html" -UseBasicParsing -TimeoutSec 5
|
||||
Write-Host "✓ apt-cache server is running on localhost:3142" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "⚠ apt-cache server not found on localhost:3142" -ForegroundColor Yellow
|
||||
Write-Host " Make sure your particleos-builder apt-cacher-ng is running" -ForegroundColor Yellow
|
||||
Write-Host " You can start it with: docker start apt-cacher-ng" -ForegroundColor Yellow
|
||||
$continue = Read-Host "Continue anyway? (y/N)"
|
||||
if ($continue -ne "y" -and $continue -ne "Y") {
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Change to docker directory
|
||||
Set-Location $DockerDir
|
||||
Write-Host "✓ Changed to docker directory" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Build and start the container
|
||||
Write-Host "Building and starting apt-layer test container..." -ForegroundColor Blue
|
||||
docker-compose up --build -d
|
||||
|
||||
# Wait for container to be ready
|
||||
Write-Host ""
|
||||
Write-Host "Waiting for container to be ready..." -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
# Show container status
|
||||
Write-Host ""
|
||||
Write-Host "Container status:" -ForegroundColor Blue
|
||||
docker-compose ps
|
||||
|
||||
# Attach to the container
|
||||
Write-Host ""
|
||||
Write-Host "Attaching to container (use Ctrl+P, Ctrl+Q to detach)..." -ForegroundColor Blue
|
||||
docker-compose exec apt-layer-test /bin/bash
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Container stopped. To restart: cd $DockerDir && docker-compose up -d" -ForegroundColor Green
|
||||
90
scripts/start-testing.sh
Normal file
90
scripts/start-testing.sh
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
|
||||
# apt-layer Testing Environment Startup Script
|
||||
# Connects to existing apt-cache server
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}==========================================${NC}"
|
||||
echo -e "${BLUE}apt-layer C Implementation - Testing Setup${NC}"
|
||||
echo -e "${BLUE}==========================================${NC}"
|
||||
echo
|
||||
|
||||
# Get the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
DOCKER_DIR="$PROJECT_DIR/docker"
|
||||
|
||||
echo -e "${GREEN}✓ Project directory: $PROJECT_DIR${NC}"
|
||||
echo -e "${GREEN}✓ Docker directory: $DOCKER_DIR${NC}"
|
||||
echo
|
||||
|
||||
# Check if we're connected to the existing apt-cache server
|
||||
echo -e "${BLUE}Checking apt-cache server connection...${NC}"
|
||||
if curl -s http://localhost:3142/acng-report.html > /dev/null; then
|
||||
echo -e "${GREEN}✓ apt-cache server is running on localhost:3142${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ apt-cache server not found on localhost:3142${NC}"
|
||||
echo -e "${YELLOW} Make sure your particleos-builder apt-cacher-ng is running${NC}"
|
||||
echo -e "${YELLOW} You can start it with: docker start apt-cacher-ng${NC}"
|
||||
read -p -e "${BLUE}Continue anyway? (y/N): ${NC}" -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Change to docker directory
|
||||
cd "$DOCKER_DIR"
|
||||
echo -e "${GREEN}✓ Changed to docker directory${NC}"
|
||||
echo
|
||||
|
||||
# Build and start the container
|
||||
echo -e "${BLUE}Building and starting apt-layer test container...${NC}"
|
||||
docker-compose up --build -d
|
||||
|
||||
# Wait for container to be ready
|
||||
echo -e "${YELLOW}Waiting for container to be ready...${NC}"
|
||||
sleep 5
|
||||
|
||||
# Show container status
|
||||
echo -e "${BLUE}Container status:${NC}"
|
||||
docker-compose ps
|
||||
echo
|
||||
|
||||
# Attach to the container
|
||||
echo -e "${BLUE}Attaching to container (use Ctrl+P, Ctrl+Q to detach)...${NC}"
|
||||
docker-compose exec apt-layer-test /bin/bash
|
||||
|
||||
echo -e "${GREEN}Container stopped. To restart: cd $DOCKER_DIR && docker-compose up -d${NC}"
|
||||
|
||||
# Show available commands
|
||||
echo -e "${BLUE}Available Commands:${NC}"
|
||||
echo -e "${YELLOW}Attach to container:${NC} docker-compose exec apt-layer-test /bin/bash"
|
||||
echo -e "${YELLOW}View logs:${NC} docker-compose logs -f apt-layer-test"
|
||||
echo -e "${YELLOW}Stop container:${NC} docker-compose down"
|
||||
echo -e "${YELLOW}Restart container:${NC} docker-compose up -d"
|
||||
echo
|
||||
|
||||
# Ask if user wants to attach to container
|
||||
echo -e "${BLUE}Would you like to attach to the container now? (y/n)${NC}"
|
||||
read -r response
|
||||
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
echo -e "${GREEN}Attaching to container...${NC}"
|
||||
echo -e "${YELLOW}Inside the container, you can:${NC}"
|
||||
echo " - Run tests: ./testing/test-apt-layer.sh"
|
||||
echo " - Test commands: ./bin/apt-layer --help"
|
||||
echo " - Build: make clean && make"
|
||||
echo " - Exit: exit"
|
||||
echo
|
||||
docker-compose exec apt-layer-test /bin/bash
|
||||
else
|
||||
echo -e "${GREEN}Container is ready! Use 'docker-compose exec apt-layer-test /bin/bash' to attach.${NC}"
|
||||
fi
|
||||
128
scripts/test-apt-layer.sh
Normal file
128
scripts/test-apt-layer.sh
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
#!/bin/bash
|
||||
|
||||
# apt-layer C Implementation Test Script
|
||||
# Tests the C binary functionality
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== apt-layer C Implementation Tests ==="
|
||||
echo ""
|
||||
|
||||
# Get the directory where this script is located
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||
BUILD_DIR="$PROJECT_DIR/build"
|
||||
|
||||
echo "Project directory: $PROJECT_DIR"
|
||||
echo "Build directory: $BUILD_DIR"
|
||||
echo ""
|
||||
|
||||
# Create build directory if it doesn't exist
|
||||
mkdir -p "$BUILD_DIR"
|
||||
|
||||
# Change to project directory
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
# Test 1: Build the C binary
|
||||
echo "Test 1: Building C binary..."
|
||||
if make clean && make; then
|
||||
echo "✓ Build successful"
|
||||
else
|
||||
echo "✗ Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 2: Check if binary exists and is executable
|
||||
echo ""
|
||||
echo "Test 2: Binary verification..."
|
||||
if [ -x "./bin/apt-layer" ]; then
|
||||
echo "✓ Binary exists and is executable"
|
||||
ls -la ./bin/apt-layer
|
||||
else
|
||||
echo "✗ Binary not found or not executable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 3: Help command
|
||||
echo ""
|
||||
echo "Test 3: Help command..."
|
||||
if ./bin/apt-layer --help > /dev/null 2>&1; then
|
||||
echo "✓ Help command works"
|
||||
else
|
||||
echo "✗ Help command failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 4: Version command
|
||||
echo ""
|
||||
echo "Test 4: Version command..."
|
||||
if ./bin/apt-layer --version > /dev/null 2>&1; then
|
||||
echo "✓ Version command works"
|
||||
else
|
||||
echo "✗ Version command failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 5: Invalid command handling
|
||||
echo ""
|
||||
echo "Test 5: Invalid command handling..."
|
||||
if ! ./bin/apt-layer --invalid-option > /dev/null 2>&1; then
|
||||
echo "✓ Invalid command properly rejected"
|
||||
else
|
||||
echo "✗ Invalid command not properly handled"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 6: OSTree availability
|
||||
echo ""
|
||||
echo "Test 6: OSTree availability..."
|
||||
if command -v ostree > /dev/null 2>&1; then
|
||||
echo "✓ OSTree is available"
|
||||
ostree --version
|
||||
else
|
||||
echo "⚠ OSTree not found (some features may not work)"
|
||||
fi
|
||||
|
||||
# Test 7: Container tools availability
|
||||
echo ""
|
||||
echo "Test 7: Container tools availability..."
|
||||
if command -v podman > /dev/null 2>&1; then
|
||||
echo "✓ Podman is available"
|
||||
elif command -v docker > /dev/null 2>&1; then
|
||||
echo "✓ Docker is available"
|
||||
else
|
||||
echo "⚠ No container tools found (container features may not work)"
|
||||
fi
|
||||
|
||||
# Test 8: Basic OSTree operations
|
||||
echo ""
|
||||
echo "Test 8: Basic OSTree operations..."
|
||||
if command -v ostree > /dev/null 2>&1; then
|
||||
# Test OSTree repo initialization
|
||||
TEST_REPO="$BUILD_DIR/test-repo"
|
||||
if [ -d "$TEST_REPO" ]; then
|
||||
rm -rf "$TEST_REPO"
|
||||
fi
|
||||
|
||||
if ostree init --repo="$TEST_REPO" --mode=archive-z2; then
|
||||
echo "✓ OSTree repo initialization works"
|
||||
rm -rf "$TEST_REPO"
|
||||
else
|
||||
echo "✗ OSTree repo initialization failed"
|
||||
fi
|
||||
else
|
||||
echo "⚠ Skipping OSTree tests (ostree not available)"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Test Summary ==="
|
||||
echo "✓ All basic functionality tests passed"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Test with actual package installations"
|
||||
echo "2. Test layer creation with OSTree"
|
||||
echo "3. Test container-based builds"
|
||||
echo "4. Test error handling and edge cases"
|
||||
echo ""
|
||||
echo "To run more advanced tests, use the Docker testing environment:"
|
||||
echo " ./scripts/start-testing.sh"
|
||||
Loading…
Add table
Add a link
Reference in a new issue