# debian -----------------------------------------------------

#	FROM debian:buster
#
#	# vim and bash for debug
#	RUN	apt update && apt install -y \
#		mariadb-client \
#		mariadb-server \
#		vim bash \
#		&& \
#		rm -rf /var/lib/apt/lists/*
#
#	# config file .cnf :
#	COPY ./conf/50-server.cnf.debian /etc/mysql/mariadb.conf.d/50-server.cnf

# alpine -----------------------------------------------------

	FROM alpine:3.15

	# vim and bash for debug
	RUN apk update && apk add \
		mariadb \
		mariadb-client \
		vim bash \
		&& \
		rm -rf /var/cache/apk*

	# config file .cnf :
	COPY ./conf/mariadb-server.cnf.alpine /etc/my.cnf.d/mariadb-server.cnf

# common -----------------------------------------------------

ARG DB_HOST
ARG DB_NAME
ARG DB_USER
ARG DB_PSWD

# init mysql database
RUN mysql_install_db --user=mysql --ldata=/var/lib/mysql && \
	mkdir -p /var/run/mysqld && \
	chown -R mysql:root /var/run/mysqld

# configure wp database
COPY ./conf/create_db.sql /usr/bin/create_db.sql
RUN sed -i "s/\${DB_HOST}/${DB_HOST}/g" /usr/bin/create_db.sql && \
	sed -i "s/\${DB_NAME}/${DB_NAME}/g" /usr/bin/create_db.sql && \
	sed -i "s/\${DB_USER}/${DB_USER}/g" /usr/bin/create_db.sql && \
	sed -i "s/\${DB_PSWD}/${DB_PSWD}/g" /usr/bin/create_db.sql

ENTRYPOINT [ "mysqld", "--user=mysql", "--init-file=/usr/bin/create_db.sql" ]

