ARG VERSION

FROM mysql:${VERSION} AS base

ENV DB_USER=username
ENV DB_PASSWORD=pass
ENV MYSQL_ROOT_PASSWORD=root

COPY --from=artifacts schema.sql /docker-entrypoint-initdb.d/001_schema.sql
COPY --from=artifacts my.cnf /etc/mysql/conf.d/my.cnf
COPY --chown=mysql:mysql initdb /docker-entrypoint-initdb.d/
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d

COPY healthcheck.sh /usr/local/bin/

HEALTHCHECK --interval=1s --timeout=5s \
    CMD /usr/local/bin/healthcheck.sh

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["mysqld"]
