Last active
July 5, 2021 14:29
-
-
Save hoangbits/649887d2b5d5dcbc253856fea5a5b052 to your computer and use it in GitHub Desktop.
wait for mysql and create schemas
This file contains hidden or 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
#!/bin/bash | |
# Initialize MySQL database. | |
# ADD this file into the container via Dockerfile. | |
# Assuming you specify a VOLUME ["/var/lib/mysql"] or `-v /var/lib/mysql` on the `docker run` command… | |
# Once built, do e.g. `docker run your_image /path/to/docker-mysql-initialize.sh` | |
# Again, make sure MySQL is persisting data outside the container for this to have any effect. | |
set -e | |
set -x | |
echo "before wait for it" | |
#./wait-for-it.sh 127.0.0.1:43306 | |
echo "Waiting for mysql" | |
#until mysql -h"$MYSQL_HOST" -P"$MYSQL_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" &> /dev/null | |
#until mysql -h localhost -P 43306 -u root -proot &> /dev/null | |
MYSQL_HOST=db | |
MYSQL_PORT=3306 | |
MYSQL_ENV_MYSQL_ROOT_PASSWORD=root | |
until mysql -h"$MYSQL_HOST" -P"$MYSQL_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" &> /dev/null | |
do | |
printf "hohoho." | |
sleep 1 | |
done | |
echo -e "\nmysql ready" | |
echo "start create schemas" | |
mysql -h db -P 3306 -u root -proot -e 'CREATE SCHEMA IF NOT EXISTS vsdb collate utf8mb4_unicode_ci; CREATE SCHEMA IF NOT EXISTS flipt; ' | |
echo "finish start create schemas" |
This file contains hidden or 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
setup_flipt_db: # run this service as a hook to create `flipt schema` | |
image: mysql:5.7.30 | |
depends_on: | |
- db | |
entrypoint: bash -c " | |
mysql -h 127.0.0.1 -P 43306 -u root -proot -e 'CREATE DATABASE flipt;'" | |
# command: ["./init_db.sh"] | |
restart: "no" | |
volumes: | |
- ./init_db.sh:/init_db.sh | |
env_file: ../.env |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wait until:
https://docs.docker.com/compose/startup-order/
https://github.com/DreamItGetIT/wait-for-mysql/blob/master/wait.sh