Mysql recipe.
Showing
3 changed files
with
67 additions
and
0 deletions
mysql/Dockerfile
0 → 100644
mysql/files/configure
0 → 100755
1 | #!/bin/sh | ||
2 | |||
3 | set -e | ||
4 | apt-get update | ||
5 | apt-get install -y ssmtp mysql-server | ||
6 | |||
7 | mkdir /var/lib/container | ||
8 | tar -cC /var/lib/mysql/ . | gzip -9v > /var/lib/container/var_lib_mysql.tar.gz | ||
9 | rm -rf /var/lib/mysql | ||
10 | mkdir /var/lib/mysql | ||
11 | |||
12 | cp -a /tmp/files/entrypoint /sbin | ||
13 | |||
14 | rm -rf /tmp/files |
mysql/files/entrypoint
0 → 100755
1 | #!/bin/bash | ||
2 | |||
3 | set -ex | ||
4 | |||
5 | _mysql() { | ||
6 | mysqld_safe "$@" | ||
7 | } | ||
8 | |||
9 | if [[ $GID ]]; then | ||
10 | old_gid=$(getent group mysql | cut -f 3 -d :) | ||
11 | groupmod -g $GID mysql | ||
12 | else | ||
13 | found_errors+=("gid not set") | ||
14 | fi | ||
15 | |||
16 | if [[ $UID ]]; then | ||
17 | usermod -u $UID mysql | ||
18 | else | ||
19 | found_errors+=("uid not set") | ||
20 | fi | ||
21 | |||
22 | if [[ $(find /var/lib/mysql -maxdepth 1 -mindepth 1|wc -l) = 0 ]]; then | ||
23 | mkdir -p /var/lib/mysql | ||
24 | zcat /var/lib/container/var_lib_mysql.tar.gz | tar -C /var/lib/mysql -xf - | ||
25 | fi | ||
26 | |||
27 | if [[ ${#found_errors[*]} -gt 0 ]]; then | ||
28 | for error in "${found_errors[@]}"; do | ||
29 | echo "$error" | ||
30 | done | ||
31 | exit 1 | ||
32 | fi | ||
33 | |||
34 | declare -i i=0 | ||
35 | mysqld_safe --skip-networking & | ||
36 | while eval [[ \$DB_INFO_$i ]]; do | ||
37 | IFS=: eval declare -a DB_INFO=\(\$DB_INFO_$i\) | ||
38 | echo "database=${DB_INFO[0]} user=${DB_INFO[1]} password=${DB_INFO[2]}" 1>&2 | ||
39 | mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "CREATE DATABASE IF NOT EXISTS \`${DB_INFO[0]}\` DEFAULT CHARACTER SET \`utf8mb4\` COLLATE \`utf8mb4_ci\`;" | ||
40 | mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "GRANT ALL PRIVILEGES ON \`${DB_INFO[0]}\`.* TO '${DB_INFO[1]}' IDENTIFIED BY '${DB_INFO[2]}';" | ||
41 | i=$(($i + 1)) | ||
42 | done | ||
43 | mysql --defaults-extra-file=/etc/mysql/debian.cnf -e "shutdown;" | ||
44 | wait | ||
45 | |||
46 | exec "$@" |
-
Please register or sign in to post a comment