mariadb/Dockerfile
Arnaud G. GIBERT 5cdb40cff4 - Move & Rename repo from Rx3/MariaDB-MGA9 to Rx3-Docker/MariaDB,
- New version naming standard,
- Now use docker_tools for .env building,
- Now use docker_service_add macro,
- Use now rx3-docker/server:1.2.0-mga9 image,
- Add /var/log/init, /var/log/supervisor & var/log/mysql volumes.
2024-11-17 17:01:05 +01:00

123 lines
8.6 KiB
Docker

# Rx3-Docker/MariaDB Docker Image
#-------------------------------------------------------------------------------
ARG IMG_FROM_URL="rx3-docker/server:latest"
FROM ${IMG_FROM_URL}
ARG IMG_NAME
ARG IMG_NAME_FULL
ARG IMG_VERSION
ARG IMG_MAINTAINER
LABEL org.rx3.${IMG_NAME}.name=${IMG_NAME_FULL}
LABEL org.rx3.${IMG_NAME}.version=${IMG_VERSION}
LABEL org.rx3.${IMG_NAME}.maintainer=${IMG_MAINTAINER}
LABEL maintainer=${IMG_MAINTAINER}
ARG MARIADDB_LIB
ARG MARIADDB_LOG
ARG MARIADDB_PORT
ARG POSTSQL_LOG
ARG MARIADB_LOG_FILE="${MARIADDB_LOG}/mariadb.err"
ARG POSTSQL_LOG_FILE="${POSTSQL_LOG}/postsql.log"
#---------------------------------------------------------------------------------------------------
ARG MYSQLD='#!/bin/bash \n\
\n\
usermod -u ${MARIADB_UID} mysql \n\
groupmod -g ${MARIADB_GID} mysql \n\
\n\
chown -R mysql:mysql '${MARIADDB_LIB}' '${MARIADDB_LOG}' /var/run/mysqld \n\
\n\
sed -i -e "s/^skip-networking/#skip-networking/" /etc/my.cnf.d/server.cnf \n\
sed -i -e "s%hostname$%hostname\\n\\nlog_error='${MARIADB_LOG_FILE}'%" /etc/my.cnf.d/server.cnf \n\
sed -i -e "s/^plugin-load-add=/#plugin-load-add=/" /etc/my.cnf.d/cracklib_password_check.cnf \n\
\n\
rm -Rf /var/log/mysqld* \n\
\n\
echo "CREATE USER `root`@`${MARIADB_ROOT_HOST}` IDENTIFIED BY `${MARIADB_ROOT_PASSWORD}`; \n\
GRANT ALL ON *.* TO `root`@`${MARIADB_ROOT_HOST}` WITH GRANT OPTION; \n\
GRANT PROXY ON ``@`%` TO `root`@`${MARIADB_ROOT_HOST}` WITH GRANT OPTION;" >>/tmp/post.sql \n\
\n\
if [[ -n "${MARIADB_DATABASE}" ]] \n\
then \n\
echo "CREATE DATABASE IF NOT EXISTS ${MARIADB_DATABASE};" >>/tmp/post.sql \n\
fi \n\
\n\
if [[ -n "${MARIADB_USER}" ]] && [[ -n "${MARIADB_PASSWORD}" ]] \n\
then \n\
echo "CREATE USER `${MARIADB_USER}`@`%` IDENTIFIED BY `${MARIADB_PASSWORD}`;">>/tmp/post.sql \n\
\n\
if [[ -n "${MARIADB_DATABASE}" ]] \n\
then \n\
echo "GRANT ALL ON ${MARIADB_DATABASE}.* TO `${MARIADB_USER}`@`%`;" >>/tmp/post.sql \n\
fi \n\
fi \n\
\n\
\n\
/usr/sbin/mysqld-prepare-db-dir'
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
ARG MYSQLD_INI='[program:mysqld] \n\
command=/usr/sbin/mysqld'
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
ARG POSTSQL='#!/bin/bash \n\
\n\
function log() { echo "$(date --rfc-3339=ns) PostSQL: $*" | tee -a '${POSTSQL_LOG_FILE}'; } \n\
\n\
log "Starting" \n\
\n\
for i in {30..0} \n\
do \n\
if mariadb <<< "SELECT 1" &> /dev/null \n\
then \n\
break \n\
fi \n\
\n\
sleep 1 \n\
done \n\
\n\
if [ "$i" = 0 ] \n\
then \n\
log "Unable to connect server" \n\
else \n\
while read line \n\
do \n\
log "Executing: [${line}]" \n\
echo ${line} | mariadb mysql \n\
done < /tmp/post.sql \n\
fi \n\
\n\
log "Completed"'
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
ARG POSTSQL_INI='[program:postsql] \n\
command=/usr/local/sbin/postsql'
#---------------------------------------------------------------------------------------------------
RUN urpmi --force mariadb \
&& echo -e "${MYSQLD}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/init.d/mysqld \
&& chmod a+x /etc/init.d/mysqld \
&& ln -s /etc/init.d/mysqld /etc/rcD.d/S30mysqld \
&& echo -e "${MYSQLD_INI}" | sed -e "s/\`/'/g" -e 's/ *$//' > /etc/supervisord.d/mysqld.ini \
&& echo -e "${POSTSQL}" | sed -e "s/\`/'/g" -e 's/ *$//' > /usr/local/sbin/postsql \
&& chmod a+x /usr/local/sbin/postsql \
&& echo -e "${POSTSQL_INI}" | sed -e 's/ *$//' > /etc/supervisord.d/postsql.ini
VOLUME ${MARIADDB_LIB}
VOLUME ${MARIADDB_LOG}
EXPOSE ${MARIADDB_PORT}