#!/bin/bash echo "=== Testing apt-ostree OCI Image Building ===" echo # Check if we have the binary if [ ! -f "./target/release/simple-cli" ]; then echo "❌ simple-cli binary not found. Building..." cargo build --release if [ $? -ne 0 ]; then echo "❌ Build failed" exit 1 fi fi echo "✅ Found simple-cli binary" # Check if we have OSTree if ! command -v ostree &> /dev/null; then echo "❌ ostree not found. Installing..." sudo apt update && sudo apt install -y ostree fi echo "✅ Found ostree: $(ostree --version | head -1)" # Create a test OSTree repository echo "" echo "1. Creating test OSTree repository..." TEST_REPO="/tmp/test-apt-ostree-repo" rm -rf "$TEST_REPO" mkdir -p "$TEST_REPO" ostree init --repo="$TEST_REPO" --mode=archive-z2 if [ $? -ne 0 ]; then echo "❌ Failed to initialize OSTree repository" exit 1 fi echo "✅ Created test repository at $TEST_REPO" # Create a simple test commit echo "" echo "2. Creating test commit..." TEST_CHECKOUT="/tmp/test-checkout" rm -rf "$TEST_CHECKOUT" mkdir -p "$TEST_CHECKOUT" # Create some test content echo "Hello from apt-ostree OCI test" > "$TEST_CHECKOUT/test.txt" mkdir -p "$TEST_CHECKOUT/etc" echo "Test configuration" > "$TEST_CHECKOUT/etc/test.conf" mkdir -p "$TEST_CHECKOUT/usr/bin" echo '#!/bin/bash' > "$TEST_CHECKOUT/usr/bin/test-script" echo 'echo "Test script executed"' >> "$TEST_CHECKOUT/usr/bin/test-script" chmod +x "$TEST_CHECKOUT/usr/bin/test-script" # Commit to OSTree ostree commit --repo="$TEST_REPO" --branch=test/oci/integration --subject="Test commit for OCI integration" "$TEST_CHECKOUT" if [ $? -ne 0 ]; then echo "❌ Failed to create test commit" exit 1 fi COMMIT_ID=$(ostree rev-parse --repo="$TEST_REPO" test/oci/integration) echo "✅ Created test commit: $COMMIT_ID" # Test OCI build command echo "" echo "3. Testing OCI image building..." # Try to build OCI image OUTPUT_IMAGE="/tmp/test-image.oci" echo "Building OCI image: $OUTPUT_IMAGE" # Since our CLI might not be fully working, let's test the OCI module directly echo "Testing OCI module compilation..." cargo test --lib oci --no-run if [ $? -eq 0 ]; then echo "✅ OCI module compiles successfully" else echo "❌ OCI module compilation failed" exit 1 fi # Try to use the CLI if available echo "" echo "4. Testing CLI OCI commands..." # Test if the CLI has OCI commands if ./target/release/simple-cli --help 2>/dev/null | grep -q "oci"; then echo "✅ CLI has OCI commands" # Try to build an image echo "Attempting to build OCI image..." ./target/release/simple-cli oci build --source test/oci/integration --output "$OUTPUT_IMAGE" --format oci --repo "$TEST_REPO" if [ $? -eq 0 ]; then echo "✅ Successfully built OCI image: $OUTPUT_IMAGE" # Check if the image was created if [ -d "$OUTPUT_IMAGE" ]; then echo "✅ OCI image directory created" ls -la "$OUTPUT_IMAGE" fi else echo "⚠️ CLI OCI build failed (expected - implementation in progress)" fi else echo "⚠️ CLI OCI commands not available yet" fi # Test compose build-image command echo "" echo "5. Testing compose build-image command..." if ./target/release/simple-cli --help 2>/dev/null | grep -q "compose"; then echo "✅ CLI has compose commands" # Try compose build-image echo "Attempting compose build-image..." ./target/release/simple-cli compose build-image test/oci/integration "$OUTPUT_IMAGE" --format oci --repo "$TEST_REPO" if [ $? -eq 0 ]; then echo "✅ Successfully built image via compose: $OUTPUT_IMAGE" else echo "⚠️ Compose build-image failed (expected - implementation in progress)" fi else echo "⚠️ CLI compose commands not available yet" fi # Test with skopeo if available echo "" echo "6. Testing with skopeo..." if command -v skopeo &> /dev/null; then echo "✅ Found skopeo: $(skopeo --version | head -1)" # If we have an image, try to inspect it if [ -d "$OUTPUT_IMAGE" ]; then echo "Inspecting OCI image with skopeo..." skopeo inspect "oci:$OUTPUT_IMAGE" if [ $? -eq 0 ]; then echo "✅ Successfully inspected OCI image" else echo "⚠️ Failed to inspect OCI image" fi fi else echo "⚠️ skopeo not found - install with: sudo apt install skopeo" fi # Cleanup echo "" echo "7. Cleanup..." rm -rf "$TEST_CHECKOUT" echo "✅ Cleaned up test checkout" echo "" echo "=== Test Summary ===" echo "✅ OSTree repository created and populated" echo "✅ Test commit created: $COMMIT_ID" echo "✅ OCI module compiles successfully" echo "⚠️ CLI OCI commands need implementation" echo "⚠️ Compose build-image needs implementation" echo "" echo "Next steps:" echo "1. Implement CLI OCI commands" echo "2. Implement compose build-image functionality" echo "3. Test with real OSTree environments" echo "4. Validate OCI image output"