Last active
December 7, 2017 13:07
-
-
Save gerbenjacobs/be87e9c39b95602fe5eaef9a549aec14 to your computer and use it in GitHub Desktop.
Starts MySQL and PHPMyAdmin as containers, linked and executes `php artisan migrate --seed` when they're ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# WARNING: This is ephemeral storage | |
export MSYS_NO_PATHCONV=1 # Windows: prevents path expansion in 'git bash' for volume mounting | |
NAME=project | |
NAME_DB=${NAME}-database | |
NAME_PMA=${NAME}-pma | |
function header() { | |
echo -e "\n\033[0;32m$1\033[0m" | |
} | |
function oops() { | |
echo -e "\n\033[0;31m$1\033[0m" | |
exit | |
} | |
header "== Killing and removing old images" | |
docker kill ${NAME_DB} ${NAME_PMA} 2>/dev/null | |
docker rm ${NAME_DB} ${NAME_PMA} 2>/dev/null | |
header "== Starting up container for MySQL" | |
docker run \ | |
--name ${NAME_DB} \ | |
-e MYSQL_ROOT_PASSWORD=my-secret-pw \ | |
-e MYSQL_DATABASE=${NAME_DB} \ | |
-d -p 3306:3306 \ | |
mysql:latest | |
if [ $? -ne 0 ]; then oops "-- Failed to start MySQL db"; fi | |
header "== Waiting N seconds before MySQL is up and running.." | |
HEALTH_CMD="docker exec ${NAME_DB} sh -c 'mysqladmin -h 127.0.0.1 -pmy-secret-pw -uroot ping --silent 2>/dev/null'" | |
n=0 | |
eval ${HEALTH_CMD} | |
while [ $? -ne 0 ]; do | |
sleep 1 | |
n=$((n+1)) | |
echo "Waited ${n} seconds.." | |
eval ${HEALTH_CMD} | |
done | |
header "== Applying migrations" | |
php artisan migrate --seed | |
header "== Starting up container for PHPMyAdmin" | |
docker run \ | |
--name ${NAME_PMA} \ | |
--link ${NAME_DB}:db \ | |
-d -p 8888:80 \ | |
phpmyadmin/phpmyadmin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment