diff --git a/Makefile b/Makefile index 6e35a46..0cc8846 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,41 @@ -# Setup Git Hooks (no environment requirements) -setup-git-hooks: - @echo "SETUP: Installing 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!" +# ============================================================================= +# Local Full Setup - Complete Development Environment +# ============================================================================= -# Setup Husky hooks (called automatically by npm install) -setup-husky-hooks: - @echo "SETUP: Setting up Husky integration..." - @mkdir -p .husky - @echo '#!/usr/bin/env sh\n. "$$(dirname -- "$$0")/_/husky.sh"\n\n# Run the custom pre-commit script\n./.githooks/pre-commit' > .husky/pre-commit - @echo '#!/usr/bin/env sh\n. "$$(dirname -- "$$0")/_/husky.sh"\n\n# Run the custom pre-push script\n./.githooks/pre-push' > .husky/pre-push - @chmod +x .husky/pre-commit .husky/pre-push - @echo "SUCCESS: Husky hooks configured!" +# Complete local development setup (MAIN COMMAND) +local-setup: docker-cleanup docker-setup-env install-commit-tools setup-git-hooks + @echo "๐Ÿš€ SETUP: Complete local development environment..." + @echo "" + @echo "๐Ÿ“ฆ Setting up Docker containers..." + cd containers && docker-compose up -d + cd containers && docker-compose -f docker-compose.test.yml up -d + @echo "" + @echo "โณ Waiting for containers to be ready..." + @sleep 15 + @echo "" + @echo "๐Ÿ”ง Installing test dependencies..." + -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test composer install --no-interaction --prefer-dist --optimize-autoloader + -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan key:generate --env=testing --force + -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan migrate:fresh --seed --env=testing --force + @echo "" + @echo "โœ… SUCCESS: Local development environment setup complete!" + @echo "" + @echo "๐ŸŽฏ DEVELOPMENT ENVIRONMENT READY:" + @echo " - Laravel API: http://localhost:8081" + @echo " - Health Check: http://localhost:8081/api/health" + @echo " - MySQL: localhost:3306" + @echo " - Redis: localhost:6379" + @echo "" + @echo "๐Ÿงช TESTING ENVIRONMENT READY:" + @echo " - Test MySQL: localhost:3307" + @echo " - Test Redis: localhost:6380" + @echo "" + @echo "๐Ÿ› ๏ธ GIT TOOLS READY:" + @echo " - Semantic commits with Husky hooks" + @echo " - PHPStan and unit tests on push" + @echo " - make commit - Interactive semantic commits" + @echo "" + @echo "๐Ÿ“Š OPTIONAL: make sonarqube-setup - Setup SonarQube analysis" # Install Node.js dependencies for commit tools install-commit-tools: @@ -20,6 +43,13 @@ install-commit-tools: npm install @echo "SUCCESS: Commit tools installed!" +# Setup Git Hooks +setup-git-hooks: + @echo "SETUP: Installing 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!" + # Interactive semantic commit commit: @echo "๐Ÿš€ Starting interactive semantic commit..." @@ -30,46 +60,14 @@ validate-commit: @echo "VALIDATE: Checking commit message format..." npm run lint:commit -# Setup complete development environment -setup-dev: install-commit-tools setup-husky-hooks - @echo "SUCCESS: Development environment setup complete!" - @echo "" - @echo "๐ŸŽ‰ You're all set! Use the following commands:" - @echo " make commit - Create a semantic commit interactively" - @echo " make validate-commit - Validate the last commit message" - @echo " make release - Create a release (maintainers only)" - @echo "" - # Create a release (for maintainers) release: @echo "RELEASE: Creating release with release-please..." npm run release -# Run Code Linting in Docker -docker-lint: - @echo "LINT: Running Pint linter in Docker..." - docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/pint - @echo "SUCCESS: Linting completed!" - -# Run Code Linting (only recent changes) in Docker -docker-lint-dirty: - @echo "LINT: Running Pint linter on dirty files in Docker..." - docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/pint --dirty - @echo "SUCCESS: Dirty files linting completed!" - -# Run Static Analysis (Larastan) in Docker -docker-analyze: - @echo "ANALYZE: Running Larastan static analysis in Docker..." - docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/phpstan analyse --memory-limit=2G - @echo "SUCCESS: Static analysis completed!" - -# Run Artisan commands in Docker -docker-artisan: - @echo "ARTISAN: Running custom artisan command in Docker..." - @echo "Usage: make docker-artisan ARGS='migrate --seed'" - docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api php artisan $(ARGS) - +# ============================================================================= # Docker Environment Management +# ============================================================================= # Cleanup Docker environment (containers, images, volumes, networks) docker-cleanup: @@ -98,24 +96,9 @@ docker-verify-env: @echo "VERIFY: Docker environment setup..." bash containers/verify-env-setup.sh +# ============================================================================= # Docker Development Environment - -# Setup and start main development environment (full automated setup) -docker-dev: docker-cleanup docker-setup-env - @echo "SETUP: Starting main development environment..." - cd containers && docker-compose up -d - @echo ">> Waiting for containers to be ready..." - @echo ">> Main app will automatically:" - @echo " - Wait for database connection" - @echo " - Set up environment file" - @echo " - Install composer dependencies" - @echo " - Run migrations and seeders" - @echo " - Start web services" - @echo ">> Queue worker will automatically start processing jobs" - @echo ">> This may take a few minutes for initial setup..." - @echo ">> Use 'make docker-status' to check progress" - @echo ">> Use 'make docker-logs' to view detailed logs" - @echo "SUCCESS: Development environment started!" +# ============================================================================= # Start existing development environment (no rebuild) docker-up: @@ -133,92 +116,86 @@ docker-down: docker-restart: docker-down docker-up @echo "SUCCESS: Development environment restarted!" -# Rebuild and start development environment (force rebuild images) -docker-rebuild: docker-cleanup docker-setup-env - @echo "REBUILD: Docker development environment..." - cd containers && docker-compose build --no-cache - cd containers && docker-compose up -d - @echo "SUCCESS: Development environment rebuilt and started!" - -# Docker Testing Environment +# ============================================================================= +# Testing Environment +# ============================================================================= -# Setup and run tests (automated testing environment) -docker-test: docker-setup-env - @echo "TEST: Setting up and running tests..." +# Run tests (automated testing environment) +test: docker-setup-env + @echo "๐Ÿงช TESTING: Running complete test suite..." cd containers && docker-compose -f docker-compose.test.yml up -d @echo ">> Installing dependencies in test container..." @sleep 10 docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test composer install --no-interaction --prefer-dist --optimize-autoloader - @echo ">> Verifying test environment file exists..." - docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test test -f .env.testing || { echo "ERROR: .env.testing not found. Run 'make docker-setup-env' first."; exit 1; } - @echo ">> Generating test application key..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan key:generate --env=testing --force - @echo ">> Running test migrations and seeders..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan migrate:fresh --seed --env=testing --force @echo ">> Running tests..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan test --parallel --recreate-databases --stop-on-failure cd containers && docker-compose -f docker-compose.test.yml down - @echo "SUCCESS: Tests completed!" + @echo "โœ… SUCCESS: Tests completed!" # Run tests with coverage report -docker-test-coverage: docker-setup-env - @echo "TEST: Running tests with coverage..." +test-coverage: docker-setup-env + @echo "๐Ÿงช TESTING: Running tests with coverage..." cd containers && docker-compose -f docker-compose.test.yml up -d - @echo ">> Installing dependencies in test container..." @sleep 10 docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test composer install --no-interaction --prefer-dist --optimize-autoloader - @echo ">> Verifying test environment file exists..." - docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test test -f .env.testing || { echo "ERROR: .env.testing not found. Run 'make docker-setup-env' first."; exit 1; } - @echo ">> Generating test application key..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan key:generate --env=testing --force - @echo ">> Running test migrations and seeders..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan migrate:fresh --seed --env=testing --force @echo ">> Running tests with coverage..." docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan test --coverage --coverage-html reports/coverage --coverage-clover reports/coverage.xml --stop-on-failure --min=80 cd containers && docker-compose -f docker-compose.test.yml down - @echo "SUCCESS: Tests with coverage completed!" + @echo "โœ… SUCCESS: Tests with coverage completed!" -# Start test environment only (for debugging) -docker-test-up: - @echo "START: Docker test environment..." - cd containers && docker-compose -f docker-compose.test.yml up -d - @echo "SUCCESS: Test environment started!" +# ============================================================================= +# Code Quality Tools +# ============================================================================= -# Stop test environment -docker-test-down: - @echo "STOP: Docker test environment..." - cd containers && docker-compose -f docker-compose.test.yml down - @echo "SUCCESS: Test environment stopped!" +# Run Code Linting with Pint +lint: + @echo "๐Ÿ” LINT: Running Pint linter..." + docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/pint + @echo "SUCCESS: Linting completed!" + +# Run Code Linting (only recent changes) +lint-dirty: + @echo "๐Ÿ” LINT: Running Pint linter on dirty files..." + docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/pint --dirty + @echo "SUCCESS: Dirty files linting completed!" -# Docker Utilities +# Run Static Analysis (PHPStan) +analyze: + @echo "๐Ÿ” ANALYZE: Running PHPStan static analysis..." + docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/phpstan analyse --memory-limit=2G + @echo "SUCCESS: Static analysis completed!" + +# Run Artisan commands +artisan: + @echo "ARTISAN: Running custom artisan command..." + @echo "Usage: make artisan ARGS='migrate --seed'" + docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api php artisan $(ARGS) + +# ============================================================================= +# Container Utilities +# ============================================================================= # Access main container shell -docker-shell: +shell: @echo "SHELL: Accessing main container..." docker-compose -f containers/docker-compose.yml exec laravel_blog_api bash # Access test container shell -docker-test-shell: +test-shell: @echo "SHELL: Accessing test container..." docker-compose -f containers/docker-compose.test.yml exec laravel_blog_api_test bash # View logs from all containers -docker-logs: +logs: @echo "LOGS: Viewing container logs..." cd containers && docker-compose logs -f -# View logs from main app only -docker-logs-app: - @echo "LOGS: Viewing main app logs..." - cd containers && docker-compose logs -f laravel_blog_api - -# View logs from queue worker only -docker-logs-queue: - @echo "LOGS: Viewing queue worker logs..." - cd containers && docker-compose logs -f laravel_blog_api_queue - # Check container status and connection info -docker-status: +status: @echo "STATUS: Container information..." cd containers && docker-compose ps @echo "" @@ -229,14 +206,11 @@ docker-status: @echo " - Redis: localhost:6379" @echo "" @echo ">> Development Tools:" - @echo " - XDebug: Port 9003 (when enabled)" - @echo " - Application Shell: make docker-shell" - @echo " - Logs: make docker-logs" - -# Docker Health & Monitoring + @echo " - Application Shell: make shell" + @echo " - Logs: make logs" # Check application readiness and health -docker-health: +health: @echo "HEALTH: Checking application status..." @echo "" @echo "INFO: Main App Ready Marker:" @@ -253,91 +227,39 @@ docker-health: echo "ERROR: HTTP endpoint not accessible"; \ fi @echo "" - @echo "INFO: Queue Worker Status:" - @if docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api_queue pgrep -f "queue:work" >/dev/null 2>&1; then \ - echo "SUCCESS: Queue worker is running"; \ - else \ - echo "WAITING: Queue worker not running"; \ - fi - @echo "" @echo "INFO: Container Health Status:" @cd containers && docker-compose ps -# Check queue worker status -docker-queue-status: - @echo "QUEUE: Worker and job status..." - @echo "" - @echo "Queue Worker Process:" - @docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api_queue ps aux | grep "queue:work" || echo "Queue worker not running" - @echo "" - @echo "Queue Job Status:" - @docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api php artisan queue:work --stop-when-empty --max-jobs=0 2>/dev/null || echo "Cannot check queue status - application may not be ready" - -# Open application health endpoint in browser (Windows) -docker-open: - @echo "BROWSER: Opening health check endpoint..." - @echo "Attempting to open: http://localhost:8081/api/health" - @start http://localhost:8081/api/health || echo "Could not open browser automatically. Please visit: http://localhost:8081/api/health" - -# Complete Docker Setup - -# Comprehensive setup - Sets up both development and testing environments -docker-setup-all: docker-cleanup docker-setup-env - @echo "SETUP: Complete Docker environment (development + testing)..." - @echo "" - @echo "STEP 1: Setting up development environment..." - cd containers && docker-compose up -d - @echo "" - @echo "STEP 2: Waiting for development environment to be ready..." - @echo ">> This may take a few minutes for initial setup..." - @echo ">> Use 'make docker-status' to check progress" - @echo "" - @echo "STEP 3: Setting up testing environment..." - cd containers && docker-compose -f docker-compose.test.yml up -d - @echo ">> Installing dependencies in test container..." - @sleep 10 - -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test composer install --no-interaction --prefer-dist --optimize-autoloader - @echo ">> Verifying test environment file exists..." - -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test test -f .env.testing || echo "WARNING: .env.testing not found, tests may fail" - @echo ">> Generating test application key..." - -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan key:generate --env=testing --force - @echo ">> Running test migrations and seeders..." - -docker-compose -f containers/docker-compose.test.yml exec -T laravel_blog_api_test php artisan migrate:fresh --seed --env=testing --force - @echo "" - @echo "SUCCESS: Complete Docker environment setup finished!" - @echo "" - @echo "SUMMARY:" - @echo ">> Development API: http://localhost:8081" - @echo ">> Test environment: Ready for testing" - @echo ">> MySQL Main: localhost:3306" - @echo ">> MySQL Test: localhost:3307" - @echo ">> Redis: localhost:6379" - @echo "" - @echo "NEXT STEPS:" - @echo ">> Run 'make docker-status' to check all containers" - @echo ">> Run 'make docker-test' to run tests" - @echo ">> Access API at http://localhost:8081/api/health" - # ============================================================================= -# SonarQube Quality Analysis +# SonarQube Quality Analysis (Optional) # ============================================================================= -# Start SonarQube Server -docker-sonarqube-start: - @echo "SONARQUBE: Starting SonarQube server..." - cd containers && docker-compose -f docker-compose.sonarqube.yml up -d +# Complete SonarQube setup and analysis +sonarqube-setup: sonarqube-setup-env sonarqube-start + @echo "๐Ÿ” SONARQUBE: Complete setup and analysis..." @echo "โณ SonarQube is starting up... This may take a few minutes." @echo "๐Ÿ“Š SonarQube will be available at: http://localhost:9000" @echo " Default credentials: admin/admin" + @echo "" + @echo "๐Ÿ”ง NEXT STEPS:" + @echo "1. Visit http://localhost:9000 and login (admin/admin)" + @echo "2. Generate token at: Account โ†’ Security โ†’ Tokens" + @echo "3. Run: make sonarqube-setup-token" + @echo "4. Run: make sonarqube-analyze" + +# Start SonarQube Server +sonarqube-start: + @echo "SONARQUBE: Starting SonarQube server..." + cd containers && docker-compose -f docker-compose.sonarqube.yml up -d # Stop SonarQube Server -docker-sonarqube-stop: +sonarqube-stop: @echo "SONARQUBE: Stopping SonarQube server..." cd containers && docker-compose -f docker-compose.sonarqube.yml down @echo "SUCCESS: SonarQube server stopped!" # Setup SonarQube environment and token -docker-sonarqube-setup-token: +sonarqube-setup-token: @echo "SONARQUBE: Setting up SonarQube environment and token..." @echo "๐Ÿ“‹ Checking SonarQube environment configuration..." @if [ ! -f containers/.env.sonarqube ]; then \ @@ -356,7 +278,7 @@ docker-sonarqube-setup-token: @echo "SUCCESS: SonarQube environment setup completed!" # Setup SonarQube environment (create .env.sonarqube if missing) -docker-sonarqube-setup-env: +sonarqube-setup-env: @echo "SONARQUBE: Setting up SonarQube environment..." @if [ ! -f containers/.env.sonarqube ]; then \ echo "๐Ÿ“‹ Creating SonarQube environment file from example..."; \ @@ -380,14 +302,14 @@ docker-sonarqube-setup-env: @echo "SUCCESS: SonarQube environment setup completed!" # Run complete SonarQube analysis -docker-sonarqube-analyze: docker-sonarqube-setup-env docker-sonarqube-start +sonarqube-analyze: sonarqube-setup-env sonarqube-start @echo "SONARQUBE: Running complete quality analysis..." @echo "โš ๏ธ Make sure to set SONAR_TOKEN environment variable first!" @echo " Generate token at: http://localhost:9000/account/security" @if grep -q "^SONAR_TOKEN=" containers/.env.sonarqube && ! grep -q "^SONAR_TOKEN=your_token_here" containers/.env.sonarqube; then \ echo "โœ… SONAR_TOKEN is configured in .env.sonarqube"; \ else \ - echo "โŒ SONAR_TOKEN is not configured. Please run: make docker-sonarqube-setup-token"; \ + echo "โŒ SONAR_TOKEN is not configured. Please run: make sonarqube-setup-token"; \ echo " Current token status:"; \ grep -n "SONAR_TOKEN" containers/.env.sonarqube || echo " No SONAR_TOKEN found"; \ exit 1; \ @@ -395,137 +317,61 @@ docker-sonarqube-analyze: docker-sonarqube-setup-env docker-sonarqube-start ./containers/sonarqube/scripts/sonar-analysis.sh @echo "SUCCESS: SonarQube analysis completed!" -# Run SonarQube analysis (assumes server is already running) -docker-sonarqube-scan: docker-sonarqube-setup-env - @echo "SONARQUBE: Running SonarQube scanner..." - @echo "โš ๏ธ Make sure SONAR_TOKEN is set and SonarQube server is running!" - @if grep -q "^SONAR_TOKEN=" containers/.env.sonarqube && ! grep -q "^SONAR_TOKEN=your_token_here" containers/.env.sonarqube; then \ - echo "โœ… SONAR_TOKEN is configured in .env.sonarqube"; \ - else \ - echo "โŒ SONAR_TOKEN is not configured. Please run: make docker-sonarqube-setup-token"; \ - echo " Current token status:"; \ - grep -n "SONAR_TOKEN" containers/.env.sonarqube || echo " No SONAR_TOKEN found"; \ - exit 1; \ - fi - ./containers/sonarqube/scripts/sonar-analysis.sh - @echo "SUCCESS: SonarQube scan completed!" - -# Run SonarQube analysis for CI/CD (external SonarQube server) -docker-sonarqube-ci: - @echo "SONARQUBE: Running SonarQube analysis for CI/CD..." - @echo "โš ๏ธ Make sure SONAR_TOKEN and SONAR_HOST_URL are set!" - ./containers/sonarqube/scripts/sonar-analysis-ci.sh - @echo "SUCCESS: SonarQube CI analysis completed!" - -# Generate reports for SonarQube (without running scanner) -docker-sonarqube-reports: - @echo "SONARQUBE: Generating analysis reports..." - @echo ">> Running PHPStan analysis with JSON output..." - mkdir -p reports - docker-compose -f containers/docker-compose.yml exec -T laravel_blog_api ./vendor/bin/phpstan analyse --configuration=phpstan.neon --error-format=json > reports/phpstan.json || true - @echo ">> Running test coverage..." - $(MAKE) docker-test-coverage - @echo "SUCCESS: Reports generated in reports/ directory!" - $(MAKE) docker-test-coverage - @echo "SUCCESS: Reports generated in reports/ directory!" - # View SonarQube dashboard -docker-sonarqube-dashboard: +sonarqube-dashboard: @echo "๐Ÿ“Š Opening SonarQube dashboard..." open http://localhost:9000 || echo "Please open http://localhost:9000 in your browser" # Clean SonarQube data (reset everything) -docker-sonarqube-clean: +sonarqube-clean: @echo "SONARQUBE: Cleaning SonarQube data..." cd containers && docker-compose -f docker-compose.sonarqube.yml down -v @echo "SUCCESS: SonarQube data cleaned!" -# Docker-based commit workflow -docker-commit: - @echo "๐Ÿš€ Starting Docker-based semantic commit..." - docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run commit - -# Setup development environment with Docker -docker-setup-dev: - @echo "SETUP: Setting up development environment with Docker..." - docker-compose -f containers/docker-compose.dev.yml up -d - docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm install - @$(MAKE) setup-git-hooks - @echo "SUCCESS: Docker development environment setup complete!" - -# Validate commit in Docker -docker-validate-commit: - @echo "VALIDATE: Checking commit message format in Docker..." - docker-compose -f containers/docker-compose.dev.yml exec dev-tools npm run lint:commit - -# Clean up development environment -docker-cleanup-dev: - @echo "CLEANUP: Removing development containers..." - docker-compose -f containers/docker-compose.dev.yml down - @echo "SUCCESS: Development environment cleaned up!" +# ============================================================================= +# Help and Usage +# ============================================================================= # Show available commands and usage help: - @echo "Laravel Blog API - Docker-based Development Environment" - @echo "======================================================" + @echo "Laravel Blog API - Local Development Environment" + @echo "===============================================" @echo "" - @echo "Quick Start:" - @echo " make docker-dev - Setup and start development environment" - @echo " make docker-test - Run tests (includes setup)" - @echo " make docker-status - Check container status and access points" - @echo " make docker-health - Check application health" + @echo "๐Ÿš€ MAIN SETUP COMMAND:" + @echo " make local-setup - Complete local development setup" + @echo " (Docker containers + Testing + Git tools)" @echo "" - @echo "Environment Management:" - @echo " make docker-setup-env - Setup environment files" - @echo " make docker-verify-env - Verify environment setup" - @echo " make docker-setup-all - Setup both dev and test environments" - @echo " make docker-cleanup - Clean up all containers and resources" + @echo "๐Ÿ“Š OPTIONAL SETUP:" + @echo " make sonarqube-setup - Setup SonarQube code quality analysis" @echo "" - @echo "Development Environment:" - @echo " make docker-up - Start existing development environment" - @echo " make docker-down - Stop development environment" - @echo " make docker-restart - Restart development environment" - @echo " make docker-rebuild - Rebuild and start environment" + @echo "๐Ÿ”ง DEVELOPMENT WORKFLOW:" + @echo " make commit - Interactive semantic commit" + @echo " make test - Run all tests" + @echo " make test-coverage - Run tests with coverage report" + @echo " make lint - Run code linting (Pint)" + @echo " make analyze - Run static analysis (PHPStan)" @echo "" - @echo "Testing:" - @echo " make docker-test - Run all tests (automated setup)" - @echo " make docker-test-coverage - Run tests with coverage report" - @echo " make docker-test-up - Start test environment only" - @echo " make docker-test-down - Stop test environment" + @echo "๐Ÿณ CONTAINER MANAGEMENT:" + @echo " make docker-up - Start containers" + @echo " make docker-down - Stop containers" + @echo " make status - Check container status" + @echo " make health - Check application health" + @echo " make logs - View container logs" + @echo " make shell - Access main container shell" @echo "" - @echo "Code Quality:" - @echo " make docker-lint - Run code linting (Pint)" - @echo " make docker-lint-dirty - Lint only changed files" - @echo " make docker-analyze - Run static analysis (Larastan)" + @echo "๐Ÿ” SONARQUBE (OPTIONAL):" + @echo " make sonarqube-start - Start SonarQube server" + @echo " make sonarqube-analyze - Run code quality analysis" + @echo " make sonarqube-dashboard - Open SonarQube dashboard" + @echo " make sonarqube-stop - Stop SonarQube server" @echo "" - @echo "SonarQube Quality Analysis:" - @echo " make docker-sonarqube-start - Start SonarQube server" - @echo " make docker-sonarqube-stop - Stop SonarQube server" - @echo " make docker-sonarqube-setup-env - Setup SonarQube environment file" - @echo " make docker-sonarqube-setup-token - Setup SonarQube authentication token" - @echo " make docker-sonarqube-analyze - Run complete SonarQube analysis" - @echo " make docker-sonarqube-scan - Run SonarQube scanner only" - @echo " make docker-sonarqube-reports - Generate reports for SonarQube" - @echo " make docker-sonarqube-dashboard - Open SonarQube dashboard" - @echo " make docker-sonarqube-clean - Clean SonarQube data" - @echo "" - @echo "Utilities:" - @echo " make docker-shell - Access main container shell" - @echo " make docker-test-shell - Access test container shell" - @echo " make docker-logs - View all container logs" - @echo " make docker-logs-app - View main app logs" - @echo " make docker-logs-queue - View queue worker logs" - @echo " make docker-artisan ARGS='...' - Run artisan commands" - @echo " make docker-queue-status - Check queue worker status" - @echo " make docker-open - Open health endpoint in browser" - @echo "" - @echo "Git Tools:" - @echo " make setup-git-hooks - Install Git hooks (no env requirements)" + @echo "๐Ÿงน CLEANUP:" + @echo " make docker-cleanup - Clean up all containers and resources" @echo "" - @echo "Access Points:" + @echo "๐Ÿ“‹ ACCESS POINTS:" @echo " - Laravel API: http://localhost:8081" @echo " - Health Check: http://localhost:8081/api/health" - @echo " - SonarQube: http://localhost:9000" + @echo " - SonarQube: http://localhost:9000 (when started)" @echo " - MySQL: localhost:3306" @echo " - Redis: localhost:6379" diff --git a/README.md b/README.md index 6a40de7..fbeb8f1 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,52 @@ # Laravel Blog API -A clean, modern, and production-ready Laravel Blog API built with the latest versions of Laravel and PHP. This project follows a modern folder structure, applies the latest security best practices, and is designed for scalability. It serves as the backend API for a blog platform whose frontend will be built separately using Next.js. +A clean, modern, and production-ready Laravel Blog API built with the latest versions of Laravel and PHP. This project follows a modern folder structure, applies the latest security best practices, and is designed for scalability. --- ## Table of Contents -1. [API Documentation](#api-documentation) -2. [Docker Setup](#docker-setup) -3. [Semantic Commits & Releases](#semantic-commits--releases) - - [Quick Setup](#-quick-setup) - - [Commit Workflow](#-commit-workflow) - - [Commit Message Format](#-commit-message-format) - - [Commit Enforcement](#-commit-enforcement) - - [Automated Release Process](#-automated-release-process) - - [Available Commands](#๏ธ-available-commands) - - [Validation & Debugging](#-validation--debugging) -4. [Development Workflow](#development-workflow) -5. [Testing](#testing) -6. [Code Quality](#code-quality) -7. [SonarQube Analysis](#sonarqube-analysis) -8. [Git Hooks](#git-hooks) -9. [Quick Reference](#-quick-reference) -10. [Help & Troubleshooting](#help--troubleshooting) +1. [Quick Setup](#-quick-setup) +2. [API Documentation](#api-documentation) +3. [Development Workflow](#development-workflow) +4. [Testing](#testing) +5. [Code Quality](#code-quality) +6. [SonarQube Analysis (Optional)](#sonarqube-analysis-optional) +7. [Semantic Commits](#semantic-commits) +8. [Help & Troubleshooting](#help--troubleshooting) --- -## API Documentation - -Access the API documentation at: -``` -http://localhost:8081/docs/api -``` - ---- - -## Docker Setup - -This project uses **Docker exclusively** for both development and testing environments to ensure consistency across all platforms. The setup is **fully automated** with zero manual intervention required. +## ๐Ÿš€ Quick Setup ### Prerequisites - Docker and Docker Compose installed - Git (for hooks) +- Node.js 18+ (for commit tools) - Make (for Windows users: install via Chocolatey or use Git Bash) -### ๐Ÿš€ Quick Start (Recommended) +### Complete Local Development Setup -**One-command setup** for complete development environment: +**One command to set up everything:** ```bash -# Complete automated setup (development + testing environments) -make docker-dev +make local-setup ``` This single command will: -- โœ… Clean up any existing Docker containers and images -- โœ… **Automatically generate APP_KEY** for all environments using OpenSSL -- โœ… **Copy and configure environment files** from examples -- โœ… Start both development and testing Docker containers -- โœ… Install all Composer dependencies -- โœ… Run database migrations and seeders -- โœ… Set up queue workers with smart readiness detection -- โœ… Provide access URLs and next steps - -### Alternative Setup Options - -**Development environment only:** -```bash -make docker-dev -``` +- โœ… **Setup Docker containers** for Laravel API and testing +- โœ… **Install Composer dependencies** automatically +- โœ… **Configure databases** with migrations and seeders +- โœ… **Setup Git hooks** for code quality enforcement +- โœ… **Install semantic commit tools** (Husky, Commitizen) +- โœ… **Configure PHPStan and unit tests** on git push +- โœ… **Provide access URLs** and next steps -**Testing environment only:** -```bash -make docker-test -``` +### Optional: SonarQube Code Quality Analysis -**Environment files only:** ```bash -make docker-setup-env +make sonarqube-setup ``` ### ๐Ÿ“‹ Access Points @@ -88,384 +56,182 @@ After setup completion: - **API Health Check**: http://localhost:8081/api/health - **API Documentation**: http://localhost:8081/docs/api - **SonarQube Dashboard**: http://localhost:9000 (when started) -- **MySQL Main**: localhost:3306 (laravel_user/laravel_password) +- **MySQL**: localhost:3306 (laravel_user/laravel_password) - **MySQL Test**: localhost:3307 (laravel_user/laravel_password) - **Redis**: localhost:6379 -### ๏ฟฝ Environment File Structure - -This project maintains a clean environment file structure: - -**Tracked in Git:** -- `.env.docker.example` - Main development environment template -- `.env.testing.docker.example` - Testing environment template - -**Generated automatically (ignored by Git):** -- `.env` - Main development environment (Laravel's default) -- `.env.testing` - Testing environment (Laravel's testing default) - -All working environment files are automatically generated from templates with proper APP_KEY generation. - -### ๐Ÿ”ง Container Management - -```bash -# Check container status and access points -make docker-status - -# Check application health -make docker-health - -# View logs from all containers -make docker-logs - -# View specific container logs -make docker-logs-app # Main app logs -make docker-logs-queue # Queue worker logs +--- -# Container control -make docker-up # Start existing containers -make docker-down # Stop all containers -make docker-restart # Restart containers +## API Documentation -# Cleanup -make docker-cleanup # Complete cleanup (containers, images, volumes) +Access the API documentation at: +``` +http://localhost:8081/docs/api ``` --- ## Development Workflow -### Container Access +### Daily Development Commands ```bash -# Access main container shell -make docker-shell - -# Access test container shell (if test environment is running) -make docker-test-shell -``` +# Interactive semantic commit +make commit -### Running Artisan Commands +# Run tests +make test -```bash -# Run any artisan command in Docker -make docker-artisan ARGS="migrate --seed" -make docker-artisan ARGS="make:controller ApiController" -make docker-artisan ARGS="queue:work" -``` +# Run tests with coverage +make test-coverage -### Queue Management +# Code quality checks +make lint # Run Pint linter +make analyze # Run PHPStan static analysis -```bash -# Check queue worker status -make docker-queue-status - -# View queue worker logs -make docker-logs-queue +# Container management +make docker-up # Start containers +make docker-down # Stop containers +make status # Check container status +make logs # View logs +make shell # Access main container shell ``` -### Xdebug Configuration - -Xdebug is disabled by default for better performance but can be enabled: +### Artisan Commands ```bash -# Enable Xdebug for debugging -XDEBUG_MODE=debug make docker-dev - -# Enable for coverage reports -XDEBUG_MODE=coverage make docker-dev - -# Disable Xdebug (default) -XDEBUG_MODE=off make docker-dev +# Run any artisan command +make artisan ARGS="migrate --seed" +make artisan ARGS="make:controller ApiController" ``` --- ## Testing -This project uses PEST for testing with **automated Docker-based testing environment**. +This project uses **PEST** for testing with **automated Docker-based testing environment**. -### ๐Ÿงช Quick Testing +### Quick Testing -**Run all tests with automated setup:** ```bash -make docker-test -``` +# Run all tests with automated setup +make test -**Run tests with coverage report:** -```bash -make docker-test-coverage +# Run tests with coverage report +make test-coverage ``` ### Testing Environment Details -The automated testing setup creates: +The automated testing setup: - **Isolated test database**: `laravel_blog_test` on port 3307 - **Separate Redis instance**: For testing on port 6380 -- **Unique APP_KEY**: Generated specifically for test environment - **Fresh migrations**: Automatically run with seeders - -### Coverage Reports - -Coverage reports are generated at: -``` -reports/ - coverage/index.html # HTML coverage report - coverage.xml # XML coverage report for CI/CD -``` +- **Coverage reports**: Generated at `reports/coverage/index.html` ### Coverage Requirements -All tests enforce a **minimum of 80% code coverage**: -- Tests will fail if coverage falls below this threshold -- Reports highlight uncovered code paths -- Critical business logic must be properly tested - -### Manual Test Environment Management - -```bash -# Start test environment only (for debugging) -make docker-test-up - -# Stop test environment -make docker-test-down -``` +- **Minimum 80% code coverage** enforced +- **HTML reports** available at `reports/coverage/index.html` +- **XML reports** for CI/CD at `reports/coverage.xml` --- ## Code Quality ---- - -## SonarQube Analysis - -**Comprehensive code quality analysis** with SonarQube 25.7.0 Community Edition, integrated with PHPStan static analysis and PHPUnit test coverage. - -### ๐Ÿš€ Quick Start - -**Complete automated setup and analysis:** -```bash -make docker-sonarqube-analyze -``` - -This single command will: -- โœ… Setup SonarQube environment file if missing -- โœ… Start SonarQube server with PostgreSQL database -- โœ… Validate authentication token configuration -- โœ… Run PHPStan static analysis -- โœ… Execute PHPUnit tests with coverage -- โœ… Upload all results to SonarQube -- โœ… Open dashboard for review - -### ๐Ÿ”ง First-Time Setup - -**1. Environment Setup:** -```bash -make docker-sonarqube-setup-env -``` - -**2. Start SonarQube Server:** -```bash -make docker-sonarqube-start -``` - -**3. Configure Authentication Token:** -```bash -make docker-sonarqube-setup-token -``` - -This interactive helper will: -- Check if SonarQube server is running -- Guide you through token generation at http://localhost:9000 -- Automatically save the token to your environment file - -### ๐Ÿ“Š Analysis Features - -- **Code Quality**: Bugs, vulnerabilities, and code smells detection -- **Security Analysis**: Security hotspots and vulnerability scanning -- **Test Coverage**: PHPUnit test coverage integration -- **Static Analysis**: PHPStan results integration -- **Quality Gates**: Automated quality threshold enforcement -- **Technical Debt**: Measure and track technical debt -- **Code Duplication**: Detect duplicate code blocks - -### ๐ŸŽฏ Quality Standards - -The project enforces these quality standards: -- **Coverage**: โ‰ฅ 80% for new code -- **Duplications**: โ‰ค 3% for new code -- **Security Rating**: A (no vulnerabilities) -- **Maintainability Rating**: A -- **New Issues**: 0 (no new bugs or code smells) - -### ๐Ÿ“‹ Available Commands - -| Command | Description | -|---------|-------------| -| `make docker-sonarqube-analyze` | Complete analysis (recommended) | -| `make docker-sonarqube-start` | Start SonarQube server | -| `make docker-sonarqube-stop` | Stop SonarQube server | -| `make docker-sonarqube-setup-env` | Setup environment file | -| `make docker-sonarqube-setup-token` | Interactive token setup | -| `make docker-sonarqube-scan` | Run scanner only | -| `make docker-sonarqube-reports` | Generate reports only | -| `make docker-sonarqube-dashboard` | Open SonarQube dashboard | -| `make docker-sonarqube-clean` | Clean all data | -| `make docker-sonarqube-ci` | CI/CD analysis (external server) | - -### ๐ŸŒ Access Points - -- **SonarQube Dashboard**: http://localhost:9000 -- **Default Credentials**: admin/admin (change on first login) -- **Token Management**: http://localhost:9000/account/security - -### ๐Ÿ“š Documentation - -For detailed setup, configuration, and troubleshooting information, see: [containers/SONARQUBE.md](containers/SONARQUBE.md) - ---- - -### Linting with Pint - -**Automated code formatting** using Laravel Pint: +### Automated Code Quality Tools ```bash -# Lint entire project -make docker-lint +# Run linting with Laravel Pint +make lint # Lint only changed files (faster) -make docker-lint-dirty -``` +make lint-dirty -### Static Analysis with Larastan - -**Static code analysis** for better code quality: - -```bash -# Run static analysis -make docker-analyze +# Run static analysis with PHPStan +make analyze ``` -### Quality Checks +### Git Hooks -All code quality tools run within Docker containers: -- **No local PHP installation required** -- **Consistent results across all environments** -- **Integrated with testing workflow** +Automated quality checks on Git operations: +- **pre-commit**: Runs linting on changed files +- **pre-push**: Runs tests with PHPStan analysis +- **prepare-commit-msg**: Formats commit messages --- -## Git Hooks +## SonarQube Analysis (Optional) -Automate code quality checks on Git operations: +**Comprehensive code quality analysis** with SonarQube integration. -### Setup +### Quick Setup ```bash -# Install Git hooks (no environment requirements) -make setup-git-hooks +# Complete SonarQube setup +make sonarqube-setup ``` -### What the hooks do: +### Manual Setup Steps -- **pre-commit**: Runs linting on changed files -- **pre-push**: Runs tests with coverage validation -- **prepare-commit-msg**: Formats commit messages - -### Manual Hook Installation +1. **Start SonarQube server:** + ```bash + make sonarqube-start + ``` -If you prefer manual setup: -```bash -cp -r .githooks/ .git/hooks/ -chmod +x .git/hooks/pre-commit -chmod +x .git/hooks/pre-push -chmod +x .git/hooks/prepare-commit-msg -``` +2. **Generate authentication token:** + - Visit http://localhost:9000 (admin/admin) + - Go to Account โ†’ Security โ†’ Tokens + - Generate a new token ---- +3. **Configure token:** + ```bash + make sonarqube-setup-token + ``` -## Help & Troubleshooting +4. **Run analysis:** + ```bash + make sonarqube-analyze + ``` -### Getting Help +### SonarQube Features -```bash -# Show all available commands with descriptions -make help -``` - -### Common Issues - -1. **Port conflicts**: Ensure ports 8081, 3306, 3307, 6379 are not in use -2. **Docker not running**: Make sure Docker Desktop is running -3. **Permission issues**: On Linux/macOS, ensure your user is in the docker group - -### Container Architecture - -| Service | Container Name | Ports | Purpose | -|---------|---------------|-------|---------| -| **Laravel App** | `laravel_blog_api` | 8081:80 | Main application with Nginx + PHP-FPM | -| **MySQL** | `laravel_blog_api_mysql` | 3306:3306 | Development database | -| **Redis** | `laravel_blog_api_redis` | 6379:6379 | Cache and session store | -| **Queue Worker** | `laravel_blog_api_queue` | - | Background job processor | -| **MySQL Test** | `laravel_blog_api_mysql_test` | 3307:3306 | Testing database | -| **Redis Test** | `laravel_blog_api_redis_test` | 6380:6379 | Testing cache store | -| **SonarQube** | `laravel_blog_sonarqube` | 9000:9000 | Code quality analysis (when started) | -| **SonarQube DB** | `laravel_blog_sonarqube_db` | 5432:5432 | SonarQube PostgreSQL database | +- **Code Quality**: Bugs, vulnerabilities, code smells +- **Security Analysis**: Security hotspots and vulnerabilities +- **Test Coverage**: PHPUnit coverage integration +- **Static Analysis**: PHPStan results integration +- **Quality Gates**: Automated threshold enforcement -### Available Commands +### SonarQube Commands -For a complete list of all available commands, run: ```bash -make help +make sonarqube-start # Start SonarQube server +make sonarqube-analyze # Run complete analysis +make sonarqube-dashboard # Open dashboard +make sonarqube-stop # Stop SonarQube server ``` -Key command categories: -- **Environment Setup**: `docker-setup-*`, `docker-verify-env` -- **Development**: `docker-up`, `docker-down`, `docker-restart`, `docker-shell` -- **Testing**: `docker-test`, `docker-test-coverage`, `docker-test-*` -- **Code Quality**: `docker-lint`, `docker-analyze`, `docker-sonarqube-*` -- **Utilities**: `docker-logs`, `docker-status`, `docker-health` - ---- - -**Note:** This project is designed to work exclusively with Docker. All development, testing, and code quality tools are containerized for consistency and ease of use. - --- -## Semantic Commits & Releases +## Semantic Commits -This project enforces **semantic commits** following the [Conventional Commits](https://www.conventionalcommits.org/) specification and provides **automated releases** with changelog generation using **Commitizen**, **Commitlint**, and **Release Please**. +This project enforces **semantic commits** following the [Conventional Commits](https://www.conventionalcommits.org/) specification. -### ๐Ÿš€ Quick Setup +### Commit Workflow +**Interactive guided commits (recommended):** ```bash -# Complete setup with commit tools and git hooks -make setup-dev - -# OR Docker-based setup (works without Node.js) -make docker-setup-dev -``` - -### ๐Ÿ“ Commit Workflow - -#### **Option 1: Interactive Guided Commits (Recommended)** -```bash -# Local setup (requires Node.js) make commit - -# Docker-based (works anywhere) -make docker-commit ``` -#### **Option 2: Manual Commits (Auto-validated)** +**Manual commits (auto-validated):** ```bash git add . git commit -m "feat(auth): add user authentication endpoint" ``` -### ๏ฟฝ Commit Message Format +### Commit Message Format -All commits must follow this format: ``` [optional scope]: @@ -474,202 +240,127 @@ All commits must follow this format: [optional footer(s)] ``` -#### **Valid Types** -- `feat`: โœจ New feature -- `fix`: ๐Ÿ› Bug fix -- `docs`: ๐Ÿ“š Documentation changes -- `style`: ๐Ÿ’„ Code formatting (no logic changes) -- `refactor`: โ™ป๏ธ Code refactoring -- `test`: ๐Ÿงช Adding or updating tests -- `chore`: ๐Ÿ”ง Build process or auxiliary tools -- `perf`: โšก Performance improvements -- `ci`: ๐Ÿ‘ท CI configuration changes -- `build`: ๐Ÿ“ฆ Build system changes -- `revert`: โช Reverting previous commits - -#### **Examples** +**Valid types:** `feat`, `fix`, `docs`, `style`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`, `revert` + +**Examples:** ```bash feat(api): add user registration endpoint fix(auth): resolve token validation issue docs: update API documentation -refactor(user): simplify user model relationships -test(api): add integration tests for auth endpoints -chore(deps): update Laravel to v11 -perf(db): optimize user query performance -ci: add automated testing workflow +test(api): add integration tests for auth ``` -### ๐Ÿ”’ Commit Enforcement - -#### **Local Protection** -- **Git hooks** validate commit messages before push -- **Interactive guidance** for proper commit format -- **Helpful error messages** with examples - -#### **CI/CD Protection** -- **Pull request validation** checks all commits -- **GitHub Actions** enforce semantic commit format -- **Blocks merging** of invalid commits - -### ๐Ÿ“ฆ Automated Release Process - -Our automated release system works as follows: +### Automated Release Process -#### **1. Commit Analysis** -- **Release Please** analyzes all semantic commits -- **Determines version bump** based on commit types: - - `feat`: Minor version bump (1.0.0 โ†’ 1.1.0) - - `fix`: Patch version bump (1.0.0 โ†’ 1.0.1) - - `BREAKING CHANGE`: Major version bump (1.0.0 โ†’ 2.0.0) +- **Semantic versioning** based on commit types +- **Automated changelog** generation +- **GitHub releases** with proper tagging +- **Version bumping** in package files -#### **2. Release PR Creation** -When commits are pushed to main branch, Release Please automatically: -- **Creates a release PR** with version bump -- **Generates CHANGELOG.md** from commit history -- **Updates version numbers** in package files -- **Tags the release** when PR is merged +### Commit Commands -#### **3. GitHub Release** -Upon merging the release PR: -- **GitHub release** is created automatically -- **Docker images** are built and tagged -- **Deployment pipeline** can be triggered -- **Release notes** are generated from commits - -### ๐Ÿ› ๏ธ Available Commands - -#### **Setup Commands** ```bash -make setup-dev # Complete local setup -make docker-setup-dev # Docker-based setup -make install-commit-tools # Install Node.js dependencies only -make setup-git-hooks # Install git hooks only +make commit # Interactive semantic commit +make validate-commit # Validate recent commits +make release # Create release (maintainers only) ``` -#### **Commit Commands** -```bash -make commit # Interactive semantic commit (local) -make docker-commit # Interactive semantic commit (Docker) -make validate-commit # Validate recent commit messages -``` +--- -#### **Release Commands** -```bash -make release # Create release (maintainers only) -``` +## Help & Troubleshooting -### ๐Ÿ” Validation & Debugging +### Getting Help -#### **Check Commit History** ```bash -# Validate recent commits -make validate-commit - -# Check multiple commits -npx commitlint --from HEAD~5 --to HEAD - -# Validate specific commit -echo "your commit message" | npx commitlint +# Show all available commands with descriptions +make help ``` -#### **Common Issues & Solutions** - -**โŒ "Subject too long" error** -- Keep subject line under 72 characters -- Use `make commit` for guided input +### Most Common Commands -**โŒ "Type may not be empty" error** -- Ensure commit starts with valid type (feat, fix, etc.) -- Use format: `type(scope): description` +```bash +# Complete setup from scratch +make local-setup -**โŒ Git hooks not working** -- Run `make setup-git-hooks` -- Check hooks are executable: `ls -la .git/hooks/` +# Daily development workflow +make commit # Interactive semantic commit +make test # Run tests +make lint # Run code linting +make analyze # Run static analysis -**โŒ NPM/Node.js not available** -- Use Docker commands: `make docker-commit` -- Or install Node.js locally +# Container management +make docker-up # Start containers +make docker-down # Stop containers +make status # Check container status +make logs # View logs +make shell # Access container shell -### ๐Ÿ“Š Release Workflow Example +# Optional SonarQube +make sonarqube-setup # Setup SonarQube +make sonarqube-analyze # Run quality analysis -```bash -# 1. Make changes and commit with semantic format -git add . -make commit -# Select: feat -> API -> "add user search endpoint" - -# 2. Push to feature branch -git push origin feature/user-search +# Cleanup +make docker-cleanup # Clean up everything +``` -# 3. Create pull request -# CI validates all commits automatically +### Container Architecture -# 4. Merge to main branch -# Release Please analyzes commits +| Service | Container Name | Ports | Purpose | +|---------|---------------|-------|---------| +| **Laravel App** | `laravel_blog_api` | 8081:80 | Main application with Nginx + PHP-FPM | +| **MySQL** | `laravel_blog_api_mysql` | 3306:3306 | Development database | +| **Redis** | `laravel_blog_api_redis` | 6379:6379 | Cache and session store | +| **Queue Worker** | `laravel_blog_api_queue` | - | Background job processor | +| **MySQL Test** | `laravel_blog_api_mysql_test` | 3307:3306 | Testing database | +| **Redis Test** | `laravel_blog_api_redis_test` | 6380:6379 | Testing cache store | +| **SonarQube** | `laravel_blog_sonarqube` | 9000:9000 | Code quality analysis (optional) | -# 5. Release PR created automatically -# - Version: 1.2.0 (was 1.1.0, feat = minor bump) -# - Changelog: Generated from commits -# - Files: package.json, composer.json updated +### Common Issues -# 6. Merge release PR -# - GitHub release created: v1.2.0 -# - Docker images tagged: laravel-blog-api:1.2.0 -# - Deployment triggered (if configured) -``` +1. **Port conflicts**: Ensure ports 8081, 3306, 3307, 6379 are not in use +2. **Docker not running**: Make sure Docker Desktop is running +3. **Permission issues**: On Linux/macOS, ensure your user is in the docker group +4. **Node.js not found**: Install Node.js 18+ for commit tools -### ๐ŸŽฏ Benefits +### Support -โœ… **Consistent commit history** - Easy to understand project evolution -โœ… **Automated changelogs** - No manual maintenance required -โœ… **Semantic versioning** - Automatic version bumping -โœ… **Better collaboration** - Clear commit messages improve code review -โœ… **Release automation** - Streamlined deployment process -โœ… **Quality assurance** - Prevents bad commits from reaching main branch +- **View logs**: `make logs` +- **Check health**: `make health` +- **Container status**: `make status` +- **Full cleanup**: `make docker-cleanup` -### ๐Ÿ“š Additional Resources +--- -- **Detailed Guide**: [SEMANTIC-COMMITS.md](SEMANTIC-COMMITS.md) -- **Conventional Commits**: https://www.conventionalcommits.org/ -- **Commitizen**: https://github.com/commitizen/cz-cli -- **Release Please**: https://github.com/googleapis/release-please +**Note:** This project is designed to work with Docker containers for consistency across all development environments. All development tools and dependencies are containerized. --- ## ๐Ÿš€ Quick Reference -### Most Common Commands - +### Core Setup Commands ```bash -# Initial setup -make setup-dev # Setup commit tools + git hooks - -# Daily workflow -make commit # Interactive semantic commit -git add . && make commit # Stage and commit with guidance - -# Docker workflow (no Node.js required) -make docker-setup-dev # Setup with Docker -make docker-commit # Docker-based commit - -# Validation -make validate-commit # Check recent commits -npx commitlint --from HEAD~3 # Check multiple commits +make local-setup # Complete local development setup +make sonarqube-setup # Optional SonarQube setup (after local-setup) +``` -# Environment management -make docker-dev # Full development environment -make docker-test # Run all tests -make docker-cleanup # Clean up containers and volumes +### Daily Development +```bash +make commit # Interactive semantic commit +make test # Run tests +make lint # Code linting +make analyze # Static analysis ``` -### Commit Examples +### Container Management ```bash -feat(api): add user search endpoint -fix(auth): resolve token expiration issue -docs: update installation guide -test(api): add integration tests for users -chore(deps): update Laravel to v11 -refactor(auth): simplify login logic +make docker-up # Start containers +make docker-down # Stop containers +make docker-cleanup # Clean up everything ``` +### Access Points +- **API**: http://localhost:8081 +- **Health**: http://localhost:8081/api/health +- **SonarQube**: http://localhost:9000 (when started) + --- diff --git a/containers/README.md b/containers/README.md index 9eb833a..9614846 100644 --- a/containers/README.md +++ b/containers/README.md @@ -2,32 +2,37 @@ This directory contains all Docker configuration files for local development and testing of the Laravel Blog API project. -## ๐Ÿ“ Documentation +## ๏ฟฝ Quick Setup -- **[SONARQUBE.md](./SONARQUBE.md)** - Complete SonarQube 25.7.0 setup and usage guide +### Prerequisites +- Docker and Docker Compose installed +- Git (for hooks) +- Node.js 18+ (for commit tools) +- Make -## ๐Ÿ” SonarQube Quick Reference +### Complete Local Development Setup -### Essential Commands +**Main command (run from project root):** ```bash -# Start SonarQube server -make docker-sonarqube-start - -# Complete analysis (recommended) -make docker-sonarqube-analyze - -# Stop SonarQube server -make docker-sonarqube-stop +make local-setup ``` -### Setup Steps -1. `make docker-sonarqube-start` - Start server -2. Visit http://localhost:9000 (admin/admin) -3. Generate token at: Account โ†’ Security โ†’ Tokens -4. `export SONAR_TOKEN=squ_your_token` -5. `make docker-sonarqube-analyze` - Run analysis +This automated setup will: +- ๐Ÿงน Clean up any existing containers and images +- ๐Ÿ”‘ **Auto-generate unique APP_KEY** for all environments +- ๐Ÿ“ **Copy and configure** all environment files automatically +- ๐Ÿณ Start both **main AND testing** environments +- ๐Ÿ“ฆ Install Composer dependencies +- ๐Ÿ—„๏ธ Run database migrations and seeders +- โšก Set up queue workers with readiness detection +- ๐Ÿ› ๏ธ Install Git hooks and semantic commit tools +- โœ… Provide complete development and testing setup -**Full documentation**: [SONARQUBE.md](./SONARQUBE.md) +### Optional: SonarQube Code Quality Analysis + +```bash +make sonarqube-setup +``` ## ๐ŸŒŸ Environment Files @@ -43,60 +48,9 @@ This project uses a clean environment file structure: The automation scripts automatically create the working environment files from the example templates with proper APP_KEY generation. -## ๏ฟฝ๐Ÿš€ Quick Start - -### Prerequisites -- Docker and Docker Compose installed -- Git (for hooks) -- Make (for Windows users: install via Chocolatey or use Git Bash) - -### โšก Fully Automated Setup - -The Docker environment is **completely automated** with intelligent startup orchestration, automatic APP_KEY generation, and zero manual configuration required. - -#### **Option 1: Complete Setup (Recommended)** -```bash -make docker-setup-complete -``` -**What this does:** -- ๐Ÿงน Cleans up any existing containers and images -- ๐Ÿ”‘ **Auto-generates unique APP_KEY** for all environments -- ๐Ÿ“ **Copies and configures** all environment files automatically -- ๐Ÿณ Starts both **main AND testing** environments -- ๐Ÿ“ฆ Installs Composer dependencies -- ๐Ÿ—„๏ธ Runs database migrations and seeders -- โšก Sets up queue workers with readiness detection -- โœ… Provides complete development and testing setup - -#### **Option 2: Development Only** -```bash -make docker-setup-local -``` - -#### **Option 3: Testing Only** -```bash -make docker-setup-testing -``` - -### ๐Ÿ”‘ Automatic APP_KEY Generation - -**No more manual key generation!** -- Uses OpenSSL to generate secure base64-encoded keys -- Different unique keys for development and testing -- Automatically replaces empty APP_KEY in environment files -- Cross-platform compatible (Windows, macOS, Linux) - -### ๐Ÿ“ Environment File Automation - -**Intelligent environment file management:** -- `.env.docker.example` โ†’ `.env` (main development environment) -- `.env.testing.docker.example` โ†’ `.env.testing` (testing environment) -- Overwrites existing files for consistent setup -- Preserves custom configurations where appropriate - ## Architecture -### Services +### Main Services | Service | Container Name | Ports | Description | |---------|---------------|-------|-------------| @@ -110,71 +64,49 @@ make docker-setup-testing | Service | Container Name | Ports | Description | |---------|---------------|-------|-------------| | **Laravel Test** | `laravel_blog_api_test` | - | Testing environment | -| **MySQL Test** | `laravel_blog_api_mysql_test` | 3307:3306 | Temporary test database | +| **MySQL Test** | `laravel_blog_api_mysql_test` | 3307:3306 | Isolated test database | | **Redis Test** | `laravel_blog_api_redis_test` | 6380:6379 | Test cache store | -### Startup Orchestration - -The system includes robust startup orchestration: - -- **Health Checks**: All services have proper health checks -- **Dependency Management**: Containers start in correct order with `depends_on` and health conditions -- **Race Condition Prevention**: Queue worker waits for main app readiness before starting -- **Database Readiness**: Main app waits for MySQL connection before running migrations -- **Ready Marker**: Main app creates `/tmp/laravel_ready` marker when fully initialized - -## ๐Ÿ› ๏ธ Available Commands +### Optional: SonarQube Services -### ๐Ÿš€ Setup Commands (Fully Automated) -```bash -# Complete setup - main + testing environments (RECOMMENDED) -make docker-setup-complete +| Service | Container Name | Ports | Description | +|---------|---------------|-------|-------------| +| **SonarQube** | `laravel_blog_sonarqube` | 9000:9000 | Code quality analysis | +| **SonarQube DB** | `laravel_blog_sonarqube_db` | 5432:5432 | PostgreSQL database for SonarQube | -# Individual environment setup -make docker-setup-local # Development environment only -make docker-setup-testing # Testing environment only -make docker-setup-env # Environment files only (no containers) -``` +## ๐Ÿ› ๏ธ Available Commands (from project root) -### ๐Ÿ“Š Monitoring & Status +### ๐Ÿš€ Main Setup Commands ```bash -make docker-status # Container status and access URLs -make docker-logs # View all container logs (Ctrl+C to exit) -make docker-check-ready # Check application readiness -make docker-queue-status # Check queue worker status +make local-setup # Complete local development setup (MAIN COMMAND) +make sonarqube-setup # Optional SonarQube setup ``` -### ๐Ÿ”ง Container Management +### ๏ฟฝ Container Management ```bash make docker-up # Start containers only (no setup) make docker-down # Stop all containers -make docker-cleanup # Complete cleanup (containers, images, volumes) -make docker-cleanup-main # Cleanup main environment only -make docker-cleanup-testing # Cleanup testing environment only +make status # Container status and access URLs +make health # Check application health +make logs # View all container logs +make shell # Access main container shell ``` ### ๐Ÿงช Testing Operations ```bash -make docker-tests # Run tests with fresh database -make docker-tests-coverage # Run tests with HTML coverage report -make docker-test-up # Start test containers only -make docker-test-down # Stop test containers only +make test # Run tests with fresh database +make test-coverage # Run tests with HTML coverage report ``` -### ๐Ÿš Container Access +### ๏ฟฝ Code Quality ```bash -make docker-bash # Access main container shell -make docker-test-bash # Access test container shell +make lint # Run Pint linter +make analyze # Run PHPStan static analysis ``` -### ๐Ÿ”จ Advanced/Development +### ๐Ÿงน Cleanup ```bash -make docker-build-only # Build containers without full setup -make docker-rebuild # Rebuild images from scratch -make docker-rebuild # Rebuild Docker images from scratch - -# Environment management -make docker-setup-env # Setup environment files only +make docker-cleanup # Complete cleanup (containers, images, volumes) ``` ## Configuration @@ -186,7 +118,7 @@ The setup automatically creates and manages: - **`.env`** - Production-like local development environment (Laravel's default) - **`.env.testing`** - Testing environment configuration (Laravel's testing default) -Environment files are created via `make docker-setup-env` or automatically during `make docker-setup-local`. +Environment files are created automatically during `make local-setup`. ### PHP Configuration @@ -199,13 +131,13 @@ Environment files are created via `make docker-setup-env` or automatically durin ```bash # Disable Xdebug for better performance (default) -XDEBUG_MODE=off make docker-setup-local +XDEBUG_MODE=off make local-setup # Enable Xdebug for debugging -XDEBUG_MODE=debug make docker-setup-local +XDEBUG_MODE=debug make local-setup # Enable for coverage reports -XDEBUG_MODE=coverage make docker-setup-local +XDEBUG_MODE=coverage make local-setup ``` ### Database Access @@ -251,13 +183,10 @@ All services include comprehensive health checks: ```bash # Quick status overview -make docker-status +make status -# Detailed readiness check -make docker-check-ready - -# Queue worker specific status -make docker-queue-status +# Detailed health check +make health # View health check endpoint curl http://localhost:8081/api/health @@ -269,67 +198,12 @@ curl http://localhost:8081/api/health - **Subsequent Starts**: 30-60 seconds - **Health Check Grace Period**: 5 minutes for full initialization -## Testing and CI/CD - -### Automated Testing on Git Push - -The project includes a pre-push git hook that automatically: - -1. Starts test containers -2. Runs the full test suite with coverage -3. Runs PHPStan analysis -4. Stops test containers -5. Blocks push if any tests fail - -### Manual Testing - -```bash -# Run all tests with automated setup -make docker-tests - -# Run tests with coverage report (available in reports/coverage) -make docker-tests-coverage - -# Setup testing environment only -make docker-setup-testing -``` - -## Debugging and Development - -### Xdebug Configuration - -Xdebug is pre-configured and available on port 9003. Configure your IDE: - -- **Host:** `localhost` -- **Port:** `9003` -- **IDE Key:** `docker` -- **Path Mappings:** `/var/www/html` โ†’ `{your-project-path}` - -To enable Xdebug: -```bash -XDEBUG_MODE=debug make docker-setup-local -``` - -### Container Access - -```bash -# Access main application container -make docker-bash - -# Access test container -make docker-test-bash - -# View real-time logs -make docker-logs -``` - -### Common Issues and Solutions +## Common Issues and Solutions 1. **Port conflicts:** If ports are already in use, modify the port mappings in `docker-compose.yml` 2. **Permission issues:** Ensure Docker has access to your project directory -3. **Database connection errors:** Use `make docker-check-ready` to verify database is ready -4. **Containers not starting:** Run `make docker-cleanup` then `make docker-setup-local` -5. **Queue worker not processing:** Check with `make docker-queue-status` +3. **Database connection errors:** Use `make health` to verify database is ready +4. **Containers not starting:** Run `make docker-cleanup` then `make local-setup` ## File Structure @@ -337,7 +211,12 @@ make docker-logs containers/ โ”œโ”€โ”€ docker-compose.yml # Main development environment โ”œโ”€โ”€ docker-compose.test.yml # Testing environment +โ”œโ”€โ”€ docker-compose.sonarqube.yml # SonarQube environment โ”œโ”€โ”€ setup-env.sh # Environment setup script +โ”œโ”€โ”€ verify-env-setup.sh # Environment verification script +โ”œโ”€โ”€ start-main-app.sh # Application startup script +โ”œโ”€โ”€ start-queue-worker.sh # Queue worker startup script +โ”œโ”€โ”€ start-services.sh # Service orchestration script โ”œโ”€โ”€ php/ โ”‚ โ”œโ”€โ”€ Dockerfile # PHP-FPM + Nginx image โ”‚ โ”œโ”€โ”€ php.ini # Custom PHP configuration @@ -347,64 +226,27 @@ containers/ โ”œโ”€โ”€ mysql/ โ”‚ โ””โ”€โ”€ my.cnf # MySQL configuration โ”œโ”€โ”€ redis/ -โ”‚ โ””โ”€โ”€ redis.conf # Redis configuration (if needed) +โ”‚ โ””โ”€โ”€ redis.conf # Redis configuration โ”œโ”€โ”€ supervisor/ โ”‚ โ””โ”€โ”€ supervisord.conf # Process manager configuration -โ”œโ”€โ”€ start-main-app.sh # Main application startup script -โ”œโ”€โ”€ start-queue-worker.sh # Queue worker startup script -โ”œโ”€โ”€ start-services.sh # Service orchestration script -โ””โ”€โ”€ README.md # This documentation +โ””โ”€โ”€ sonarqube/ # SonarQube configuration and scripts ``` -## Security Notes - -- MySQL and Redis are configured for development use -- Default passwords should be changed for production -- Xdebug should be disabled in production environments (`XDEBUG_MODE=off`) -- All services are isolated within Docker networks -- Container startup is fully automated with proper security practices - -## Performance Optimization - -### Volume Mounts -- Code is mounted for instant file changes during development -- Database and Redis use named volumes for persistence -- Test environment uses optimized settings for faster execution - -### Resource Allocation -- MySQL: 256MB buffer pool -- Redis: 256MB max memory -- PHP: 512MB memory limit -- Xdebug: Disabled by default for better performance - -### Startup Performance -- Smart dependency management prevents unnecessary waits -- Health checks optimize container readiness detection -- Queue worker starts only after main app is fully ready - ---- - -**Need help?** -- Check the main project README for general setup -- Use `make docker-check-ready` to diagnose issues -- View logs with `make docker-logs` -- Create an issue in the repository for bugs - ## Quick Reference -### Most Common Commands +### Most Common Commands (from project root) ```bash # Complete setup from scratch -make docker-setup-local +make local-setup # Check if everything is working -make docker-status -make docker-check-ready +make status +make health # Development workflow -make docker-logs # View logs -make docker-bash # Access container -make docker-down # Stop when done +make logs # View logs +make shell # Access container +make docker-down # Stop when done # Reset everything make docker-cleanup @@ -415,13 +257,12 @@ make docker-cleanup - **Health Check**: http://localhost:8081/api/health - **MySQL**: localhost:3306 (user: laravel_user, password: laravel_password) - **Redis**: localhost:6379 - -### File Overview -- `docker-compose.yml` - Main development environment -- `docker-compose.test.yml` - Testing environment -- `setup-env.sh` - Environment file creation -- `start-main-app.sh` - Application startup orchestration -- `start-queue-worker.sh` - Queue worker with readiness detection -- `start-services.sh` - Container service management +- **SonarQube**: http://localhost:9000 (when started) --- + +**Need help?** +- Check the main project README for general setup +- Use `make health` to diagnose issues +- View logs with `make logs` +- Create an issue in the repository for bugs diff --git a/containers/WINDOWS-SETUP.md b/containers/WINDOWS-SETUP.md deleted file mode 100644 index aab6506..0000000 --- a/containers/WINDOWS-SETUP.md +++ /dev/null @@ -1,346 +0,0 @@ -# Laravel Blog API - Docker Setup Guide for Windows - -This guide will help you set up the **fully automated** Docker development environment for the Laravel Blog API project on Windows. **Zero manual configuration required!** - -## Prerequisites - -1. **Docker Desktop for Windows** - - Download from: https://www.docker.com/products/docker-desktop - - Ensure WSL 2 backend is enabled - - Allocate at least 4GB RAM to Docker - - Verify installation: `docker --version` - -2. **Git for Windows** - - Download from: https://git-scm.windows.com/ - - Includes Git Bash which is required for shell scripts - - Verify installation: `git --version` - -3. **Make for Windows** (Optional but recommended) - - Install via Chocolatey: `choco install make` - - Or install manually from: http://gnuwin32.sourceforge.net/packages/make.htm - - Alternative: Use Git Bash for all make commands - -## ๐Ÿš€ Quick Start (Fully Automated) - -### โšก One-Command Complete Setup (Recommended) - -Open Git Bash, PowerShell, or Command Prompt in the project root: - -```bash -# Complete automated setup - main + testing environments -make docker-setup-complete -``` - -**๐ŸŽ‰ That's it! This single command will:** -- โœ… **Clean up** any existing Docker containers and images -- โœ… **Auto-generate APP_KEY** using OpenSSL (unique keys for dev/test) -- โœ… **Copy and configure** all environment files automatically -- โœ… **Start main environment** (API on http://localhost:8081) -- โœ… **Start testing environment** (isolated test database) -- โœ… **Install dependencies** automatically -- โœ… **Run migrations and seeders** for both environments -- โœ… **Setup queue workers** with smart readiness detection -- โœ… **Display access URLs** and next steps - -### Alternative Options - -**Development environment only:** -```bash -make docker-setup-local -``` - -**Testing environment only:** -```bash -make docker-setup-testing -``` - -## ๐Ÿ”‘ Automatic APP_KEY Generation - -**No more manual key generation or environment file editing!** - -- Uses OpenSSL (included with Git Bash) to generate secure keys -- Creates different unique keys for development and testing -- Automatically replaces empty `APP_KEY=` in all environment files -- Works seamlessly on Windows (Git Bash), WSL, or PowerShell - -### Step-by-Step Process (All Automated) - -1. **Environment File Creation:** - - `.env.docker.example` โ†’ `.env` (main development environment) - - `.env.testing.docker.example` โ†’ `.env.testing` (testing environment) - -2. **APP_KEY Generation:** - - Development: `APP_KEY=base64:xxxxxxxxxxxx` - - Testing: `APP_KEY=base64:yyyyyyyyyyyy` (different key) - -3. **Container Orchestration:** - - MySQL and Redis start first (with health checks) - - Laravel app waits for database connectivity -## ๐Ÿ“Š After Setup - Access Points - -**๐ŸŽฏ Your applications are ready at:** - -| Service | URL | Description | -|---------|-----|-------------| -| **Main API** | http://localhost:8081 | Laravel application | -| **API Health** | http://localhost:8081/api/health | Health check endpoint | -| **API Docs** | http://localhost:8081/docs/api | API documentation | -| **MySQL Main** | localhost:3306 | Development database | -| **MySQL Test** | localhost:3307 | Testing database | -| **Redis** | localhost:6379 | Cache/sessions | - -**๐Ÿ” Database Credentials:** -- Username: `laravel_user` -- Password: `laravel_password` -- Main DB: `laravel_blog` -- Test DB: `laravel_blog_test` - -## ๐Ÿ”ง Monitoring & Management - -### Real-time Status Monitoring - -```bash -# Check if everything is running and healthy -make docker-status - -# Detailed readiness check -make docker-check-ready - -# View live logs from all containers (Ctrl+C to exit) -make docker-logs - -# Check queue worker status specifically -make docker-queue-status -``` - -## ๐Ÿ“‹ Available Commands (Windows Compatible) - -All commands work perfectly in **Windows Command Prompt**, **PowerShell**, and **Git Bash**: - -### ๐Ÿš€ Setup Commands -```cmd -rem Complete setup - main + testing (RECOMMENDED) -make docker-setup-complete - -rem Individual environment setup -make docker-setup-local rem Development only -make docker-setup-testing rem Testing only -make docker-setup-env rem Environment files only -``` - -### ๐Ÿ“Š Monitoring Commands -```cmd -rem Status and health monitoring -make docker-status rem Container status + URLs -make docker-check-ready rem Application readiness -make docker-logs rem Live logs (Ctrl+C to exit) -make docker-queue-status rem Queue worker status -``` - -### ๐Ÿ› ๏ธ Management Commands -```cmd -rem Container management -make docker-up rem Start containers only -make docker-down rem Stop all containers -make docker-cleanup rem Complete cleanup - -rem Container access -make docker-bash rem Access main container -make docker-test-bash rem Access test container -``` - -### ๐Ÿงช Testing Commands -```cmd -rem Automated testing -make docker-tests rem Run tests with fresh DB -make docker-tests-coverage rem Tests with coverage report -``` - -## Windows-Specific Considerations - -### Character Encoding -- All output has been optimized for Windows terminals -- No emoji or Unicode characters that cause display issues -- Clean, readable status messages in Command Prompt and PowerShell - -### Path Handling -- All volume mounts work correctly with Windows paths -- No path conversion issues between Windows and containers -- Proper handling of file permissions - -### Performance on Windows -- Optimized volume mounts for Windows Docker Desktop -- Reasonable startup times (2-5 minutes for initial setup) -- Good development performance with file watching - -## Troubleshooting Windows Issues - -### Common Problems and Solutions - -1. **Docker is not running** - ```bash - # Error: Cannot connect to the Docker daemon - # Solution: Start Docker Desktop and wait for it to fully initialize - ``` - -2. **Port conflicts** - ```bash - # Error: Port already in use - # Solution: Stop other services or modify ports in docker-compose.yml - netstat -ano | findstr :8081 - ``` - -3. **Permission denied errors** - ```bash - # Solution: Ensure Docker Desktop has access to your drive - # Docker Desktop -> Settings -> Resources -> File Sharing - ``` - -4. **Make command not found** - ```bash - # If you don't have make installed, use Git Bash: - # Open Git Bash and run make commands from there - ``` - -5. **Container startup issues** - ```bash - # Solution: Clean reset and retry - make docker-cleanup - make docker-setup-local - ``` - -### Windows Terminal Configuration - -For the best experience, use one of these terminals: - -1. **Git Bash** (Recommended) - - Comes with Git for Windows - - Full Unix-like environment - - All commands work perfectly - -2. **Windows Terminal** (Modern) - - Download from Microsoft Store - - Better display and color support - - Multiple tab support - -3. **PowerShell** (Built-in) - - Available on all Windows systems - - Good compatibility with make commands - -### File Watching and Development - -Windows file watching works well with this setup: -- Code changes are immediately reflected in containers -- No need to restart containers for code changes -- Laravel's file watching works correctly - -## Xdebug Setup for Windows IDEs - -### PHPStorm Configuration - -1. **Configure PHP Interpreter:** - - File -> Settings -> PHP -> CLI Interpreter - - Add new Docker Compose interpreter - - Service: `laravel_blog_api` - -2. **Configure Xdebug:** - - File -> Settings -> PHP -> Debug - - Port: `9003` - - Check "Can accept external connections" - -3. **Path Mappings:** - - Local path: `C:\your\project\path` - - Remote path: `/var/www/html` - -### VS Code Configuration - -Add to `.vscode/launch.json`: -```json -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Listen for Xdebug", - "type": "php", - "request": "launch", - "port": 9003, - "pathMappings": { - "/var/www/html": "${workspaceFolder}" - } - } - ] -} -``` - -## Performance Tips for Windows - -### Optimize Docker Desktop - -1. **Resource Allocation:** - - CPU: At least 2 cores - - Memory: 4GB minimum, 8GB recommended - - Disk: Enable fast disk access - -2. **WSL 2 Backend:** - - Ensure WSL 2 is enabled (much faster than Hyper-V) - - Keep project files in WSL 2 file system for best performance - -3. **Exclude from Antivirus:** - - Add Docker Desktop folder to antivirus exclusions - - Add project folder to exclusions - -### Development Workflow - -```bash -# Start development session -make docker-setup-local - -# During development, containers stay running -# Make code changes - they're reflected immediately -# No need to restart containers - -# When finished for the day -make docker-down - -# For complete cleanup (weekly) -make docker-cleanup -``` - -## Getting Help - -### Debug Information Commands - -```bash -# Get comprehensive status -make docker-check-ready - -# View logs for troubleshooting -make docker-logs - -# Check specific container -docker logs laravel_blog_api - -# Test database connectivity -make docker-bash -# Then inside container: -php artisan tinker -# DB::connection()->getPdo(); // Should not throw error -``` - -### Resources - -- **Main README**: `../README.md` for general project information -- **Docker README**: `README.md` for detailed Docker configuration -- **Health Check**: http://localhost:8081/api/health for live status -- **Database**: Connect to localhost:3306 with your favorite DB tool -- **Redis**: Connect to localhost:6379 for cache inspection - ---- - -**Success!** Once setup is complete, you'll have a fully automated, robust Laravel development environment running on Windows with: -- Automatic startup orchestration -- Health monitoring -- Queue processing -- Database migrations -- Clean Windows terminal output -- Full Xdebug support diff --git a/containers/docker-compose.dev.yml b/containers/docker-compose.dev.yml deleted file mode 100644 index 9acef27..0000000 --- a/containers/docker-compose.dev.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: laravel_blog_dev - -services: - # Development tools container - dev-tools: - build: - context: . - dockerfile: php/Dockerfile - container_name: laravel_blog_dev_tools - working_dir: /var/www/html - volumes: - - ../:/var/www/html - - ~/.gitconfig:/root/.gitconfig:ro - - ~/.ssh:/root/.ssh:ro - environment: - - NODE_ENV=development - command: tail -f /dev/null # Keep container running - networks: - - laravel_blog_api_network - -networks: - laravel_blog_api_network: - external: true