FROM debian:bullseye-slim # Installation des dépendances de base + PostgreSQL RUN apt-get update && apt-get install -y \ apache2 \ supervisor \ wget \ curl \ unzip \ gnupg \ lsb-release \ openjdk-17-jdk \ postgresql-13 \ postgresql-contrib \ && rm -rf /var/lib/apt/lists/* # Installation de Tomcat 10 RUN cd /opt && \ wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.47/bin/apache-tomcat-10.1.47.tar.gz && \ tar -xzf apache-tomcat-10.1.47.tar.gz && \ mv apache-tomcat-10.1.47 tomcat && \ rm apache-tomcat-10.1.47.tar.gz && \ chmod +x /opt/tomcat/bin/*.sh # Variables d'environnement ENV CATALINA_HOME=/opt/tomcat ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 ENV PATH=$PATH:$CATALINA_HOME/bin # Installation Apache Exporter RUN wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.10/apache_exporter-1.0.10.linux-amd64.tar.gz \ && tar xzf apache_exporter-1.0.10.linux-amd64.tar.gz \ && mv apache_exporter-1.0.10.linux-amd64/apache_exporter /usr/local/bin/ \ && rm -rf apache_exporter-* # Installation Node Exporter RUN wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz \ && tar xzf node_exporter-1.7.0.linux-amd64.tar.gz \ && mv node_exporter-1.7.0.linux-amd64/node_exporter /usr/local/bin/ \ && rm -rf node_exporter-* # Installation Promtail RUN wget https://github.com/grafana/loki/releases/download/v2.9.0/promtail-linux-amd64.zip \ && unzip promtail-linux-amd64.zip \ && mv promtail-linux-amd64 /usr/local/bin/promtail \ && chmod +x /usr/local/bin/promtail \ && rm promtail-linux-amd64.zip # Suppression et recréation des répertoires PostgreSQL RUN rm -rf /var/lib/postgresql/13/main && \ mkdir -p /var/run/postgresql \ /var/lib/postgresql/13/main \ /var/log/postgresql \ /var/log/apache2 \ /var/log/promtail \ /opt/tomcat/logs \ /var/log/supervisor \ /docker-entrypoint-initdb.d && \ chown -R postgres:postgres /var/run/postgresql /var/lib/postgresql /var/log/postgresql # Initialisation de PostgreSQL RUN su - postgres -c "/usr/lib/postgresql/13/bin/initdb -D /var/lib/postgresql/13/main" && \ echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/13/main/pg_hba.conf && \ echo "listen_addresses='*'" >> /var/lib/postgresql/13/main/postgresql.conf # Copie des scripts SQL COPY database/schema.sql /docker-entrypoint-initdb.d/01-schema.sql COPY database/data.sql /docker-entrypoint-initdb.d/02-data.sql # Script pour créer la base de données et exécuter les scripts SQL RUN echo '#!/bin/bash\n\ echo "Waiting for PostgreSQL to start..."\n\ for i in {1..30}; do\n\ if su - postgres -c "psql -c \"SELECT 1;\"" >/dev/null 2>&1; then\n\ echo "PostgreSQL is ready!"\n\ break\n\ fi\n\ echo "Waiting... ($i/30)"\n\ sleep 1\n\ done\n\ \n\ echo "Creating database and user..."\n\ su - postgres -c "psql -c \"SELECT 1 FROM pg_database WHERE datname = '\''archiweb_db'\''\" | grep -q 1 || psql -c \"CREATE DATABASE archiweb_db;\""\n\ su - postgres -c "psql -c \"SELECT 1 FROM pg_roles WHERE rolname = '\''archiweb_user'\''\" | grep -q 1 || psql -c \"CREATE USER archiweb_user WITH PASSWORD '\''archiweb_password'\'';\""\n\ su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE archiweb_db TO archiweb_user;\""\n\ su - postgres -c "psql -d archiweb_db -c \"GRANT ALL ON SCHEMA public TO archiweb_user;\""\n\ \n\ echo "Executing SQL scripts..."\n\ if [ -f /docker-entrypoint-initdb.d/01-schema.sql ]; then\n\ echo "Running schema.sql..."\n\ su - postgres -c "psql -d archiweb_db -f /docker-entrypoint-initdb.d/01-schema.sql"\n\ fi\n\ \n\ if [ -f /docker-entrypoint-initdb.d/02-data.sql ]; then\n\ echo "Running data.sql..."\n\ su - postgres -c "psql -d archiweb_db -f /docker-entrypoint-initdb.d/02-data.sql"\n\ fi\n\ \n\ echo "Database setup complete!"' > /usr/local/bin/init-database.sh && \ chmod +x /usr/local/bin/init-database.sh # Copie des configurations COPY configs/promtail/config.yaml /etc/promtail/config.yaml COPY configs/supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Configuration Apache RUN echo '\n\ SetHandler server-status\n\ Require all granted\n\ ' > /etc/apache2/conf-available/server-status.conf \ && a2enconf server-status \ && a2enmod status \ && a2enmod proxy \ && a2enmod proxy_http # Configuration du proxy Apache vers Tomcat RUN echo '\n\ ProxyPreserveHost On\n\ ProxyPass /api http://localhost:8080/api\n\ ProxyPassReverse /api http://localhost:8080/api\n\ ' > /etc/apache2/sites-available/000-default.conf # Copie du WAR COPY archiweb-api-1.0.0.war /opt/tomcat/webapps/api.war EXPOSE 80 8080 9100 9117 9080 5432 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]