# ****************************************************************************************************
# *      ______                                                  _                       _           *
# *     |  ____|                                           /\   (_)                     | |          *
# *     | |__  _   _ _ __ ___  _ __   ___  __ _ _ __      /  \   _ _ __ _ __   ___  _ __| |_ ___     *
# *     |  __|| | | | '__/ _ \| '_ \ / _ \/ _` | '_ \    / /\ \ | | '__| '_ \ / _ \| '__| __/ __|    *
# *     | |___| |_| | | | (_) | |_) |  __/ (_| | | | |  / ____ \| | |  | |_) | (_) | |  | |_\__ \    *
# *     |______\__,_|_|  \___/| .__/ \___|\__,_|_| |_| /_/    \_\_|_|  | .__/ \___/|_|   \__|___/    *
# *                           | |                                      | |                           *
# *                           |_|                                      |_|                           *
# *                                                                                                  *
# ****************************************************************************************************

# This file is part of the European Airports Project, a free, collaborative platform of airport data 
# extending beyond the official AIPs.

# Copyright (C) 2023

# Florian Meissner <florianmeissner@gmx.de>

# This program is free software: you can redistribute it and/or modify it under the 
# terms of the GNU General Public License as published by the Free Software Foundation, either 
# version 3 of the License, or (at your option) any later version. This program is distributed in the 
# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
# details. You should have received a copy of the GNU General Public License along with this program. 
# (license.md in the root folder of this project) If not, see <http://www.gnu.org/licenses/>.



ARG MARIADB_VERSION
FROM mariadb:${MARIADB_VERSION}

# Set timezone
RUN echo "Etc/UTC" > /etc/timezone && \
    dpkg-reconfigure -f noninteractive tzdata

# Copy config files
COPY etc/ /etc/

# Copy update script
COPY tools/osupdate /sbin/osupdate
COPY tools/dbInit.sh /dbInit.sh
COPY tools/dbDump.sh /dbDump.sh

# Copy CheckMk files
#COPY checkmk/check-mk-agent_2.1.0p18-1_all.deb /tmp/checkmk_agent.deb
#COPY checkmk/plugins /usr/lib/check_mk_agent/plugins
#COPY checkmk/config /etc/check_mk
#COPY checkmk/mk-job /usr/local/bin

# Install dependencies
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y cron logrotate && \
#    apt-get install -y /tmp/checkmk_agent.deb && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /etc/logrotate.d/mysql-server 
#    rm /tmp/checkmk_agent.deb
    
# Configure cron
COPY tools/crontab /tmp/crontab
RUN service cron start && \
    crontab /tmp/crontab && \
    rm /tmp/crontab

# Define healthcheck
HEALTHCHECK --interval=60s --timeout=30s --start-period=5s --retries=3 \
    CMD [ "/usr/local/bin/healthcheck.sh", "--connect" ]

# Set entrypoint script
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
