#!/bin/bash # Test DinD Setup Script # This script verifies that the DinD container is properly configured # and can perform the operations needed by the CI workflow set -e echo "๐Ÿงช Testing DinD Setup..." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Function to print colored output print_status() { local status=$1 local message=$2 if [ "$status" = "PASS" ]; then echo -e "${GREEN}โœ… $message${NC}" elif [ "$status" = "FAIL" ]; then echo -e "${RED}โŒ $message${NC}" else echo -e "${YELLOW}โš ๏ธ $message${NC}" fi } # Test 1: Check if DinD container exists and is running echo "1. Checking DinD container status..." if docker ps --format "table {{.Names}}" | grep -q "^ci-dind$"; then print_status "PASS" "DinD container is running" else print_status "FAIL" "DinD container is not running" echo "Starting DinD container..." docker run -d \ --name ci-dind \ --privileged \ -p 2375:2375 \ -e DOCKER_TLS_CERTDIR="" \ docker:dind # Wait for DinD to be ready echo "Waiting for DinD to be ready..." timeout 60 bash -c 'until docker exec ci-dind docker version; do sleep 2; done' print_status "PASS" "DinD container started successfully" fi # Test 2: Check Docker functionality inside DinD echo "2. Testing Docker functionality inside DinD..." if docker exec ci-dind docker version > /dev/null 2>&1; then print_status "PASS" "Docker is working inside DinD" else print_status "FAIL" "Docker is not working inside DinD" exit 1 fi # Test 3: Check if Harbor certificate is installed echo "3. Checking Harbor certificate installation..." if docker exec ci-dind test -f /usr/local/share/ca-certificates/registry.crt; then print_status "PASS" "Harbor certificate is installed" else print_status "WARN" "Harbor certificate not found - will be installed during CI run" fi # Test 4: Test git functionality inside DinD echo "4. Testing git functionality inside DinD..." if docker exec ci-dind git --version > /dev/null 2>&1; then print_status "PASS" "Git is available inside DinD" else print_status "FAIL" "Git is not available inside DinD" echo "Installing git in DinD..." docker exec ci-dind apk add --no-cache git print_status "PASS" "Git installed successfully" fi # Test 5: Test workspace directory echo "5. Testing workspace directory..." if docker exec ci-dind test -d /workspace; then print_status "PASS" "Workspace directory exists" else print_status "WARN" "Workspace directory does not exist - will be created during CI run" fi # Test 6: Test basic Docker operations echo "6. Testing basic Docker operations..." if docker exec ci-dind docker run --rm alpine:latest echo "test" > /dev/null 2>&1; then print_status "PASS" "Basic Docker operations work" else print_status "FAIL" "Basic Docker operations failed" exit 1 fi # Test 7: Test Docker Compose echo "7. Testing Docker Compose..." if docker exec ci-dind docker compose version > /dev/null 2>&1; then print_status "PASS" "Docker Compose is available" else print_status "FAIL" "Docker Compose is not available" exit 1 fi echo "" echo "๐ŸŽ‰ DinD Setup Test Complete!" echo "" echo "If all tests passed, your DinD environment is ready for CI/CD operations." echo "The CI workflow will:" echo " 1. Checkout code directly into the DinD container from your Forgejo repository" echo " 2. Run tests in isolated containers" echo " 3. Build and push images to Harbor" echo "" echo "To run the CI workflow, push changes to your main branch."