Repository navigation
Expand file tree
/
Copy pathmysql.sh
More file actions
60 lines (52 loc) · 1.75 KB
/
Copy pathmysql.sh
File metadata and controls
60 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
### This file is not meant to be run directly, but to be sourced from
### the dev script. It defines all the functions required to run an
### MySQL docker container.
######################
# Configuration #
######################
if [ "$MODE" = "test" ]; then
MYSQL_PORT=33306
else
MYSQL_PORT=23306
fi
MYSQL_USER=root
MYSQL_PASSWORD=hasuraMySQL1
MYSQL_VOLUME_NAME='hasura-dev-mysql'
MYSQL_CONTAINER_NAME="hasura-dev-mysql-$MYSQL_PORT"
# space deliberately omitted between -u and -p params https://hub.docker.com/_/mysql
MYSQL_DOCKER="docker exec -it $MYSQL_CONTAINER_NAME mysql -u$MYSQL_USER -p$MYSQL_PASSWORD"
MYSQL_CONTAINER_IMAGE=mysql:8.0
MYSQL_PLATFORM=linux/amd64 # for M1 arch we use the rosetta emulation
######################
# Functions #
######################
function mysql_launch_container {
echo "Launching MySQL container: $MYSQL_CONTAINER_NAME"
docker volume create "$MYSQL_VOLUME_NAME"
docker run \
--name "$MYSQL_CONTAINER_NAME" \
--platform="$MYSQL_PLATFORM" \
--publish="127.0.0.1:${MYSQL_PORT}:3306" \
--volume="${MYSQL_VOLUME_NAME}:/var/lib/mysql" \
--env=MYSQL_ROOT_PASSWORD="$MYSQL_PASSWORD" \
--env=MYSQL_DATABASE='hasura' \
--detach \
"$MYSQL_CONTAINER_IMAGE" \
-h "localhost"
}
function mysql_wait {
echo -n "Waiting for mysql to come up"
until ( $MYSQL_DOCKER -e 'SELECT 1' ) &>/dev/null; do
echo -n '.' && sleep 0.2
done
echo " Ok"
}
function mysql_cleanup {
echo "Removing $MYSQL_CONTAINER_NAME and its volumes in 5 seconds!"
echo " PRESS CTRL-C TO ABORT removal of all containers, or ENTER to clean up right away"
read -rt5 || true
docker stop "$MYSQL_CONTAINER_NAME"
docker rm -v "$MYSQL_CONTAINER_NAME"
docker volume rm "$MYSQL_VOLUME_NAME"
}