PRA2024/projekt_2/start.sh
Adam Gulczyński cc75c784b2 working, v1
2024-01-15 23:08:37 +01:00

19 lines
531 B
Bash
Executable File

#!/bin/bash
CONTAINER_NAME="pra-db"
SQL_FILE="init_db.sql"
docker-compose up -d
# Copy the SQL file to the container
docker cp $SQL_FILE $CONTAINER_NAME:/init_db.sql
# Wait until the PostgreSQL server is ready
echo "Waiting for PostgreSQL to become available..."
until docker exec $CONTAINER_NAME pg_isready -U devuser -d pra_db > /dev/null 2>&1; do
sleep 1
done
echo "PostgreSQL is available now."
# Execute the SQL file inside the container
docker exec -it $CONTAINER_NAME sh -c "psql -U devuser -d pra_db -f /init_db.sql"