Made it workable on docker containers

This commit is contained in:
Frank van den Berg
2026-01-06 19:48:33 +01:00
parent 91c0c3e6d1
commit 3de1e907f2
3 changed files with 58 additions and 15 deletions

37
docker/setup.sh Normal file → Executable file
View File

@@ -66,12 +66,15 @@ dc up "${BUILD_ARGS[@]}"
# Helper to run commands in php container
pexec() { dc exec -T php "$@"; }
# Wait for database to be healthy (mariadb)
# Wait for database to be healthy (mariadb/mysql)
printf "Waiting for database to be healthy..."
# Use docker inspect health status
DB_HEALTH=""
for i in {1..60}; do
DB_HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "$(docker ps --filter name=_database_ --format '{{.ID}}' | head -n1)" 2>/dev/null || true)
DB_ID=$(dc ps -q database 2>/dev/null || true)
if [ -n "$DB_ID" ]; then
DB_HEALTH=$(docker inspect -f '{{.State.Health.Status}}' "$DB_ID" 2>/dev/null || true)
fi
if [ "$DB_HEALTH" = "healthy" ]; then
echo " OK"
break
@@ -79,7 +82,7 @@ for i in {1..60}; do
printf "."
sleep 2
if [ "$i" -eq 60 ]; then
echo "\nWarning: database health check not healthy yet, continuing anyway."
echo -e "\nWarning: database health check not healthy yet, continuing anyway."
fi
done
@@ -100,11 +103,23 @@ if grep -q '^APP_SECRET=$' "$ROOT_DIR/.env" 2>/dev/null; then
fi
# Prepare DB
pexec php bin/console doctrine:database:create --if-not-exists || true
pexec php bin/console doctrine:migrations:migrate -n || true
echo "Creating database if it doesn't exist..."
pexec php bin/console doctrine:database:create --if-not-exists
echo "Running migrations..."
pexec php bin/console doctrine:migrations:migrate -n
# Import JS deps (Importmap/Asset Mapper)
pexec php bin/console importmap:install || true
if [ -f "$ROOT_DIR/importmap.php" ]; then
pexec php bin/console importmap:install || true
fi
# Build assets if using Webpack Encore
if [ -f "$ROOT_DIR/package.json" ]; then
echo "Installing npm dependencies..."
pexec npm install
echo "Building assets..."
pexec npm run build
fi
APP_URL=http://localhost:8080
MAILPIT_URL=http://localhost:8025
@@ -117,10 +132,12 @@ Open the app: $APP_URL
Mailpit (dev): $MAILPIT_URL
Common commands:
(cd docker && $DOCKER_COMPOSE logs -f nginx)
(cd docker && $DOCKER_COMPOSE logs -f php)
(cd docker && $DOCKER_COMPOSE exec php bash)
(cd docker && $DOCKER_COMPOSE down)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f nginx)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f php)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE logs -f php-worker)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE exec php bash)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE exec php npm run watch)
(cd "$DOCKER_DIR" && $DOCKER_COMPOSE down)
You can re-run this script any time. Use --no-build to skip rebuilding images.
EOT