From 5a14efb5fcdb7557428963f92f80f73c77354f6a Mon Sep 17 00:00:00 2001 From: denshooter Date: Fri, 12 Sep 2025 23:36:42 +0200 Subject: [PATCH] Make Docker mandatory for pre-push hook - Docker must be running and functional before push is allowed - Added comprehensive Docker status checks (info + hello-world test) - Enhanced error messages with platform-specific Docker start instructions - Improved build error reporting with detailed log output - Added common troubleshooting tips for Docker build failures - Push will fail if Docker is not available or build fails --- .githooks/pre-push | 56 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/.githooks/pre-push b/.githooks/pre-push index 9f40662..80ab572 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -139,20 +139,52 @@ if [ "$CURRENT_BRANCH" = "production" ]; then print_warning "No .env file found. Make sure secrets are configured in Gitea." fi - # Check if Docker is running + # Check if Docker is running and ready + print_status "Checking Docker status..." if ! docker info > /dev/null 2>&1; then - print_warning "Docker is not running. Skipping Docker build test." + print_error "Docker is not running! Please start Docker before pushing." + print_status "To start Docker:" + print_status " - macOS: Open Docker Desktop application" + print_status " - Linux: sudo systemctl start docker" + print_status " - Windows: Start Docker Desktop application" + print_status "" + print_status "Wait for Docker to fully start before trying again." + exit 1 + fi + + # Test Docker functionality + if ! docker run --rm hello-world > /dev/null 2>&1; then + print_error "Docker is running but not functional!" + print_status "Docker might still be starting up. Please wait and try again." + print_status "Or restart Docker if the issue persists." + exit 1 + fi + + print_success "Docker is running and functional" + + # Check Docker image can be built + print_status "Testing Docker build..." + + # Create a temporary log file for build output + BUILD_LOG=$(mktemp) + + if docker build -t portfolio-app:test . > "$BUILD_LOG" 2>&1; then + print_success "Docker build test passed" + docker rmi portfolio-app:test > /dev/null 2>&1 + rm -f "$BUILD_LOG" else - # Check Docker image can be built - print_status "Testing Docker build..." - if docker build -t portfolio-app:test . > /dev/null 2>&1; then - print_success "Docker build test passed" - docker rmi portfolio-app:test > /dev/null 2>&1 - else - print_warning "Docker build test failed, but continuing..." - # Don't fail the push for Docker build issues in pre-push hook - # The CI/CD pipeline will catch this - fi + print_error "Docker build test failed!" + print_status "Build errors:" + echo "----------------------------------------" + cat "$BUILD_LOG" + echo "----------------------------------------" + print_status "Please fix Docker build issues before pushing." + print_status "Common issues:" + print_status " - Missing files referenced in Dockerfile" + print_status " - Network issues during npm install" + print_status " - Insufficient disk space" + rm -f "$BUILD_LOG" + exit 1 fi fi