diff --git a/mariadb/build/Dockerfile b/mariadb/build/Dockerfile new file mode 100644 index 0000000..5d957d4 --- /dev/null +++ b/mariadb/build/Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.9 + +RUN apk add --no-cache mariadb mariadb-client mariadb-server-utils && \ + rm -f /var/cache/apk/* + +## Required by mysql-backup +RUN apk add --no-cache bash gzip && \ + rm -f /var/cache/apk/* + +RUN mkdir -p /run/mysqld && \ + chown -R mysql:mysql /run/mysqld + +RUN sed -i "s|.*bind-address\s*=.*|bind-address=0.0.0.0|g" /etc/my.cnf.d/mariadb-server.cnf + +COPY src/ / + +EXPOSE 3306 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/mariadb/build/src/entrypoint.sh b/mariadb/build/src/entrypoint.sh new file mode 100755 index 0000000..ae31f70 --- /dev/null +++ b/mariadb/build/src/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh + + + +if ! [ -d /var/lib/mysql/mysql ]; then + chown -R mysql:mysql /var/lib/mysql + mysql_install_db --user=mysql --ldata=/var/lib/mysql > /dev/null +fi + + + +## Support of Ctrl-C: see https://github.com/docker-library/mysql/issues/47 +run() { + "$@" & + pid="$!" + trap "kill -SIGQUIT $pid" INT TERM + wait +} + +run mysqld --user=mysql --skip-name-resolve --skip-networking=0 "$@" \ No newline at end of file diff --git a/mariadb/hooks/init b/mariadb/hooks/init index 2e8a84c..2c64b8d 100755 --- a/mariadb/hooks/init +++ b/mariadb/hooks/init @@ -25,31 +25,7 @@ fi if ! [ -d "$HOST_DATASTORE/${SERVICE_NAME}$DB_DATADIR" ]; then MYSQL_ROOT_PASSWORD="$(gen_password)" - - debug docker run -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \ - --rm \ - -v "$DATA_DIR:$DB_DATADIR" \ - --entrypoint /bin/bash "$DOCKER_BASE_IMAGE" - docker run -e "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" \ - --rm \ - -v "$DATA_DIR:$DB_DATADIR" \ - --entrypoint /bin/bash "$DOCKER_BASE_IMAGE" -c ' - mysqld() { - echo "diverted mysqld call..." >&2; - echo "$*" | grep -E "(--help|--skip-networking)" >/dev/null 2>&1 || return; - echo " .. Allowing call." >&2; - /usr/sbin/mysqld "$@"; - } - export -f mysqld; - /docker-entrypoint.sh mysqld' || true - ## docker errorlevel is still 0 even if it failed. - ## AND we must ignore mysqld error ! - [ "$(find "$DATA_DIR" \ - -maxdepth 0 -type d -empty 2>/dev/null)" ] && { - err "Docker run probably failed to do it's job." - exit 1 - } - + mkdir -p "${HOST_DB_PASSFILE%/*}" ## XXXvlab: this won't help support multiple project running on the ## same host cat < "$HOST_DB_PASSFILE" @@ -57,5 +33,27 @@ if ! [ -d "$HOST_DATASTORE/${SERVICE_NAME}$DB_DATADIR" ]; then password=$MYSQL_ROOT_PASSWORD EOF chmod 600 "$HOST_DB_PASSFILE" + + ## deactivating final connection check + ddb () { true; } + export -f ddb + ensure_db_docker_running || exit 1 + + docker exec -i "$_DB_NAME" mysql <&1 >/dev/null) || { + err "Docker run probably failed to do it's job." + echo "$err" | prefix " " >&2 + exit 1 + } + info "New root password for mysql. " fi \ No newline at end of file diff --git a/mariadb/metadata.yml b/mariadb/metadata.yml index 3c742ee..24c018e 100644 --- a/mariadb/metadata.yml +++ b/mariadb/metadata.yml @@ -1,6 +1,4 @@ name: MariaDB -## From: mysql Ver 15.1 Distrib 10.0.21-MariaDB -docker-image: docker.0k.io/mariadb:1.0.0 maintainer: "Valentin Lab " provides: mysql-database: