#!/bin/sh


#migrate DB
cd /var/www/html
while ! mysqladmin ping -h"db" --silent; do
    sleep 1
done
echo "Ready...."

sudo -u www-data -s -- <<EOF
    # Export variables for www-data user so they
    # are accessible when running wp CLI
    export WP_DB_HOST="$WP_DB_HOST"
    export MYSQL_DATABASE="$MYSQL_DATABASE"
    export MYSQL_USER="$MYSQL_USER"
    export MYSQL_PASSWORD="$MYSQL_PASSWORD"

    # Execute database update
    composer update-db

EOF

echo "Done"

chown -R www-data:www-data /var/www/html/app/uploads

#start image
exec apache2-foreground
