FROM alpine:3.21.2

LABEL org.opencontainers.image.authors="alier@student.42mulhouse.fr"

RUN apk add mariadb mariadb-client

RUN mkdir -p /run/mysqld \
  && mkdir -p /var/lib/mysql \
  && chown -R mysql:mysql /run/mysqld \
  && chown -R mysql:mysql /var/lib/mysql

COPY ./tools/docker-entrypoint.sh /docker-entrypoint.sh
COPY ./conf/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf

VOLUME [ "/var/lib/mysql" ]

ENTRYPOINT [ "/docker-entrypoint.sh" ]

EXPOSE 3306

HEALTHCHECK --start-period=5s \
  CMD mariadb -e 'SELECT @@datadir;' || exit 1

USER mysql

CMD ["mariadbd"]