mirror of
https://github.com/Ladebeze66/Inception.git
synced 2025-12-16 14:08:13 +01:00
final
This commit is contained in:
parent
69ca21b80e
commit
8f35747001
@ -1,10 +1,11 @@
|
|||||||
SHELL := /bin/bash
|
SHELL := /bin/bash
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
|
USER = $(shell whoami)
|
||||||
HOSTNAME=fgras-ca.42.fr
|
HOSTNAME=fgras-ca.42.fr
|
||||||
HOSTS_FILE=/etc/hosts
|
HOSTS_FILE=/etc/hosts
|
||||||
VOLUME_DIR_MYSQL=/home/fgras-ca/Inception/data/mysql
|
VOLUME_DIR_MYSQL = /home/$(USER)/data/mysql
|
||||||
VOLUME_DIR_HTML=/home/fgras-ca/Inception/data/html
|
VOLUME_DIR_HTML = /home/$(USER)/data/html
|
||||||
|
|
||||||
all: sudo-validate setup-hosts create-volumes start-docker
|
all: sudo-validate setup-hosts create-volumes start-docker
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ sudo-validate:
|
|||||||
|
|
||||||
down:
|
down:
|
||||||
@echo "Stopping and removing all Docker containers..."
|
@echo "Stopping and removing all Docker containers..."
|
||||||
@docker-compose -f /home/fgras-ca/Inception/data/scrs/docker-compose.yml down
|
@docker-compose -f /home/$(USER)/data/scrs/docker-compose.yml down
|
||||||
|
|
||||||
re: down all
|
re: down all
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ create-volumes:
|
|||||||
|
|
||||||
start-docker:
|
start-docker:
|
||||||
@echo "Starting Docker Compose in detached mode..."
|
@echo "Starting Docker Compose in detached mode..."
|
||||||
@docker-compose -f /home/fgras-ca/Inception/data/scrs/docker-compose.yml up -d --build
|
@docker-compose -f /home/$(USER)/data/scrs/docker-compose.yml up --build
|
||||||
|
|
||||||
.PHONY: all re down clean setup-hosts create-volumes start-docker sudo-validate
|
.PHONY: all re down clean setup-hosts create-volumes start-docker sudo-validate
|
||||||
|
|
||||||
|
|||||||
@ -52,11 +52,11 @@ volumes:
|
|||||||
driver: local
|
driver: local
|
||||||
driver_opts:
|
driver_opts:
|
||||||
type: none
|
type: none
|
||||||
device: /home/fgras-ca/Inception/data/mysql
|
device: /home/${USER}/data/mysql
|
||||||
o: bind
|
o: bind
|
||||||
wordpress_data:
|
wordpress_data:
|
||||||
driver: local
|
driver: local
|
||||||
driver_opts:
|
driver_opts:
|
||||||
type: none
|
type: none
|
||||||
device: /home/fgras-ca/Inception/data/html
|
device: /home/${USER}/data/html
|
||||||
o: bind
|
o: bind
|
||||||
|
|||||||
@ -1,26 +1,27 @@
|
|||||||
FROM debian:buster
|
FROM debian:buster
|
||||||
|
|
||||||
# Install necessary packages
|
# Installer les paquets nécessaires
|
||||||
RUN apt update -y && apt upgrade -y
|
RUN apt update -y && apt upgrade -y && \
|
||||||
RUN apt-get install -y mariadb-server mariadb-client gettext-base
|
apt-get install -y mariadb-server mariadb-client gettext-base procps && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
# Create the required directory for the Unix socket file
|
# Créer les répertoires requis
|
||||||
RUN mkdir -p /run/mysqld /var/www
|
RUN mkdir -p /run/mysqld /var/www && \
|
||||||
RUN chown mysql:mysql /run/mysqld
|
chown mysql:mysql /run/mysqld
|
||||||
|
|
||||||
# Copy configuration files
|
# Copier les fichiers de configuration
|
||||||
COPY ./conf/50-server.cnf /etc/mysql/mariadb.conf.d/
|
COPY ./conf/50-server.cnf /etc/mysql/mariadb.conf.d/
|
||||||
COPY ./tools/init_db.sql /etc/mysql/init_db.sql
|
COPY ./tools/init_db_template.sql /docker-entrypoint-initdb.d/init_db_template.sql
|
||||||
COPY ./tools/init_db.sql /docker-entrypoint-initdb.d/init_db.sql
|
|
||||||
COPY ./tools/entrypoint.sh /usr/local/bin/entrypoint.sh
|
COPY ./tools/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
|
|
||||||
# Ensure the script and SQL file have the correct permissions
|
# Assurer les permissions correctes pour le script et les fichiers SQL
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
RUN chmod +x /usr/local/bin/entrypoint.sh && \
|
||||||
RUN chmod 644 /etc/mysql/init_db.sql
|
chmod 644 /docker-entrypoint-initdb.d/init_db_template.sql && \
|
||||||
RUN chmod 644 /docker-entrypoint-initdb.d/init_db.sql
|
chmod -R 777 /var/lib/mysql
|
||||||
RUN chmod -R 777 /var/lib/mysql
|
|
||||||
|
|
||||||
|
# Exposer le port 3306
|
||||||
EXPOSE 3306
|
EXPOSE 3306
|
||||||
|
|
||||||
# Use the entrypoint script
|
# Utiliser le script d'entrée
|
||||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Créer un fichier SQL pour initialiser la base de données
|
# Démarrer le service MariaDB
|
||||||
cat << EOF > /docker-entrypoint-initdb.d/init_db.sql
|
|
||||||
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};
|
|
||||||
CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
|
|
||||||
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'%';
|
|
||||||
FLUSH PRIVILEGES;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
service mysql start
|
service mysql start
|
||||||
|
# Remplacer les variables dans le fichier SQL
|
||||||
# Vérifier si le socket existe
|
envsubst < /docker-entrypoint-initdb.d/init_db_template.sql > /docker-entrypoint-initdb.d/init_db.sql
|
||||||
if [ ! -S /var/run/mysqld/mysqld.sock ]; then
|
# Exécuter le script SQL d'initialisation
|
||||||
echo "Le fichier de socket MySQL n'existe pas. Création du socket..."
|
|
||||||
mkdir -p /var/run/mysqld
|
|
||||||
chown mysql:mysql /var/run/mysqld
|
|
||||||
service mysql restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Exécuter le script SQL
|
|
||||||
mysql -u root -p"${MYSQL_ROOT_PASSWORD}" < /docker-entrypoint-initdb.d/init_db.sql
|
mysql -u root -p"${MYSQL_ROOT_PASSWORD}" < /docker-entrypoint-initdb.d/init_db.sql
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Échec de l'exécution du script SQL"
|
echo "Échec de l'exécution du script SQL"
|
||||||
@ -27,6 +13,12 @@ fi
|
|||||||
|
|
||||||
echo "=== Script SQL exécuté avec succès ==="
|
echo "=== Script SQL exécuté avec succès ==="
|
||||||
|
|
||||||
# Garder le conteneur en cours d'exécution
|
# Fonction de surveillance pour garder le conteneur en cours d'exécution
|
||||||
chown -R mysql:mysql /var/lib/mysql
|
while true; do
|
||||||
tail -f /dev/null
|
sleep 60
|
||||||
|
if ! pgrep mysqld > /dev/null; then
|
||||||
|
echo "Le service MySQL s'est arrêté, redémarrage..."
|
||||||
|
service mysql restart
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +0,0 @@
|
|||||||
CREATE DATABASE IF NOT EXISTS '${MYSQL_DATABASE}';
|
|
||||||
CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
|
|
||||||
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'%';
|
|
||||||
FLUSH PRIVILEGES;
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE};
|
||||||
|
CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'%' IDENTIFIED BY '${MYSQL_PASSWORD}';
|
||||||
|
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'%';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
|
|
||||||
|
CREATE USER IF NOT EXISTS '${MYSQL_ADMIN_USER}'@'%' IDENTIFIED BY '${MYSQL_ADMIN_PASSWORD}';
|
||||||
|
GRANT ALL PRIVILEGES ON *.* TO '${MYSQL_ADMIN_USER}'@'%' WITH GRANT OPTION;
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
@ -9,7 +9,7 @@ RUN apt update -y && apt upgrade -y && \
|
|||||||
rm /tmp/wordpress.tar.gz && \
|
rm /tmp/wordpress.tar.gz && \
|
||||||
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp
|
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && mv wp-cli.phar /usr/local/bin/wp
|
||||||
|
|
||||||
RUN apt-get install sendmail -y
|
#RUN apt-get install sendmail -y
|
||||||
|
|
||||||
# Copier les fichiers de configuration PHP et le script d'auto-configuration
|
# Copier les fichiers de configuration PHP et le script d'auto-configuration
|
||||||
COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/
|
COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d/
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
define('DB_NAME', 'wordpress');
|
define('DB_NAME', getenv('MYSQL_DATABASE'));
|
||||||
define('DB_USER', 'fgras');
|
define('DB_USER', getenv('MYSQL_USER'));
|
||||||
define('DB_PASSWORD', '1234');
|
define('DB_PASSWORD', getenv('MYSQL_PASSWORD'));
|
||||||
define('DB_HOST', 'mariadb');
|
define('DB_HOST', 'mariadb');
|
||||||
|
define('DB_CHARSET', 'utf8');
|
||||||
define('URL', getenv('DOMAIN_NAME'));
|
define('URL', getenv('DOMAIN_NAME'));
|
||||||
define('TITLE', getenv('WP_TITLE'));
|
define('TITLE', getenv('WP_TITLE'));
|
||||||
define('ADMIN_USER', getenv('WP_ADMIN_USR'));
|
define('ADMIN_USER', getenv('WP_ADMIN_USR'));
|
||||||
|
|||||||
@ -1,12 +1,16 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Démarrer PHP-FPM
|
# Créer le répertoire pour le PID de PHP-FPM et définir les permissions
|
||||||
service php7.3-fpm start
|
mkdir -p /run/php
|
||||||
|
chown www-data:www-data /run/php
|
||||||
|
|
||||||
|
# Assurez-vous que PHP-FPM est arrêté avant de le démarrer en mode non daemonisé
|
||||||
|
service php7.3-fpm stop
|
||||||
|
|
||||||
# Attendre que MariaDB soit prêt
|
# Attendre que MariaDB soit prêt
|
||||||
until mysqladmin ping -h mariadb --silent; do
|
until mysqladmin ping -h mariadb --silent; do
|
||||||
echo "Waiting for MariaDB to be ready..."
|
echo "Waiting for MariaDB to be ready..."
|
||||||
sleep 2
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
# Télécharger WP-CLI si nécessaire
|
# Télécharger WP-CLI si nécessaire
|
||||||
@ -33,5 +37,6 @@ else
|
|||||||
echo "=== WordPress is already installed ==="
|
echo "=== WordPress is already installed ==="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Garder le conteneur en cours d'exécution
|
# Démarrer PHP-FPM en mode non daemonisé
|
||||||
tail -f /dev/null
|
php-fpm7.3 -F
|
||||||
|
|
||||||
|
|||||||
@ -1,25 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
USER="fgras-ca"
|
|
||||||
|
|
||||||
# Vérifiez si le script est exécuté en tant que root
|
|
||||||
if [ "$(whoami)" != "root" ]; then
|
|
||||||
echo "This script must be run as root"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ajouter l'utilisateur au fichier sudoers
|
|
||||||
if ! grep -q "$USER ALL=(ALL:ALL) ALL" /etc/sudoers; then
|
|
||||||
echo "Adding $USER to sudoers file..."
|
|
||||||
echo "$USER ALL=(ALL:ALL) ALL" >> /etc/sudoers
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Configurer le délai de validité du mot de passe sudo à une durée indéfinie
|
|
||||||
if ! grep -q "timestamp_timeout=-1" /etc/sudoers; then
|
|
||||||
echo "Setting sudo password timeout to indefinite..."
|
|
||||||
echo "Defaults timestamp_timeout=-1" >> /etc/sudoers
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Mise à jour des paquets
|
# Mise à jour des paquets
|
||||||
echo "Updating package lists..."
|
echo "Updating package lists..."
|
||||||
apt-get update
|
apt-get update
|
||||||
|
|||||||
23
data/sudo_setup.sh
Normal file
23
data/sudo_setup.sh
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
USER="fgras-ca"
|
||||||
|
|
||||||
|
# Vérifiez si le script est exécuté en tant que root
|
||||||
|
if [ "$(whoami)" != "root" ]; then
|
||||||
|
echo "This script must be run as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ajouter l'utilisateur au fichier sudoers
|
||||||
|
if ! grep -q "$USER ALL=(ALL:ALL) ALL" /etc/sudoers; then
|
||||||
|
echo "Adding $USER to sudoers file..."
|
||||||
|
echo "$USER ALL=(ALL:ALL) ALL" >> /etc/sudoers
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Configurer le délai de validité du mot de passe sudo à une durée indéfinie
|
||||||
|
if ! grep -q "timestamp_timeout=-1" /etc/sudoers; then
|
||||||
|
echo "Setting sudo password timeout to indefinite..."
|
||||||
|
echo "Defaults timestamp_timeout=-1" >> /etc/sudoers
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Sudo setup completed."
|
||||||
Loading…
x
Reference in New Issue
Block a user