feature - 6 - fix dev compose issues

This commit is contained in:
myrmidex 2025-12-27 17:30:07 +01:00
parent 5a26120141
commit 630a8cc73f
5 changed files with 153 additions and 37 deletions

View file

@ -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 <<EOF
{
frankenphp {
worker {
file /app/public/index.php
num 1
watch
}
}
frankenphp
order php_server before file_server
}
@ -62,14 +57,6 @@ RUN cat > /etc/caddy/Caddyfile <<EOF
header {
X-Frame-Options "SAMEORIGIN"
}
# Show PHP errors in development
@phpFiles {
path *.php
}
header @phpFiles {
X-Debug-Mode "development"
}
}
EOF
@ -81,38 +68,62 @@ RUN cat > /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

0
bootstrap/cache/.gitignore vendored Normal file → Executable file
View file

2
package-lock.json generated
View file

@ -1,5 +1,5 @@
{
"name": "backend",
"name": "app",
"lockfileVersion": 3,
"requires": true,
"packages": {

97
shell.nix Normal file
View file

@ -0,0 +1,97 @@
{ pkgs ? import <nixpkgs> {} }:
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
'';
}

View file

@ -8,4 +8,12 @@ export default defineConfig({
refresh: true,
}),
],
server: {
host: '0.0.0.0',
port: 5173,
hmr: {
host: 'localhost',
port: 5173,
},
},
});