From b75f782453d83d89e0a95ff17572b128c368498c Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Mon, 28 Nov 2022 08:46:47 +0100 Subject: [PATCH] save 22-11-28 --- .gitignore | 1 - Makefile | 1 + README.md | 11 ++++++----- srcs/.env | 26 ++++++++++++++++++++++++++ srcs/bonus/gitea/start.sh | 4 ++-- srcs/bonus/hexo/README.md | 11 ++++++----- srcs/wordpress/Dockerfile | 14 ++++++++------ srcs/wordpress/start.sh | 19 +++++++++---------- srcs/wordpress/www.conf | 4 +--- 9 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 srcs/.env diff --git a/.gitignore b/.gitignore index aff0f57..ffa1aa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -srcs/.env inception.pem diff --git a/Makefile b/Makefile index 52f59e6..37fec60 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ $(CERT): mv inception.pem $(DATA_FOLDER)/ssl start: $(CERT) + mkdir -p $(DATA_FOLDER)/www/wordpress docker compose -f srcs/docker-compose.yml up --build debug: $(CERT) diff --git a/README.md b/README.md index c7faabe..d0b8930 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # Inception +## Subject: +### Mandatory: + Contenairize a web server which will host wordpresss localy with docker on alpine/debian base. + Server must be nginx and database mariadb. All services must be on their own containers +### Bonus: + Handle wordpress cache with redis, add adminer, add an ftp server and another service of your choice (gitea) -Projet 42: -Sujet: Conteneuriser un serveur web qui hebergera wordpress localement à l'aide de docker, alpine/debian, nginx et mariadb - -## Todo: -- add login/register/admin buttons in wordpress ## Instructions: ### Setup it: diff --git a/srcs/.env b/srcs/.env new file mode 100644 index 0000000..5b488f8 --- /dev/null +++ b/srcs/.env @@ -0,0 +1,26 @@ +DOMAIN=narnaud.42.fr +#DOMAIN=localhost + +MYSQL_ROOT_PWD=mariadbword + +WP_DATABASE_NAME=wordpress +WP_DATABASE_USR=maria +WP_DATABASE_PWD=mariaword +GITEA_DATABASE_NAME=giteadb +GITEA_DATABASE_USR=gitea +GITEA_DATABASE_PWD=giteaword + +WP_TITLE=Inception +WP_ADMIN_USR=theboss +WP_ADMIN_PWD=thebossword +WP_ADMIN_EMAIL=nicolas.rr.arnaud@gmail.com +WP_USR=narnaud +WP_PWD=narnaudword +WP_EMAIL=narnaud@student.42nice.fr + +FTP_USR=ftpuser +FTP_PWD=ftpuserword + +GITEA_ADMIN_USR=theboss +GITEA_ADMIN_PWD=thebossword +GITEA_ADMIN_MAIL=nicolas.rr.arnaud@gamil.com diff --git a/srcs/bonus/gitea/start.sh b/srcs/bonus/gitea/start.sh index 8953049..c1ffab9 100644 --- a/srcs/bonus/gitea/start.sh +++ b/srcs/bonus/gitea/start.sh @@ -3,7 +3,7 @@ while ! mariadb -hmariadb -u$GITEA_DATABASE_USR -p$GITEA_DATABASE_PWD $GITEA_DATABASE_NAME &>/dev/null; do echo "Gitea waiting db..." - sleep 5 + sleep 30 done if [ ! -f "app.ini.bak" ]; then @@ -17,4 +17,4 @@ if [ ! -f "app.ini.bak" ]; then gitea admin user create --username $GITEA_ADMIN_USR --password $GITEA_ADMIN_PWD --email $GITEA_ADMIN_MAIL --admin fi echo "Launching gitea on localhost:3000" -gitea web --config /etc/gitea/app.ini &> /dev/null +gitea web --config /etc/gitea/app.ini diff --git a/srcs/bonus/hexo/README.md b/srcs/bonus/hexo/README.md index c7faabe..d0b8930 100644 --- a/srcs/bonus/hexo/README.md +++ b/srcs/bonus/hexo/README.md @@ -1,10 +1,11 @@ # Inception +## Subject: +### Mandatory: + Contenairize a web server which will host wordpresss localy with docker on alpine/debian base. + Server must be nginx and database mariadb. All services must be on their own containers +### Bonus: + Handle wordpress cache with redis, add adminer, add an ftp server and another service of your choice (gitea) -Projet 42: -Sujet: Conteneuriser un serveur web qui hebergera wordpress localement à l'aide de docker, alpine/debian, nginx et mariadb - -## Todo: -- add login/register/admin buttons in wordpress ## Instructions: ### Setup it: diff --git a/srcs/wordpress/Dockerfile b/srcs/wordpress/Dockerfile index 750324f..9ea4743 100644 --- a/srcs/wordpress/Dockerfile +++ b/srcs/wordpress/Dockerfile @@ -9,17 +9,19 @@ RUN apk update && apk upgrade && apk add --no-cache \ php8-shmop php8-simplexml php8-soap php8-sockets php8-sodium php8-sqlite3 php8-sysvsem \ php8-sysvshm php8-tokenizer php8-xml php8-xmlreader php8-xmlwriter php8-xsl php8-zip php8-zlib -RUN adduser -S nginx && addgroup -S nginx -COPY php-fpm.conf /etc/php8/php-fpm.conf -COPY www.conf /etc/php8/php-fpm.d/www.conf +RUN addgroup -g 1000 nginx && adduser -u 1000 -G nginx -D nginx RUN wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar RUN chmod +x wp-cli.phar RUN cp wp-cli.phar /usr/bin/wp RUN ln -s /usr/bin/php8 /usr/bin/php -WORKDIR /var/www/wordpress/ - - +COPY php-fpm.conf /etc/php8/php-fpm.conf +COPY www.conf /etc/php8/php-fpm.d/www.conf COPY start.sh /tmp/start.sh + +WORKDIR /var/www/wordpress/ +RUN chown -hR 1000:1000 /var/www /etc/php8 /var/log/php8 /run \ + && chmod -R g+wrx /var/www /etc/php* /var/log/php8 /run +USER 1000 ENTRYPOINT [ "sh", "/tmp/start.sh" ] diff --git a/srcs/wordpress/start.sh b/srcs/wordpress/start.sh index 12158fe..d957d99 100644 --- a/srcs/wordpress/start.sh +++ b/srcs/wordpress/start.sh @@ -3,13 +3,12 @@ while ! mariadb -hmariadb -u$WP_DATABASE_USR -p$WP_DATABASE_PWD $WP_DATABASE_NAM echo "Wordpress waiting db..." sleep 5 done - if [ ! -f "index.php" ]; then - wp core download --allow-root - wp config create --dbname=$WP_DATABASE_NAME --dbuser=$WP_DATABASE_USR --dbpass=$WP_DATABASE_PWD --dbhost=mariadb --dbcharset="utf8" --dbcollate="utf8_general_ci" --allow-root - wp core install --url=https://$DOMAIN/wordpress --title=$WP_TITLE --admin_user=$WP_ADMIN_USR --admin_password=$WP_ADMIN_PWD --admin_email=$WP_ADMIN_EMAIL --skip-email --allow-root - wp user create $WP_USR $WP_EMAIL --role=author --user_pass=$WP_PWD --allow-root - wp theme install generatepress --activate --allow-root + wp core download + wp config create --dbname=$WP_DATABASE_NAME --dbuser=$WP_DATABASE_USR --dbpass=$WP_DATABASE_PWD --dbhost=mariadb --dbcharset="utf8" --dbcollate="utf8_general_ci" + wp core install --url=https://$DOMAIN/wordpress --title=$WP_TITLE --admin_user=$WP_ADMIN_USR --admin_password=$WP_ADMIN_PWD --admin_email=$WP_ADMIN_EMAIL --skip-email + wp user create $WP_USR $WP_EMAIL --role=author --user_pass=$WP_PWD + wp theme install generatepress --activate wp widget add meta sidebar-1 1 sed -i "90i define('WP_REDIS_HOST', 'redis');" wp-config.php @@ -18,9 +17,9 @@ if [ ! -f "index.php" ]; then sed -i "93i define('WP_REDIS_READ_TIMEOUT', 1);" wp-config.php sed -i "94i define('WP_REDIS_DATABASE', 0);" wp-config.php - wp plugin install redis-cache --activate --allow-root - wp plugin update --all --allow-root + wp plugin install redis-cache --activate + wp plugin update --all wget -O adminer.php https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1-mysql-en.php fi -wp redis enable --allow-root -/usr/sbin/php-fpm8 -R &> /dev/null +wp redis enable +/usr/sbin/php-fpm8 -R diff --git a/srcs/wordpress/www.conf b/srcs/wordpress/www.conf index 5cfac25..0e22408 100644 --- a/srcs/wordpress/www.conf +++ b/srcs/wordpress/www.conf @@ -1,10 +1,8 @@ [www] -user = nginx -group = nginx listen = 9000 pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 -pm.max_spare_servers = 3 \ No newline at end of file +pm.max_spare_servers = 3