From 3dd1f9329f38d61a673c4e879d228c1b8dee5836 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Thu, 22 Sep 2022 23:12:18 +0200 Subject: [PATCH] work well? no makefile --- srcs/.env | 15 ++ srcs/docker-compose.yml | 62 ++++---- srcs/requirements/mariadb/Dockerfile | 12 +- srcs/requirements/mariadb/conf/server.conf | 133 ++++++++++++++++++ .../mariadb/tools/mySqlScript.sql | 4 + srcs/requirements/mariadb/tools/start.sh | 1 + srcs/requirements/nginx/Dockerfile | 28 ++-- srcs/requirements/nginx/conf/nginx.conf | 2 +- srcs/requirements/nginx/conf/nginx2.conf | 26 ++++ srcs/requirements/wordpress/Dockerfile | 23 +-- srcs/requirements/wordpress/conf/www.conf | 9 ++ srcs/requirements/wordpress/tools/start.sh | 31 ++++ .../wordpress/tools/wp-config.php | 98 +++++++++++++ 13 files changed, 374 insertions(+), 70 deletions(-) create mode 100644 srcs/requirements/mariadb/conf/server.conf create mode 100644 srcs/requirements/mariadb/tools/mySqlScript.sql create mode 100644 srcs/requirements/mariadb/tools/start.sh create mode 100644 srcs/requirements/nginx/conf/nginx2.conf create mode 100644 srcs/requirements/wordpress/conf/www.conf create mode 100644 srcs/requirements/wordpress/tools/start.sh create mode 100644 srcs/requirements/wordpress/tools/wp-config.php diff --git a/srcs/.env b/srcs/.env index e69de29..c0061a4 100644 --- a/srcs/.env +++ b/srcs/.env @@ -0,0 +1,15 @@ +WP_URL=apommier.42.fr +WP_TITLE=wordpress +WP_DB_HOST=mariadb + +WP_ADMIN_LOGIN=admin +WP_ADMIN_PASSWORD=admin +WP_ADMIN_EMAIL=admin@42.fr + +WP_USER_LOGIN=apommier +WP_USER_PASSWORD=apommier +WP_USER_EMAIL=apommier@student.42.fr + +MARIADB_DATABASE=wordpress +MARIADB_USER=apommier +MARIADB_PASSWORD=1234 diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 59f08b9..24cacd4 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -3,62 +3,60 @@ version: '3.3' services: nginx: - build: ./requirements/nginx - #image: nginx:stable-alpine - #container_name: nginx + build: requirements/nginx/ + container_name: nginx + environment: + - DOMAIN_NAME=apommier.42.fr + - SSL_CERTIFICATE=/etc/ssl/certs/nginx-selfsigned.crt + - SSL_CERTIFICATE_KEY=/etc/ssl/private/nginx-selfsigned.key depends_on: - - php - - mysql + - wordpress ports: - - 80:80 - 443:443 + - 80:80 volumes: - #- wpfiles:/var/www/html - ./wordpress:/var/www/html - - ./wordpress:/var/www/html3 - - ./wordpress:/var/www/html2 - #- ./requirements/nginx/conf/nginx.conf:/etc/nginx/conf.d/default.conf + restart: unless-stopped networks: - wpnetwork - restart: always - php: - #build: ./requirements/wordpress - image: php:7.4-fpm-alpine + wordpress: + build: ./requirements/wordpress volumes: # - wpfiles:/var/www/html - ./wordpress:/var/www/html depends_on: - - mysql + - mariadb networks: - wpnetwork - #restart: always + restart: unless-stopped - mysql: - #build: ./requirements/mariadb - image: mysql:latest + mariadb: + build: ./requirements/mariadb + container_name: mariadb + #image: mariadb:latest #container_name: mariadb - environment: - #MARIADB_DATABASE: wp - #MARIADB_USER: wp - #MARIADB_PASSWORD: secret - #MARIADB_ROOT_PASSWORD: secret - MYSQL_DATABASE: wp - MYSQL_USER: wp - MYSQL_PASSWORD: secret - MYSQL_ROOT_PASSWORD: secret + #environment: + # MARIADB_DATABASE: wp + # MARIADB_USER: wp + # MARIADB_PASSWORD: secret + # MARIADB_ROOT_PASSWORD: secret + #mariadb_DATABASE: wp + #mariadb_USER: wp + #mariadb_PASSWORD: secret + #mariadb_ROOT_PASSWORD: secret volumes: - #- ./requirements/mariadb:/var/lib/mysql + #- ./requirements/mariadb:/var/lib/mariadb #- wpfiles:/var/www/html - ./wordpress:/var/www/html networks: - wpnetwork - #restart: always + restart: unless-stopped networks: wpnetwork: driver: bridge -#volumes: - # wpfiles: \ No newline at end of file +volumes: + wpfiles: \ No newline at end of file diff --git a/srcs/requirements/mariadb/Dockerfile b/srcs/requirements/mariadb/Dockerfile index 607203e..0378ef4 100644 --- a/srcs/requirements/mariadb/Dockerfile +++ b/srcs/requirements/mariadb/Dockerfile @@ -11,7 +11,13 @@ # **************************************************************************** # FROM debian:buster +RUN apt-get update -y +RUN apt-get install -y mariadb-client mariadb-common mariadb-server +RUN sed -i 's/bind-address/bind-address = 0.0.0.0 #/i' /etc/mysql/mariadb.conf.d/50-server.cnf +RUN mkdir /mysql_scripts +COPY ./tools/ /mysql_scripts/ +#COPY ./conf/server.conf /etc/mysql/mariadb.conf.d/ -RUN apt-get update -RUN apt-get -y install mariadb-server -RUN apt-get -y install mariadb-client \ No newline at end of file +RUN service mysql start && mysql < /mysql_scripts/mySqlScript.sql + +CMD ["mysqld"] \ No newline at end of file diff --git a/srcs/requirements/mariadb/conf/server.conf b/srcs/requirements/mariadb/conf/server.conf new file mode 100644 index 0000000..6b256c8 --- /dev/null +++ b/srcs/requirements/mariadb/conf/server.conf @@ -0,0 +1,133 @@ +# +#These groups are read by MariaDB server. +#Use it for options that only the server (but not clients) should see +# +#See the examples of server my.cnf files in /usr/share/mysql + +#this is read by the standalone daemon and embedded servers +[server] + +#this is only for the mysqld standalone daemon +[mysqld] + +# +# * Basic Settings +# +user = mysql +pid-file = /run/mysqld/mysqld.pid +socket = /run/mysqld/mysqld.sock +port = 3306 +basedir = /usr +datadir = /var/lib/mysql +tmpdir = /tmp +lc-messages-dir = /usr/share/mysql +#skip-external-locking + +#Instead of skip-networking the default is now to listen only on +#localhost which is more compatible and is not less secure. +#bind-address = 127.0.0.1 + +# +# * Fine Tuning +# +#key_buffer_size = 16M +#max_allowed_packet = 16M +#thread_stack = 192K +#thread_cache_size = 8 +# This replaces the startup script and checks MyISAM tables if needed +# the first time they are touched +#myisam_recover_options = BACKUP +#max_connections = 100 +#table_cache = 64 +#thread_concurrency = 10 + +# +# * Query Cache Configuration +# +#query_cache_limit = 1M +query_cache_size = 16M + +# +# * Logging and Replication +# +# Both location gets rotated by the cronjob. +# Be aware that this log type is a performance killer. +# As of 5.1 you can enable the log at runtime! +#general_log_file = /var/log/mysql/mysql.log +#general_log = 1 +# +# Error log - should be very few entries. +# +log_error = /var/log/mysql/error.log +# +# Enable the slow query log to see queries with especially long duration +#slow_query_log_file = /var/log/mysql/mariadb-slow.log +#long_query_time = 10 +#log_slow_rate_limit = 1000 +#log_slow_verbosity = query_plan +#log-queries-not-using-indexes +# +# The following can be used as easy to replay backup logs or for replication. +# note: if you are setting up a replication slave, see README.Debian about +# other settings you may need to change. +#server-id = 1 +#log_bin = /var/log/mysql/mysql-bin.log +expire_logs_days = 10 +#max_binlog_size = 100M +#binlog_do_db = include_database_name +#binlog_ignore_db = exclude_database_name + +# +# * Security Features +# +# Read the manual, too, if you want chroot! +#chroot = /var/lib/mysql/ +# +# For generating SSL certificates you can use for example the GUI tool "tinyca". +# +#ssl-ca = /etc/mysql/cacert.pem +#ssl-cert = /etc/mysql/server-cert.pem +#ssl-key = /etc/mysql/server-key.pem +# +# Accept only connections using the latest and most secure TLS protocol version. +# ..when MariaDB is compiled with OpenSSL: +#ssl-cipher = TLSv1.2 +# ..when MariaDB is compiled with YaSSL (default in Debian): +#ssl = on + +# +# * Character sets +# +# MySQL/MariaDB default is Latin1, but in Debian we rather default to the full +# utf8 4-byte character set. See also client.cnf +# +character-set-server = utf8mb4 +collation-server = utf8mb4_general_ci + +# +# * InnoDB +# +# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. +# Read the manual for more InnoDB related options. There are many! + +# +# * Unix socket authentication plugin is built-in since 10.0.22-6 +# +# Needed so the root database user can authenticate without a password but +# only when running as the unix root user. +# +# Also available for other users if required. +# See https://mariadb.com/kb/en/unix_socket-authentication-plugin/ + +# this is only for embedded server +[embedded] + +# This group is only read by MariaDB servers, not by MySQL. +# If you use the same .cnf file for MySQL and MariaDB, +# you can put MariaDB-only options here +[mariadb] + +# This group is only read by MariaDB-10.3 servers. +# If you use the same .cnf file for MariaDB of different versions, +# use this group for options that older servers don't understand +[mariadb-10.3] \ No newline at end of file diff --git a/srcs/requirements/mariadb/tools/mySqlScript.sql b/srcs/requirements/mariadb/tools/mySqlScript.sql new file mode 100644 index 0000000..902e15c --- /dev/null +++ b/srcs/requirements/mariadb/tools/mySqlScript.sql @@ -0,0 +1,4 @@ +create database if not exists wordpress; +create user apommier@'%' identified by '1234'; +grant all privileges on *.* to apommier@'%'; +flush privileges; \ No newline at end of file diff --git a/srcs/requirements/mariadb/tools/start.sh b/srcs/requirements/mariadb/tools/start.sh new file mode 100644 index 0000000..ba29c68 --- /dev/null +++ b/srcs/requirements/mariadb/tools/start.sh @@ -0,0 +1 @@ +/usr/bin/mysqld_safe --datadir='/home/mariadb' \ No newline at end of file diff --git a/srcs/requirements/nginx/Dockerfile b/srcs/requirements/nginx/Dockerfile index 973b10e..78e3f0b 100644 --- a/srcs/requirements/nginx/Dockerfile +++ b/srcs/requirements/nginx/Dockerfile @@ -10,23 +10,15 @@ # # # **************************************************************************** # -FROM debian:buster +FROM debian:buster -RUN su -RUN apt update && apt upgrade -y -RUN apt install nginx sudo -y -#COPY /home/apommier/42/inception/srcs/wordpresse/ var/www/html +RUN apt update -y +RUN apt-get install -y nginx openssl -RUN ls var/www/ -#CMD ["echo","-----------new-----------"] -#CMD ["ls","var/www/"] -#CMD ["echo","-----------new-----------"] -#CMD ["ls","var/www/html"] -#CMD ["echo","-----------new-----------"] -#CMD ["ls","var/www/html2"] -#CMD ["echo","-----------new-----------"] -#CMD ["ls","var/www/html3"] -ENTRYPOINT ["nginx","-g","daemon off;"] -#RUN cd var/www/html && ls && cat index.php -#RUN ls var/www/ -#RUN sudo service nginx restart \ No newline at end of file +RUN mkdir -p /etc/ssl/private +RUN mkdir -p /etc/ssl/certs +RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt -subj "/C=FR/ST=17/L=StJeanDeLiversay/O=42/CN=apommier" + +COPY conf/nginx2.conf /etc/nginx/conf.d/default.conf + +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/srcs/requirements/nginx/conf/nginx.conf b/srcs/requirements/nginx/conf/nginx.conf index 0569fa0..b7aaa74 100644 --- a/srcs/requirements/nginx/conf/nginx.conf +++ b/srcs/requirements/nginx/conf/nginx.conf @@ -6,7 +6,7 @@ server { root /var/www/html2; - index index.php; + index index.php index.html; location / { autoindex on; diff --git a/srcs/requirements/nginx/conf/nginx2.conf b/srcs/requirements/nginx/conf/nginx2.conf new file mode 100644 index 0000000..e05c691 --- /dev/null +++ b/srcs/requirements/nginx/conf/nginx2.conf @@ -0,0 +1,26 @@ +server { + listen 443 ssl; + listen 80; + + server_name apommier.42.fr; + + ssl_protocols TLSv1.3; + ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt; + ssl_certificate_key //etc/ssl/private/nginx-selfsigned.key; + + index index.php; + + root /var/www/html; + + autoindex on; + + location / { + try_files $uri $uri/ =404; + } + + location ~ \.php$ { + include fastcgi.conf; + fastcgi_pass wordpress:9000; + fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; + } +} \ No newline at end of file diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index eb80cfa..08da3c2 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -13,24 +13,15 @@ FROM debian:buster RUN apt-get update -RUN apt install -y php-fpm -RUN apt install -y wget -RUN apt install -y tar +RUN apt-get -y install php7.3 php-mysqli php-fpm wget sendmail sudo -WORKDIR /var/www/html +EXPOSE 9000 -#RUN wget https://wordpress.org/latest.tar.gz -#RUN tar -xzvf latest.tar.gz -#RUN ls -#RUN ls /var -#RUN mkdir /var/www -#RUN mv ./wordpress /var/www/html +#COPY ./conf/www.conf /etc/php/7.3/fpm/pool.d +COPY ./tools /var/www/tools -RUN apt install -y php-mysql -RUN apt install -y php-gd -RUN apt install -y php-mysqli +RUN chmod +x /var/www/tools/start.sh -#RUN service php restart +ENTRYPOINT [ "/var/www/tools/start.sh" ] - -#RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql \ No newline at end of file +CMD ["/usr/sbin/php-fpm7.3", "--nodaemonize"] \ 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..5645eec --- /dev/null +++ b/srcs/requirements/wordpress/conf/www.conf @@ -0,0 +1,9 @@ +[www] +user = www-data +group = www-data +listen = wordpress:9000 +pm = dynamic +pm.start_servers = 6 +pm.max_children = 25 +pm.min_spare_servers = 2 +pm.max_spare_servers = 10 \ No newline at end of file diff --git a/srcs/requirements/wordpress/tools/start.sh b/srcs/requirements/wordpress/tools/start.sh new file mode 100644 index 0000000..8550913 --- /dev/null +++ b/srcs/requirements/wordpress/tools/start.sh @@ -0,0 +1,31 @@ +#!/bin/bash + + sed -i "s/listen = \/run\/php\/php7.3-fpm.sock/listen = 9000/" "/etc/php/7.3/fpm/pool.d/www.conf"; +# chown -R www-data:www-data /var/www/*; +# chown -R 755 /var/www/*; + mkdir -p /run/php/; + touch /run/php/php7.3-fpm.pid; + +if [ ! -f /var/www/html/wp-config.php ]; then + echo "Wordpress: setting up..." + mkdir -p /var/www/html + 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; + cd /var/www/html; + echo "Wordpress: downloading..." + wp core download --locale=fr_FR --allow-root; + #echo "Wordpress: creating users admin..." + echo "Wordpress: configuration..." + mv /var/www/tools/wp-config.php /var/www/html/ + #wp config create --dbname=${MARIADB_DATABASE} --dbuser=${MARIADB_USER} --dbpass=${MARIADB_PASSWORD} --dbhost=${WP_DB_HOST} --allow-root; + echo "Wordpress: installation..."; + wp core install --url=apommier.42.fr --title=CoUcoU --admin_user=admin --admin_password=admin --admin_email=admin@42.fr --skip-email --allow-root; + echo "Wordpress: create user..."; + #wp user create --allow-root ${WP_USER_LOGIN} ${WP_USER_EMAIL} --user_pass=${WP_USER_PASSWORD}; + wp user create apommier apommier@student.42.fr --user_pass=1234 --allow-root; + #sudo -u ${USER} -i -- wp user create ${WP_USER_LOGIN} apommier@student.42.fr --user_pass=${WP_USER_PASSWORD}; + echo "Wordpress: set up!" +fi + +exec "$@" \ No newline at end of file diff --git a/srcs/requirements/wordpress/tools/wp-config.php b/srcs/requirements/wordpress/tools/wp-config.php new file mode 100644 index 0000000..14e731e --- /dev/null +++ b/srcs/requirements/wordpress/tools/wp-config.php @@ -0,0 +1,98 @@ +_=r2;(P}<-Qi ZnAL%G3n CQWA' ); +define( 'SECURE_AUTH_KEY', 'T+2K-V&%Nb0+lvfRvom)BMt&aNXM:G`3!y>HwXk*tf=j:cR5!fccpWxAv5b&v`Qe' ); +define( 'LOGGED_IN_KEY', '3FV[c{H<[z<~d=m{-;5#g&5iZk{,Ceke76tc%CTGbksQvT),i=PoVz}bet;(dD+5' ); +define( 'NONCE_KEY', 'G>:_Ja?N<5ySFU?,g=[7?k~&tf)sFqElCa~Og.mpYhK* =eD4l6cLBa7O)m.yN)#' ); +define( 'AUTH_SALT', 'O,[H`{.h 6<~YG XUkw}&B6>/o]}<@9I apmJ PQ(%WsTI>jWvKPAUS`m4hdxy`Q$2kC3ZSLMrdFm^(W*xeG=lg/Xe%GKaIdX&' ); +define( 'LOGGED_IN_SALT', '2!0~FjHbN9&*7)-hzL$l~xQ6alaEm|1T0e2A9 71LsUF(kc&Cx