From 778e1a90565b1c75b25f8f11bd64ccf8cff10b3a Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 25 Jun 2025 23:10:28 +0200 Subject: [PATCH] feat(inception imporing stuff (come back on the subject) --- Makefile | 22 ++++++++++--------- srcs/requirements/mariadb/Dockerfile | 12 +++++++++- srcs/requirements/nginx/Dockerfile | 2 -- .../nginx/tools/generate_ssl_certificate.sh | 2 +- srcs/requirements/wordpress/Dockerfile | 21 ++++++++++++++++++ srcs/requirements/wordpress/tools/install.sh | 19 ++++++++++++++++ 6 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 srcs/requirements/wordpress/tools/install.sh diff --git a/Makefile b/Makefile index 41de72d..fb981c1 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2025/06/12 18:09:23 by rparodi #+# #+# # -# Updated: 2025/06/14 18:26:21 by rparodi ### ########.fr # +# Updated: 2025/06/17 00:07:38 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -92,14 +92,16 @@ fclean: clean re: header fclean all footer -setup_vm: - echo "127.0.0.1 rparodi.42.fr" | sudo tee -a /etc/hosts &> /dev/null - @printf "$(GREY)Adding the custom host $(GREEN)rparodi.42.fr$(END)\n"; \ - sudo $(PACK_MAN) docker docker-compose docker-buildx - @printf "$(GREY)Install the $(GREEN)docker docker-compose docker-buildx packages$(END)\n"; \ - sudo usermod -aG docker $(shell whoami) - @printf "$(GREY)User add to the $(GOLD)docker's group$(END)\n"; \ - @printf "$(GREY)Virtual Machine now $(GOLD)setuped$(END)\n"; \ +setup_vm: header + @echo "127.0.0.1 rparodi.42.fr" | sudo tee -a /etc/hosts &> /dev/null + @printf "$(GREY)Adding the custom host $(GREEN)rparodi.42.fr$(END)\n"; + @sudo $(PACK_MAN) docker docker-compose docker-buildx &> /dev/null + @printf "$(GREY)Install the $(GREEN)docker docker-compose docker-buildx packages$(END)\n"; + @sudo usermod -aG docker $(shell whoami) + @printf "$(GREY)User add to the $(GREEN)docker's group$(END)\n"; + @printf "$(GREY)Virtual Machine now $(GOLD)setuped$(END)\n"; + +setup: setup_vm # Header header: @@ -133,4 +135,4 @@ footer: @printf ' $(GREY)The build is $(GOLD)finished$(END)\n $(GREY)Have a good $(GOLD)evaluation !$(END)\n' # Phony -.PHONY: all nginx mariadb wordpress get_secret clean fclean re +.PHONY: all nginx mariadb wordpress get_secret clean fclean re setup setup_vm diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile index 9f6c7ca..c90c885 100644 --- a/srcs/requirements/mariadb/Dockerfile +++ b/srcs/requirements/mariadb/Dockerfile @@ -1,5 +1,15 @@ FROM alpine:3.21 -RUN apk update && apk add mariadb mariadb-client +RUN apk update && apk add mariadb mariadb-client bash + +RUN mkdir -p /run/mysqld && chown -R mysql:mysql /run/mysqld + +HEALTHCHECK --start-period=5m CMD mariadb -e 'SELECT @@datadir;' || exit 1 + +RUN mysql_install_db --user=$DB_USER --basedir=/usr --datadir=/var/lib/mysql + +USER mysql EXPOSE 3306 + +CMD ["mariadbd"] diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index fac9ac2..336b581 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -12,8 +12,6 @@ RUN chmod +x /usr/bin/generate_ssl_certificate RUN /usr/bin/generate_ssl_certificate -USER nginx - EXPOSE 443 CMD ["nginx", "-g", "daemon off;"] diff --git a/srcs/requirements/nginx/tools/generate_ssl_certificate.sh b/srcs/requirements/nginx/tools/generate_ssl_certificate.sh index 3b8207a..2a081b0 100644 --- a/srcs/requirements/nginx/tools/generate_ssl_certificate.sh +++ b/srcs/requirements/nginx/tools/generate_ssl_certificate.sh @@ -8,7 +8,7 @@ END = \033[0m if [ ! -f "$CERT_DIR/nginx.key" ]; then @printf '$GREYGenerating the ssl$GREEN Certificate$END\n'; - openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=FR/ST=Paris/L=42/O=Students/OU=Inception/CN=rparodi.42.fr" + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=FR/ST=Paris/L=42/O=Students/OU=Inception/CN=$DOMAIN" else @printf '$GREYGenerating the ssl certificate$RED already exist$END\n'; fi diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index e69de29..3de5cac 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -0,0 +1,21 @@ +FROM alpine:3.21 + +RUN apk update && apk add bash wget php82 php82-phar php82-mysqli php82-fpm mariadb-client + +# RUN wget https://wordpress.org/latest.tar.gz -O /tmp/wp.tar.gz + +RUN mkdir -p /var/www/html + +RUN wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /bin/wp-cli.phar; +RUN chmod +x /bin/wp-cli.phar; +RUN mv /bin/wp-cli.phar /bin/wp; + +RUN ln -s /usr/bin/php82 /usr/bin/php; +RUN ln -s /usr/sbin/php-fpm82 /usr/sbin/php-fpm; +RUN export PHP_OPTIONS="-d memory_limit=512M" + +COPY tools/install.sh /usr/bin/install-wp + +RUN chmod +x /usr/bin/install-wp + +CMD ["install-wp", "php-fpm"] diff --git a/srcs/requirements/wordpress/tools/install.sh b/srcs/requirements/wordpress/tools/install.sh new file mode 100644 index 0000000..410b8eb --- /dev/null +++ b/srcs/requirements/wordpress/tools/install.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +cd /var/www/html + +mariadb-admin --host=mariadb --port=3306 --user="$DB_USER" --password="$DB_PASS" --wait status + +if ! [ -f wp-load.php ]; then + wp core download --locale=fr_FR --allow-root --path=/var/www/html +fi + +if ! [ -f wp-config.php ]; then + wp config create --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASSWORD --dbhost=$DB_HOST --skip-check --path=/var/www/html --allow-root + wp core install --url=$DOMAIN --title=$WP_TITLE --admin_user=$WP_ADMIN --admin_password=$WP_PASS_ADMIN --admin_email=$WP_MAIL_ADMIN --skip-email --path=/var/www/html --allow-root +fi + +chown wordpress:wordpress -R /var/www/html +chmod -R +rw /var/www/html + +exec php-fpm --nodeamonize