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
This commit is contained in:
@@ -139,20 +139,52 @@ if [ "$CURRENT_BRANCH" = "production" ]; then
|
|||||||
print_warning "No .env file found. Make sure secrets are configured in Gitea."
|
print_warning "No .env file found. Make sure secrets are configured in Gitea."
|
||||||
fi
|
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
|
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."
|
||||||
else
|
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
|
# Check Docker image can be built
|
||||||
print_status "Testing Docker build..."
|
print_status "Testing Docker build..."
|
||||||
if docker build -t portfolio-app:test . > /dev/null 2>&1; then
|
|
||||||
|
# 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"
|
print_success "Docker build test passed"
|
||||||
docker rmi portfolio-app:test > /dev/null 2>&1
|
docker rmi portfolio-app:test > /dev/null 2>&1
|
||||||
|
rm -f "$BUILD_LOG"
|
||||||
else
|
else
|
||||||
print_warning "Docker build test failed, but continuing..."
|
print_error "Docker build test failed!"
|
||||||
# Don't fail the push for Docker build issues in pre-push hook
|
print_status "Build errors:"
|
||||||
# The CI/CD pipeline will catch this
|
echo "----------------------------------------"
|
||||||
fi
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user