Skip to content

Conversation

chrislow
Copy link

@chrislow chrislow commented Nov 5, 2024

PR for #3

@DanielVera987
Copy link

Help with docker-compose?

@chrislow
Copy link
Author

i can try!

@mdaushi
Copy link

mdaushi commented Sep 26, 2025

Help with docker-compose?

After trying several approaches, I found that this method works for now:

You can still use Laravel Sail as usual, but with a slight modification to the start-container script:

#!/usr/bin/env bash

if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
    echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
    exit 1
fi

if [ ! -z "$WWWUSER" ]; then
    usermod -u $WWWUSER sail
fi

if [ ! -d /.composer ]; then
    mkdir /.composer
fi

chmod -R ugo+rw /.composer

# Fix Git dubious ownership
git config --global --add safe.directory /var/www/html
git config --global --add safe.directory '*'

# Make sure we are in the correct directory
cd /var/www/html

# Always install dependencies before optimization
echo "Installing Composer dependencies..."
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
    composer install --optimize-autoloader --no-dev --no-interaction
else
    gosu $WWWUSER composer install --optimize-autoloader --no-dev --no-interaction
fi

# Check if vendor/autoload.php exists
if [ ! -f "/var/www/html/vendor/autoload.php" ]; then
    echo "ERROR: vendor/autoload.php not found after composer install!"
    echo "Trying composer install again..."
    composer install --no-cache --optimize-autoloader --no-dev --no-interaction
fi

# Run production optimizations only if vendor exists
if [ -f "/var/www/html/vendor/autoload.php" ]; then
    echo "Running production optimizations..."

    # Wait for database to be ready
    echo "Waiting for database connection..."
    for i in {1..5}; do
        if php artisan migrate:status > /dev/null 2>&1; then
            echo "Database connection established."
            break
        fi
        echo "Waiting for database... ($i/5)"
        sleep 2
    done

    # Set permissions for writable folders
    chmod -R 777 /var/www/html/storage 2>/dev/null || true
    chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true

    # Ensure required storage folders exist
    mkdir -p /var/www/html/storage/framework/sessions 2>/dev/null || true
    mkdir -p /var/www/html/storage/framework/views 2>/dev/null || true
    mkdir -p /var/www/html/storage/framework/cache 2>/dev/null || true
    mkdir -p /var/www/html/storage/logs 2>/dev/null || true

    echo "Production optimizations completed."
else
    echo "Skipping production optimizations (APP_ENV: $APP_ENV, vendor exists: $([ -f '/var/www/html/vendor/autoload.php' ] && echo 'yes' || echo 'no'))"
fi

if [ $# -gt 0 ]; then
    if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
        exec "$@"
    else
        exec gosu $WWWUSER "$@"
    fi
else
    exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants