commit 04b138497b7000279ef5eb54535cfb6707a4b2b2 Author: Namonay Date: Wed Jan 17 16:53:15 2024 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be8ae6d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*/.env \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..16959bf --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +DETACH ?= true + +all: +ifeq ($(DETACH), true) + docker-compose -f srcs/docker-compose.yml up -d +else + docker-compose -f srcs/docker-compose.yml up +endif + +clean: + docker-compose -f srcs/docker-compose.yml down + +fclean: + -docker stop $$(docker ps -qa) + -docker rm $$(docker ps -qa) + -docker rmi -f $$(docker images -qa) + -docker volume rm $$(docker volume ls -q) + -docker network rm $$(docker network ls -q) 2>/dev/null +re: fclean + docker-compose -f srcs/docker-compose.yml up -d diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml new file mode 100644 index 0000000..5c91e26 --- /dev/null +++ b/srcs/docker-compose.yml @@ -0,0 +1,66 @@ +version: '3' + +services: + mariadb: + container_name: mariadb + env_file: .env + networks: + - inception + build: + context: requirements/mariadb + dockerfile : Dockerfile + volumes: + - mariadb:/var/lib/mysql + restart: unless-stopped + expose: + - "3306" + + nginx: + container_name: nginx + env_file: .env + volumes: + - wordpress:/var/www/wordpress + networks: + - inception + depends_on: + - wordpress + build: + context: requirements/nginx + dockerfile: Dockerfile + ports: + - "443:443" + restart: on-failure + + wordpress: + container_name: wordpress + env_file: .env + volumes: + - wordpress:/var/www/wordpress + networks: + - inception + build: + context: requirements/wordpress + dockerfile: Dockerfile + depends_on: + - mariadb + restart: on-failure + expose: + - "9000" + +volumes: + wordpress: + driver: local + driver_opts: + type: 'none' + o: 'bind' + device: '/home/vvaas/data/wordpress' + mariadb: + driver: local + driver_opts: + type: 'none' + o: 'bind' + device: '/home/vvaas/data/mariadb' + +networks: + inception: + driver: bridge \ No newline at end of file diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile new file mode 100644 index 0000000..5358045 --- /dev/null +++ b/srcs/requirements/mariadb/Dockerfile @@ -0,0 +1,18 @@ +FROM debian:buster + +RUN apt update -y +RUN apt upgrade -y +RUN apt install mariadb-server -y +RUN apt install procps -y + +COPY conf/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf +#moves the config file from conf to the docker container + +COPY tools/mariadb.sh /mariadb.sh +#moves the script inside the docker container + +RUN chmod +x /mariadb.sh + +EXPOSE 3306 + +ENTRYPOINT ["/bin/bash", "mariadb.sh"] diff --git a/srcs/requirements/mariadb/conf/50-server.cnf b/srcs/requirements/mariadb/conf/50-server.cnf new file mode 100644 index 0000000..b30d617 --- /dev/null +++ b/srcs/requirements/mariadb/conf/50-server.cnf @@ -0,0 +1,6 @@ +[mysqld] +datadir = /var/lib/mysql +socket = /run/mysqld/mysqld.sock +bind_address = * +port = 3306 +user = mysql diff --git a/srcs/requirements/mariadb/tools/mariadb.sh b/srcs/requirements/mariadb/tools/mariadb.sh new file mode 100644 index 0000000..169f49e --- /dev/null +++ b/srcs/requirements/mariadb/tools/mariadb.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +service mysql start + +echo "CREATE USER IF NOT EXISTS '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_USER';" | mysql +echo "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';" | mysql +echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';" | mysql +echo "FLUSH PRIVILEGES;" | mysql +echo "CREATE DATABASE IF NOT EXISTS $MYSQL_DATABASE;" | mysql + +sleep 2 + +service mysql stop + +exec mysqld_safe \ No newline at end of file diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile new file mode 100644 index 0000000..5ba5463 --- /dev/null +++ b/srcs/requirements/nginx/Dockerfile @@ -0,0 +1,19 @@ +FROM debian:buster + +RUN apt update -y +RUN apt install nginx -y +RUN apt install openssl -y + +RUN mkdir -p /etc/nginx/ssl + +RUN openssl req -x509 -nodes -out /etc/nginx/ssl/inception.crt -keyout /etc/nginx/ssl/inception.key -subj "/C=FR/ST=CM/L=ANgouleme/O=42/OU=42/CN=vvaas/UID=vvaas" +#create a non-encrypted SSL certificate +COPY conf/nginx.conf /etc/nginx/conf.d +# move the nginx config file in conf into the docker container +RUN chmod +w /var/www/html +RUN chown -R www-data:www-data /var/www/html + +EXPOSE 443 + +ENTRYPOINT ["nginx", "-g", "daemon off;"] +#start nginx \ No newline at end of file diff --git a/srcs/requirements/nginx/conf/nginx.conf b/srcs/requirements/nginx/conf/nginx.conf new file mode 100644 index 0000000..125e3e2 --- /dev/null +++ b/srcs/requirements/nginx/conf/nginx.conf @@ -0,0 +1,20 @@ +server { + listen 0.0.0.0:443; + + ssl on; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_certificate /etc/nginx/ssl/inception.crt; + ssl_certificate_key /etc/nginx/ssl/inception.key; + root /var/www/wordpress; + server_name vvaas.42.fr; + index index.php; + + location / { + try_files $uri $uri/ =404; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass wordpress:9000; + } +} diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile new file mode 100644 index 0000000..0270b5a --- /dev/null +++ b/srcs/requirements/wordpress/Dockerfile @@ -0,0 +1,34 @@ +FROM debian:buster + +RUN apt update -y +RUN apt upgrade -y +RUN apt-get install wget -y +RUN apt-get install php7.3 -y +RUN apt-get install php-fpm -y +RUN apt-get install php-mysql -y +RUN apt-get install mariadb-client -y +RUN apt-get install less -y +RUN wget https://fr.wordpress.org/latest-fr_FR.tar.gz -P /var/www +#install all dependencies + +RUN cd /var/www && tar -xzf latest-fr_FR.tar.gz && rm latest-fr_FR.tar.gz + +COPY conf/www.conf /etc/php/7.3/fpm/pool.d +# copy the config file in conf into the docker container + +RUN wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar +RUN chmod +x wp-cli.phar +RUN mv wp-cli.phar /usr/local/bin/wp.phar +#download and install the CLI used in configscript.sh + +RUN chown -R root:root /var/www/wordpress + +COPY conf/configscript.sh configscript.sh +#move the script from conf to the docker container + +RUN chmod +x configscript.sh + +EXPOSE 9000 + +ENTRYPOINT ["bash", "configscript.sh"] +#start the script \ No newline at end of file diff --git a/srcs/requirements/wordpress/conf/configscript.sh b/srcs/requirements/wordpress/conf/configscript.sh new file mode 100644 index 0000000..5ab1bba --- /dev/null +++ b/srcs/requirements/wordpress/conf/configscript.sh @@ -0,0 +1,18 @@ +#!/bin/bash +sleep 10 +#Waits for mariadb to be fully operational. +if [ ! -e /var/www/wordpress/wp-config.php ]; then +wp.phar config create --allow-root --dbname=$MYSQL_DATABASE --dbuser=$MYSQL_USER --dbpass=$MYSQL_PASSWORD --dbhost=mariadb:3306 --path='/var/www/wordpress' +#Create the wp-config.php. +wp.phar core install --allow-root --url=$URL --title=$WP_TITLE --admin_user=$WP_ADMIN_USER --admin_password=$WP_ADMIN_PASSWORD --admin_email=$WP_ADMIN_EMAIL --path='/var/www/wordpress' +#install wordpress using the parameters and configs files. +wp.phar user create --allow-root --role=author $USER_USER $USER_EMAIL --user_pass=$USER_PASSWORD --path='/var/www/wordpress' +#create an user. + +sleep 2 +fi +if [ ! -d /run/php ]; then + mkdir /run/php + #create the php directory if it's not already created. +fi +/usr/sbin/php-fpm7.3 -F \ No newline at end of file diff --git a/srcs/requirements/wordpress/conf/www.conf b/srcs/requirements/wordpress/conf/www.conf new file mode 100644 index 0000000..6b3f760 --- /dev/null +++ b/srcs/requirements/wordpress/conf/www.conf @@ -0,0 +1,21 @@ +[www] + +user = www-data +group = www-data + +listen = wordpress:9000 + +listen.owner = www-data +listen.group = www-data + +pm = dynamic + +pm.max_children = 5 + +pm.start_servers = 2 + +pm.min_spare_servers = 1 + +pm.max_spare_servers = 3 + +clear_env = no \ No newline at end of file