#!/bin/bash

# Start BIND9 test container
# Usage: ./01_start_container.sh

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_DIR="$(dirname "$SCRIPT_DIR")"

cd "$TEST_DIR"

echo "Starting BIND9 test container..."

# Ensure private directory exists with proper permissions
mkdir -p private
chmod 777 private

# Start the container
docker compose up -d

echo "Waiting for container to be ready..."
sleep 5

# Check if container is running
if docker compose ps | grep -q "Up"; then
    echo "✓ Container started successfully"
    echo "Container status:"
    docker compose ps
else
    echo "✗ Failed to start container"
    docker compose logs
    exit 1
fi

echo ""
echo "BIND9 test environment is ready!"
echo "DNS server listening on localhost:53"