verify-containerfiles.sh
1 #!/bin/bash 2 set -euo pipefail 3 4 # Verify Containerfiles are properly configured for Podman 5 6 # Colors for output 7 RED='\033[0;31m' 8 GREEN='\033[0;32m' 9 YELLOW='\033[1;33m' 10 BLUE='\033[0;34m' 11 NC='\033[0m' # No Color 12 13 log_info() { 14 echo -e "${BLUE}[INFO]${NC} $1" 15 } 16 17 log_success() { 18 echo -e "${GREEN}[SUCCESS]${NC} $1" 19 } 20 21 log_warning() { 22 echo -e "${YELLOW}[WARNING]${NC} $1" 23 } 24 25 log_error() { 26 echo -e "${RED}[ERROR]${NC} $1" 27 } 28 29 check_containerfiles() { 30 log_info "Checking Containerfiles..." 31 32 # Check if Containerfiles exist 33 if [ ! -f "Containerfile" ]; then 34 log_error "Containerfile not found" 35 return 1 36 fi 37 38 if [ ! -f "Containerfile.alpine" ]; then 39 log_error "Containerfile.alpine not found" 40 return 1 41 fi 42 43 log_success "Containerfiles found" 44 45 # Check for Podman-specific optimizations 46 local checks=( 47 "docker.io/library/:Explicit registry specification" 48 "adduser.*-u.*1001:Specific UID for Podman compatibility" 49 "HEALTHCHECK:Health check configuration" 50 "org.opencontainers.image:OCI labels" 51 "chown.*ferrisproof:Proper ownership" 52 ) 53 54 for check_info in "${checks[@]}"; do 55 local pattern="${check_info%%:*}" 56 local desc="${check_info##*:}" 57 58 if grep -q "$pattern" Containerfile.alpine; then 59 log_success "✓ $desc found in Containerfile.alpine" 60 else 61 log_warning "⚠ $desc not found in Containerfile.alpine" 62 fi 63 done 64 } 65 66 check_scripts() { 67 log_info "Checking script references..." 68 69 # Check if scripts reference Containerfiles correctly 70 if grep -q "Containerfile" scripts/container-build.sh; then 71 log_success "✓ container-build.sh references Containerfiles" 72 else 73 log_error "✗ container-build.sh doesn't reference Containerfiles" 74 return 1 75 fi 76 77 if grep -q "Containerfile" .gitlab-ci.yml; then 78 log_success "✓ GitLab CI references Containerfiles" 79 else 80 log_error "✗ GitLab CI doesn't reference Containerfiles" 81 return 1 82 fi 83 } 84 85 test_container_build() { 86 log_info "Testing container build (dry run)..." 87 88 # Check if Podman is available 89 if command -v podman &> /dev/null; then 90 log_info "Testing with Podman..." 91 if podman build --help > /dev/null 2>&1; then 92 log_success "✓ Podman build command available" 93 else 94 log_warning "⚠ Podman build command failed" 95 fi 96 elif command -v docker &> /dev/null; then 97 log_info "Testing with Docker..." 98 if docker build --help > /dev/null 2>&1; then 99 log_success "✓ Docker build command available" 100 else 101 log_warning "⚠ Docker build command failed" 102 fi 103 else 104 log_warning "⚠ Neither Podman nor Docker found" 105 fi 106 } 107 108 main() { 109 log_info "Verifying Containerfile configuration for Podman..." 110 echo 111 112 check_containerfiles 113 echo 114 115 check_scripts 116 echo 117 118 test_container_build 119 echo 120 121 log_success "Containerfile verification completed! 🎉" 122 echo 123 log_info "Next steps:" 124 echo " • Test build: ./scripts/container-build.sh build" 125 echo " • Run CI: ./scripts/ci-local.sh" 126 echo " • Check documentation: docs/ci-pipeline.md" 127 } 128 129 main "$@"