From 630a8cc73f5e426c9cbb259c1a48ca3a06d386ec Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sat, 27 Dec 2025 17:30:07 +0100 Subject: [PATCH] feature - 6 - fix dev compose issues --- Dockerfile.dev | 83 ++++++++++++++++++-------------- bootstrap/cache/.gitignore | 0 package-lock.json | 2 +- shell.nix | 97 ++++++++++++++++++++++++++++++++++++++ vite.config.js | 8 ++++ 5 files changed, 153 insertions(+), 37 deletions(-) mode change 100644 => 100755 bootstrap/cache/.gitignore create mode 100644 shell.nix diff --git a/Dockerfile.dev b/Dockerfile.dev index 958f2f2..1ef1399 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -29,21 +29,16 @@ WORKDIR /app # Configure PHP for development RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" -# Configure Xdebug -RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ - && echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ - && echo "xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +# Configure Xdebug (disabled by default to reduce noise) +RUN echo "xdebug.mode=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo ";xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo ";xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo ";xdebug.start_with_request=yes" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini -# Configure Caddy for development with file watching +# Configure Caddy for development (simpler, no worker mode) RUN cat > /etc/caddy/Caddyfile < /etc/caddy/Caddyfile < /start.sh <<'EOF' #!/bin/sh set -e -# Install/update composer dependencies if needed -if [ ! -d "vendor" ]; then +# Ensure all required Laravel directories exist +mkdir -p /app/bootstrap/cache +mkdir -p /app/storage/app/public +mkdir -p /app/storage/framework/cache/data +mkdir -p /app/storage/framework/sessions +mkdir -p /app/storage/framework/testing +mkdir -p /app/storage/framework/views +mkdir -p /app/storage/logs + +# Set permissions - use www-data user +chown -R www-data:www-data /app/storage /app/bootstrap/cache +chmod -R 775 /app/storage /app/bootstrap/cache + +# Create cache directories with proper permissions +mkdir -p /app/storage/framework/cache/data +chown -R www-data:www-data /app/storage/framework/cache +chmod -R 775 /app/storage/framework/cache + +# Check if vendor exists in the volume +if [ ! -f "vendor/autoload.php" ]; then echo "Installing composer dependencies..." composer install +else + echo "Composer dependencies found, skipping install..." fi -# Install/update npm dependencies if needed -if [ ! -d "node_modules" ]; then +# Check if node_modules exists in the volume +if [ ! -f "node_modules/.bin/vite" ]; then echo "Installing npm dependencies..." npm install +else + echo "Node modules found, skipping npm install..." fi -# Clear Laravel caches for development -php artisan config:clear -php artisan cache:clear -php artisan route:clear -php artisan view:clear - -# Ensure storage permissions -chown -R www-data:www-data /app/storage /app/bootstrap/cache -chmod -R 777 /app/storage /app/bootstrap/cache +# Run Laravel commands as www-data to avoid permission issues +su -s /bin/sh www-data -c "php artisan config:clear" || true +su -s /bin/sh www-data -c "php artisan cache:clear" || true +su -s /bin/sh www-data -c "php artisan route:clear" || true +su -s /bin/sh www-data -c "php artisan view:clear" || true # Run migrations if database is ready echo "Waiting for database..." sleep 5 -php artisan migrate --force || echo "Migration failed or not needed" +su -s /bin/sh www-data -c "php artisan migrate --force" || echo "Migration failed or not needed" + +# Generate app key if not set +if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:YOUR_KEY_HERE" ]; then + echo "Generating application key..." + su -s /bin/sh www-data -c "php artisan key:generate" +fi # Start Vite dev server in background for hot reload npm run dev & -# Start FrankenPHP -exec frankenphp run --config /etc/caddy/Caddyfile --watch +# Start FrankenPHP (runs as root in dev for simplicity) +exec frankenphp run --config /etc/caddy/Caddyfile EOF RUN chmod +x /start.sh diff --git a/bootstrap/cache/.gitignore b/bootstrap/cache/.gitignore old mode 100644 new mode 100755 diff --git a/package-lock.json b/package-lock.json index e8eac3c..09088a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "backend", + "name": "app", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..fb1f0f9 --- /dev/null +++ b/shell.nix @@ -0,0 +1,97 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + buildInputs = with pkgs; [ + # PHP and tools + php83 + php83Packages.composer + + # Node.js and npm + nodejs_20 + + # Container tools + podman + podman-compose + + # Database client (optional, for direct DB access) + mariadb-client + + # Utilities + git + curl + gnumake + ]; + + shellHook = '' + # Define helper functions + rebuild() { + echo "🔨 Rebuilding development environment..." + podman-compose down -v + podman-compose build --no-cache app + podman-compose up -d + echo "✅ Rebuild complete! Check logs with: podman-compose logs -f app" + } + + rebuild-quick() { + echo "⚡ Quick rebuild (keeping volumes)..." + podman-compose down + podman-compose build app + podman-compose up -d + echo "✅ Quick rebuild complete!" + } + + logs() { + podman-compose logs -f "$@" + } + + shell() { + podman-compose exec app sh + } + + artisan() { + podman-compose exec app php artisan "$@" + } + + echo "🚀 Dish Planner Development Environment" + echo "=======================================" + echo "PHP: $(php --version | head -n1)" + echo "Node: $(node --version)" + echo "Podman: $(podman --version)" + echo "Podman-compose: $(podman-compose --version 2>/dev/null || echo 'checking...')" + echo "" + echo "Quick commands:" + echo " rebuild - Full rebuild (removes volumes)" + echo " rebuild-quick - Quick rebuild (keeps volumes)" + echo " logs [service] - Follow logs (default: all)" + echo " shell - Enter app container" + echo " artisan [cmd] - Run artisan commands" + echo "" + echo "Standard commands:" + echo " podman-compose up -d - Start containers" + echo " podman-compose down - Stop containers" + echo " make dev - Start via Makefile" + echo "" + + # Auto-start prompt + if [ -f "docker-compose.yml" ]; then + read -p "Start development containers? (y/N) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Starting containers..." + podman-compose up -d + + # Wait a moment for containers to start + sleep 3 + + echo "" + echo "✅ Services should be available at:" + echo " App: http://localhost:8000" + echo " Vite: http://localhost:5173" + echo " Mailhog: http://localhost:8025" + echo " MariaDB: localhost:3306" + echo "" + echo "Run 'podman-compose logs -f app' to follow logs" + fi + fi + ''; +} \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 421b569..0f996c9 100644 --- a/vite.config.js +++ b/vite.config.js @@ -8,4 +8,12 @@ export default defineConfig({ refresh: true, }), ], + server: { + host: '0.0.0.0', + port: 5173, + hmr: { + host: 'localhost', + port: 5173, + }, + }, });