From a4249ab3eeac074d68ce0db726a23e9b054594fc Mon Sep 17 00:00:00 2001 From: Mubbasher Ahmed Qureshi <6255767+mubbi@users.noreply.github.com> Date: Fri, 18 Jul 2025 18:32:15 +0500 Subject: [PATCH 1/2] chore(main): release 1.2.1 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c3f1463..41ea87d 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.2.0" + ".": "1.2.1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index e013a66..9c2a8b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.2.1](https://github.com/mubbi/laravel-blog-api/compare/v1.2.0...v1.2.1) (2025-07-18) + + +### Bug Fixes + +* fix health check for queue worker to get its correct status ([ec6e20d](https://github.com/mubbi/laravel-blog-api/commit/ec6e20d83ea0656773eb058ff63db8f44d0ddbfb)) +* fix health check for queue worker to get its correct status ([0f3ead1](https://github.com/mubbi/laravel-blog-api/commit/0f3ead1d053f5d0fee469128b830123f76e8e5d7)) + ## [1.2.0](https://github.com/mubbi/laravel-blog-api/compare/v1.1.0...v1.2.0) (2025-07-18) From dc7493b8b6314442fe425bf0f5c47bbd508d0efd Mon Sep 17 00:00:00 2001 From: mubbasher-ahmed Date: Sat, 19 Jul 2025 02:37:00 +0500 Subject: [PATCH 2/2] fix: fix port check commands and git hook setup --- Makefile | 2 +- containers/check-ports.sh | 228 +++++++++++++++++----------- containers/check-sonarqube-ports.sh | 215 ++++++++++++++++++++++---- 3 files changed, 328 insertions(+), 117 deletions(-) diff --git a/Makefile b/Makefile index 9201b7a..7f5f018 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ install-commit-tools: # Setup Git Hooks setup-git-hooks: @echo "SETUP: Installing Git hooks..." - cp -r .githooks/ .git/hooks/ + cp -r .githooks/* .git/hooks/ chmod +x .git/hooks/pre-commit && chmod +x .git/hooks/pre-push && chmod +x .git/hooks/prepare-commit-msg && chmod +x .git/hooks/commit-msg @echo "SUCCESS: Git hooks installed!" diff --git a/containers/check-ports.sh b/containers/check-ports.sh index a6ce502..0eb09fd 100755 --- a/containers/check-ports.sh +++ b/containers/check-ports.sh @@ -26,13 +26,76 @@ OPTIONAL_PORTS=( "5432:PostgreSQL (SonarQube)" ) -# Function to check if a port is available +# Function to detect operating system +detect_os() { + if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then + echo "windows" + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "linux" + else + echo "unknown" + fi +} + +# Function to check if a port is available (platform-independent) check_port() { local port=$1 local description=$2 local optional=${3:-false} - - if nc -z localhost $port 2>/dev/null; then + local os=$(detect_os) + local port_in_use=false + + case $os in + "windows") + # Use netstat on Windows (available by default) + if netstat -an | grep -q ":$port "; then + port_in_use=true + fi + ;; + "macos") + # Use netstat on macOS (available by default) + if netstat -an | grep -q "\\.$port "; then + port_in_use=true + fi + ;; + "linux") + # Try multiple methods on Linux + if command -v ss &> /dev/null; then + # Use ss (modern replacement for netstat) + if ss -tuln | grep -q ":$port "; then + port_in_use=true + fi + elif command -v netstat &> /dev/null; then + # Fall back to netstat + if netstat -tuln | grep -q ":$port "; then + port_in_use=true + fi + elif command -v nc &> /dev/null; then + # Fall back to netcat + if nc -z localhost $port 2>/dev/null; then + port_in_use=true + fi + else + echo -e "${YELLOW}⚠️ Cannot check port $port - no suitable tools available${NC}" + return 0 + fi + ;; + *) + # Unknown OS - try netcat if available + if command -v nc &> /dev/null; then + if nc -z localhost $port 2>/dev/null; then + port_in_use=true + fi + else + echo -e "${YELLOW}⚠️ Cannot check port $port - unsupported OS${NC}" + return 0 + fi + ;; + esac + + if [ "$port_in_use" = true ]; then if [ "$optional" = true ]; then echo -e "${YELLOW}⚠️ OPTIONAL PORT $port ($description) is already in use${NC}" else @@ -49,73 +112,86 @@ check_port() { return 0 } -# Function to suggest alternative ports -suggest_alternative_port() { - local base_port=$1 - local description=$2 - local start_range=$((base_port + 1)) - local end_range=$((base_port + 100)) - - echo -e "${BLUE}💡 Searching for alternative ports for $description...${NC}" - - for ((port=start_range; port<=end_range; port++)); do - if ! nc -z localhost $port 2>/dev/null; then - echo -e "${GREEN} Suggested alternative: $port${NC}" - return 0 - fi - done - - echo -e "${YELLOW} No alternatives found in range $start_range-$end_range${NC}" - return 1 -} +# Check if required tools are available and provide helpful messages +check_requirements() { + local os=$(detect_os) + local tools_available=false -# Function to show port change instructions -show_port_change_instructions() { - local port=$1 - local description=$2 - local suggested_port=$3 - - echo -e "${BLUE}📝 To change port $port ($description) to $suggested_port:${NC}" - - case $port in - 8081) - echo " Update containers/docker-compose.yml: ports: \"$suggested_port:80\"" + case $os in + "windows") + if command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (Windows)${NC}" + fi ;; - 8001) - echo " Update containers/docker-compose.yml: ports: \"$suggested_port:8001\"" + "macos") + if command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (macOS)${NC}" + fi ;; - 3306) - echo " Update containers/docker-compose.yml: ports: \"$suggested_port:3306\"" + "linux") + if command -v ss &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using ss for port checking (Linux)${NC}" + elif command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (Linux)${NC}" + elif command -v nc &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netcat for port checking (Linux)${NC}" + fi ;; - 6379) - echo " Update containers/docker-compose.yml: ports: \"$suggested_port:6379\"" - ;; - 3307) - echo " Update containers/docker-compose.test.yml: ports: \"$suggested_port:3306\"" - ;; - 6380) - echo " Update containers/docker-compose.test.yml: ports: \"$suggested_port:6379\"" - ;; - 9000) - echo " Update containers/docker-compose.sonarqube.yml: ports: \"$suggested_port:9000\"" - ;; - 5432) - echo " Update containers/docker-compose.sonarqube.yml: ports: \"$suggested_port:5432\"" + *) + if command -v nc &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netcat for port checking${NC}" + fi ;; esac - echo "" + + if [ "$tools_available" = false ]; then + echo -e "${RED}❌ Error: No suitable tools available for port checking.${NC}" + echo "Please install one of the following:" + case $os in + "linux") + echo " • ss: sudo apt-get install iproute2 (Ubuntu/Debian) or sudo yum install iproute (CentOS/RHEL)" + echo " • netstat: sudo apt-get install net-tools (Ubuntu/Debian) or sudo yum install net-tools (CentOS/RHEL)" + echo " • netcat: sudo apt-get install netcat (Ubuntu/Debian) or sudo yum install nc (CentOS/RHEL)" + ;; + "macos") + echo " • netcat: brew install netcat" + ;; + "windows") + echo " • netstat should be available by default on Windows" + echo " • If using WSL, install net-tools: sudo apt-get install net-tools" + ;; + *) + echo " • netcat: install via your package manager" + ;; + esac + return 1 + fi + + return 0 } # Main function main() { - echo -e "${BLUE}🔍 Checking port availability for Laravel Blog API Docker setup...${NC}" + echo -e "${BLUE}��� Checking port availability for Laravel Blog API Docker setup...${NC}" echo "" - + + # Check if we have the required tools + if ! check_requirements; then + exit 1 + fi + echo "" + local unavailable_ports=() local failed_required=false - + # Check required ports - echo -e "${BLUE}📋 Checking required ports:${NC}" + echo -e "${BLUE}��� Checking required ports:${NC}" for port_info in "${REQUIRED_PORTS[@]}"; do local port="${port_info%%:*}" local description="${port_info#*:}" @@ -124,62 +200,36 @@ main() { failed_required=true fi done - + echo "" - + # Check optional ports (SonarQube) - echo -e "${BLUE}📋 Checking optional ports (SonarQube):${NC}" + echo -e "${BLUE}��� Checking optional ports (SonarQube):${NC}" for port_info in "${OPTIONAL_PORTS[@]}"; do local port="${port_info%%:*}" local description="${port_info#*:}" check_port "$port" "$description" true done - + echo "" - + # Summary and recommendations if [ "$failed_required" = true ]; then echo -e "${RED}❌ SETUP CANNOT CONTINUE - Some required ports are unavailable!${NC}" echo "" - echo -e "${YELLOW}🔧 SOLUTIONS:${NC}" + echo -e "${YELLOW}��� SOLUTIONS:${NC}" echo "1. Stop the services using these ports" echo "2. Use alternative ports (see suggestions below)" echo "3. Modify docker-compose files with new ports" echo "" - - echo -e "${BLUE}💡 PORT ALTERNATIVES:${NC}" - for port_info in "${unavailable_ports[@]}"; do - local port="${port_info%%:*}" - local description="${port_info#*:}" - - # Find suggested alternative - local start_range=$((port + 1)) - for ((alt_port=start_range; alt_port<=start_range+50; alt_port++)); do - if ! nc -z localhost $alt_port 2>/dev/null; then - show_port_change_instructions "$port" "$description" "$alt_port" - break - fi - done - done - echo -e "${YELLOW}⚠️ After making changes, run this script again to verify.${NC}" return 1 else echo -e "${GREEN}✅ ALL REQUIRED PORTS ARE AVAILABLE!${NC}" - echo -e "${GREEN}🚀 Docker setup can proceed safely.${NC}" + echo -e "${GREEN}��� Docker setup can proceed safely.${NC}" return 0 fi } -# Check if netcat is available -if ! command -v nc &> /dev/null; then - echo -e "${RED}❌ Error: 'nc' (netcat) is required but not installed.${NC}" - echo "Please install netcat:" - echo " macOS: brew install netcat" - echo " Ubuntu/Debian: sudo apt-get install netcat" - echo " CentOS/RHEL: sudo yum install nc" - exit 1 -fi - # Run the main function main "$@" diff --git a/containers/check-sonarqube-ports.sh b/containers/check-sonarqube-ports.sh index 6a1a24b..cc6bb7e 100755 --- a/containers/check-sonarqube-ports.sh +++ b/containers/check-sonarqube-ports.sh @@ -17,12 +17,75 @@ SONARQUBE_PORTS=( "5432:PostgreSQL (SonarQube Database)" ) -# Function to check if a port is available +# Function to detect operating system +detect_os() { + if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then + echo "windows" + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "macos" + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "linux" + else + echo "unknown" + fi +} + +# Function to check if a port is available (platform-independent) check_port() { local port=$1 local description=$2 - - if nc -z localhost $port 2>/dev/null; then + local os=$(detect_os) + local port_in_use=false + + case $os in + "windows") + # Use netstat on Windows (available by default) + if netstat -an | grep -q ":$port "; then + port_in_use=true + fi + ;; + "macos") + # Use netstat on macOS (available by default) + if netstat -an | grep -q "\\.$port "; then + port_in_use=true + fi + ;; + "linux") + # Try multiple methods on Linux + if command -v ss &> /dev/null; then + # Use ss (modern replacement for netstat) + if ss -tuln | grep -q ":$port "; then + port_in_use=true + fi + elif command -v netstat &> /dev/null; then + # Fall back to netstat + if netstat -tuln | grep -q ":$port "; then + port_in_use=true + fi + elif command -v nc &> /dev/null; then + # Fall back to netcat + if nc -z localhost $port 2>/dev/null; then + port_in_use=true + fi + else + echo -e "${YELLOW}⚠️ Cannot check port $port - no suitable tools available${NC}" + return 0 + fi + ;; + *) + # Unknown OS - try netcat if available + if command -v nc &> /dev/null; then + if nc -z localhost $port 2>/dev/null; then + port_in_use=true + fi + else + echo -e "${YELLOW}⚠️ Cannot check port $port - unsupported OS${NC}" + return 0 + fi + ;; + esac + + if [ "$port_in_use" = true ]; then echo -e "${RED}❌ PORT $port ($description) is already in use${NC}" return 1 else @@ -31,13 +94,14 @@ check_port() { return 0 } -# Function to suggest alternative ports for SonarQube +# Function to suggest alternative ports for SonarQube (platform-independent) suggest_sonarqube_alternatives() { local port=$1 local description=$2 - + local os=$(detect_os) + echo -e "${BLUE}💡 Searching for alternative ports for $description...${NC}" - + case $port in 9000) # Suggest common alternative ports for web interfaces @@ -48,15 +112,52 @@ suggest_sonarqube_alternatives() { local alternatives=(5433 5434 5435 15432 25432) ;; esac - + for alt_port in "${alternatives[@]}"; do - if ! nc -z localhost $alt_port 2>/dev/null; then + local port_in_use=false + + case $os in + "windows") + if netstat -an | grep -q ":$alt_port "; then + port_in_use=true + fi + ;; + "macos") + if netstat -an | grep -q "\\.$alt_port "; then + port_in_use=true + fi + ;; + "linux") + if command -v ss &> /dev/null; then + if ss -tuln | grep -q ":$alt_port "; then + port_in_use=true + fi + elif command -v netstat &> /dev/null; then + if netstat -tuln | grep -q ":$alt_port "; then + port_in_use=true + fi + elif command -v nc &> /dev/null; then + if nc -z localhost $alt_port 2>/dev/null; then + port_in_use=true + fi + fi + ;; + *) + if command -v nc &> /dev/null; then + if nc -z localhost $alt_port 2>/dev/null; then + port_in_use=true + fi + fi + ;; + esac + + if [ "$port_in_use" = false ]; then echo -e "${GREEN} Suggested alternative: $alt_port${NC}" show_sonarqube_port_change_instructions "$port" "$description" "$alt_port" return 0 fi done - + echo -e "${YELLOW} No common alternatives available. Try manually selecting a port.${NC}" return 1 } @@ -66,9 +167,9 @@ show_sonarqube_port_change_instructions() { local port=$1 local description=$2 local suggested_port=$3 - + echo -e "${BLUE}📝 To change SonarQube port $port ($description) to $suggested_port:${NC}" - + case $port in 9000) echo " Update containers/docker-compose.sonarqube.yml:" @@ -83,14 +184,84 @@ show_sonarqube_port_change_instructions() { echo "" } +# Check if required tools are available and provide helpful messages +check_requirements() { + local os=$(detect_os) + local tools_available=false + + case $os in + "windows") + if command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (Windows)${NC}" + fi + ;; + "macos") + if command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (macOS)${NC}" + fi + ;; + "linux") + if command -v ss &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using ss for port checking (Linux)${NC}" + elif command -v netstat &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netstat for port checking (Linux)${NC}" + elif command -v nc &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netcat for port checking (Linux)${NC}" + fi + ;; + *) + if command -v nc &> /dev/null; then + tools_available=true + echo -e "${GREEN}✅ Using netcat for port checking${NC}" + fi + ;; + esac + + if [ "$tools_available" = false ]; then + echo -e "${RED}❌ Error: No suitable tools available for port checking.${NC}" + echo "Please install one of the following:" + case $os in + "linux") + echo " • ss: sudo apt-get install iproute2 (Ubuntu/Debian) or sudo yum install iproute (CentOS/RHEL)" + echo " • netstat: sudo apt-get install net-tools (Ubuntu/Debian) or sudo yum install net-tools (CentOS/RHEL)" + echo " • netcat: sudo apt-get install netcat (Ubuntu/Debian) or sudo yum install nc (CentOS/RHEL)" + ;; + "macos") + echo " • netcat: brew install netcat" + ;; + "windows") + echo " • netstat should be available by default on Windows" + echo " • If using WSL, install net-tools: sudo apt-get install net-tools" + ;; + *) + echo " • netcat: install via your package manager" + ;; + esac + return 1 + fi + + return 0 +} + # Main function main() { echo -e "${BLUE}🔍 Checking SonarQube port availability...${NC}" echo "" - + + # Check if we have the required tools + if ! check_requirements; then + exit 1 + fi + echo "" + local unavailable_ports=() local failed=false - + # Check SonarQube ports for port_info in "${SONARQUBE_PORTS[@]}"; do local port="${port_info%%:*}" @@ -100,9 +271,9 @@ main() { failed=true fi done - + echo "" - + # Summary and recommendations if [ "$failed" = true ]; then echo -e "${YELLOW}⚠️ Some SonarQube ports are unavailable!${NC}" @@ -112,14 +283,14 @@ main() { echo "2. Use alternative ports (see suggestions below)" echo "3. Skip SonarQube setup (it's optional)" echo "" - + echo -e "${BLUE}💡 PORT ALTERNATIVES:${NC}" for port_info in "${unavailable_ports[@]}"; do local port="${port_info%%:*}" local description="${port_info#*:}" suggest_sonarqube_alternatives "$port" "$description" done - + echo -e "${YELLOW}💡 NOTE: SonarQube is optional. You can continue without it.${NC}" return 1 else @@ -129,15 +300,5 @@ main() { fi } -# Check if netcat is available -if ! command -v nc &> /dev/null; then - echo -e "${RED}❌ Error: 'nc' (netcat) is required but not installed.${NC}" - echo "Please install netcat:" - echo " macOS: brew install netcat" - echo " Ubuntu/Debian: sudo apt-get install netcat" - echo " CentOS/RHEL: sudo yum install nc" - exit 1 -fi - # Run the main function main "$@"