138 lines
5.4 KiB
Docker
138 lines
5.4 KiB
Docker
FROM debian:bullseye-slim
|
|
|
|
# Installation des dépendances de base
|
|
RUN apt-get update && apt-get install -y \
|
|
apache2 \
|
|
supervisor \
|
|
wget \
|
|
curl \
|
|
unzip \
|
|
gnupg \
|
|
lsb-release \
|
|
openjdk-17-jdk \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Installation de PostgreSQL 18 depuis le dépôt officiel
|
|
RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
|
|
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
|
|
apt-get update && \
|
|
apt-get install -y postgresql-18 postgresql-client-18 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 18
|
|
RUN rm -rf /var/lib/postgresql/18/main && \
|
|
mkdir -p /var/run/postgresql \
|
|
/var/lib/postgresql/18/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 18
|
|
RUN su - postgres -c "/usr/lib/postgresql/18/bin/initdb -D /var/lib/postgresql/18/main" && \
|
|
echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/18/main/pg_hba.conf && \
|
|
echo "listen_addresses='*'" >> /var/lib/postgresql/18/main/postgresql.conf
|
|
|
|
# Modification du pg_hba.conf pour utiliser md5 au lieu de peer (comme dans le script bash)
|
|
RUN sed -i "s/^local\s\+all\s\+all\s\+peer/local all all md5/" /var/lib/postgresql/18/main/pg_hba.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
|
|
# Mot de passe changé en archiweb_pass
|
|
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 ENCRYPTED PASSWORD '\''archiweb_pass'\'';\""\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 '<Location "/server-status">\n\
|
|
SetHandler server-status\n\
|
|
Require all granted\n\
|
|
</Location>' > /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 '<VirtualHost *:80>\n\
|
|
ProxyPreserveHost On\n\
|
|
ProxyPass /api http://localhost:8080/api\n\
|
|
ProxyPassReverse /api http://localhost:8080/api\n\
|
|
</VirtualHost>' > /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"]
|