diff --git a/Makefile b/Makefile index 0edbe3d..95c59e0 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,11 @@ all: up build: sudo docker network create --subnet=172.20.30.0/24 wordpress - sudo mkdir -p ./build /home/djonker/data/adminer - sudo curl -f https://wordpress.org/latest.tar.gz --output /home/djonker/data/latest.tar.gz - sudo tar -xvf /home/djonker/data/latest.tar.gz - sudo mv wordpress /home/djonker/data/wordpress - sudo cp srcs/requirements/wordpress/srcs/wordpress.conf /home/djonker/data/wordpress/wp-config.php - sudo curl -f https://downloads.wordpress.org/plugin/w3-total-cache.2.4.1.zip --output /home/djonker/data/rediscache.zip - sudo unzip /home/djonker/data/rediscache.zip - sudo mv w3-total-cache /home/djonker/data/wordpress/wp-content/plugins/w3-total-cache - sudo chown -R 33:33 /home/djonker/data/wordpress + sudo mkdir -p ./build /home/djonker/data/adminer /home/djonker/data/wordpress + sudo cp srcs/requirements/wordpress/srcs/wordpress.conf /home/djonker/data/wordpress/wp-config.php.temp + sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + sudo mv wp-cli.phar /home/djonker/data/wordpress/wp-cli.phar + sudo chmod +x /home/djonker/data/wordpress/wp-cli.phar sudo curl -L https://github.com/vrana/adminer/releases/download/v4.8.1/adminer-4.8.1.php --output /home/djonker/data/adminer/adminer.php up: build diff --git a/srcs/.env b/srcs/.env index 5312d12..7923a14 100644 --- a/srcs/.env +++ b/srcs/.env @@ -1,3 +1,9 @@ WORDPRESSDATABASEPASSWD=password WORDPRESSDATABASEUSER=wordpress WORDPRESSDATABASE=wordpress +WPADMINUSER=djonker +WPADMINPASSWD=password +WPADMINEMAIL=danny@houtworm.email +WPUSERUSER=user42 +WPUSERPASSWD=password +WPUSEREMAIL=user42@houtworm.email diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index a812018..5d8aab8 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -33,6 +33,17 @@ services: ipv4_address: 172.20.30.20 wordpress: build: ./requirements/wordpress + environment: + - WORDPRESSDATABASE=${WORDPRESSDATABASE} + - WORDPRESSDATABASEUSER=${WORDPRESSDATABASEUSER} + - WORDPRESSDATABASEPASSWD=${WORDPRESSDATABASEPASSWD} + - WPADMINUSER=${WPADMINUSER} + - WPADMINPASSWD=${WPADMINPASSWD} + - WPADMINEMAIL=${WPADMINEMAIL} + - WPUSERUSER=${WPUSERUSER} + - WPUSERPASSWD=${WPUSERPASSWD} + - WPUSEREMAIL=${WPUSEREMAIL} + init: true container_name: wordpress restart: always volumes: diff --git a/srcs/requirements/mariadb/srcs/start.sh b/srcs/requirements/mariadb/srcs/start.sh index 536a034..b9dc7c0 100644 --- a/srcs/requirements/mariadb/srcs/start.sh +++ b/srcs/requirements/mariadb/srcs/start.sh @@ -6,7 +6,7 @@ else mysql_install_db --user=mysql --datadir=/var/lib/mysql mysqld & sleep 10 mysql -e "CREATE DATABASE $WORDPRESSDATABASE" - mysql wordpress < wordpress.sql + #mysql wordpress < wordpress.sql mysql -e "GRANT ALL PRIVILEGES ON $WORDPRESSDATABASE.* TO $WORDPRESSDATABASEUSER@172.20.30.30 IDENTIFIED BY '$WORDPRESSDATABASEPASSWD'" mysql -e "GRANT ALL PRIVILEGES ON $WORDPRESSDATABASE.* TO $WORDPRESSDATABASEUSER@172.20.30.40 IDENTIFIED BY '$WORDPRESSDATABASEPASSWD'" killall mysqld diff --git a/srcs/requirements/redis/Dockerfile b/srcs/requirements/redis/Dockerfile index 0d874b3..e0b1d8a 100644 --- a/srcs/requirements/redis/Dockerfile +++ b/srcs/requirements/redis/Dockerfile @@ -3,4 +3,5 @@ RUN sleep 10 RUN apk update RUN apk add redis WORKDIR /root/ -CMD sh redis-server +CMD redis-server --protected-mode no +EXPOSE 6379/tcp diff --git a/srcs/requirements/wordpress/Dockerfile b/srcs/requirements/wordpress/Dockerfile index 742b510..f6ddaf5 100644 --- a/srcs/requirements/wordpress/Dockerfile +++ b/srcs/requirements/wordpress/Dockerfile @@ -1,4 +1,10 @@ FROM alpine +ARG WORDPRESSDATABASE=${WORDPRESSDATABASE} +ARG WORDPRESSDATABASEUSER=${WORDPRESSDATABASEUSER} +ARG WORDPRESSDATABASEPASSWD=${WORDPRESSDATABASEPASSWD} +ARG WPADMINUSER=${WPADMINUSER} +ARG WPADMINPASSWD=$(WPADMINPASSWD) +ARG WPADMINEMAIL=$(WPADMINEMAIL) RUN sleep 10 RUN apk update RUN apk add openssl @@ -11,8 +17,10 @@ RUN apk add php-curl RUN apk add php-json RUN apk add php-xml RUN apk add php-zip +RUN apk add php-phar +COPY srcs/start.sh /root/start.sh COPY srcs/www.conf /etc/php81/php-fpm.d/www.conf COPY srcs/wordpress.conf /var/www/wordpress/wp-config.php WORKDIR /root/ -CMD php-fpm81 -F -R +CMD sh start.sh EXPOSE 9000/tcp diff --git a/srcs/requirements/wordpress/srcs/start.sh b/srcs/requirements/wordpress/srcs/start.sh new file mode 100644 index 0000000..a54f935 --- /dev/null +++ b/srcs/requirements/wordpress/srcs/start.sh @@ -0,0 +1,20 @@ +#!/bin/sh +if cat /var/www/wordpress/wp-config.php +then + touch /var/www/wordpress/wp-config.php +else + sleep 15 + cd /var/www/wordpress + mv wp-cli.phar /usr/bin/wpcli + mv wp-config.php.temp wp-config.php + sed -i "23i define( 'DB_NAME', '${WORDPRESSDATABASE}' );" wp-config.php + sed -i "26i define( 'DB_USER', '${WORDPRESSDATABASEUSER}' );" wp-config.php + sed -i "29i define( 'DB_PASSWORD', '${WORDPRESSDATABASEPASSWD}' );" wp-config.php + wpcli core download + wpcli core install --url=https://djonker.42.fr --title=Wordpress --admin_user=${WPADMINUSER} --admin_password=${WPADMINPASSWD} --admin_email=${WPADMINEMAIL} + wpcli user create ${WPUSERUSER} ${WPUSEREMAIL} --user_pass=${WPUSERPASSWD} --role=subscriber + wpcli plugin install redis-cache --activate + chown -R 1000:1000 /var/www/wordpress +fi +wpcli redis enable +php-fpm81 -F -R diff --git a/srcs/requirements/wordpress/srcs/wordpress.conf b/srcs/requirements/wordpress/srcs/wordpress.conf index 07fc170..cc6cb21 100644 --- a/srcs/requirements/wordpress/srcs/wordpress.conf +++ b/srcs/requirements/wordpress/srcs/wordpress.conf @@ -20,13 +20,10 @@ // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ -define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ -define( 'DB_USER', 'wordpress' ); /** MySQL database password */ -define( 'DB_PASSWORD', 'password' ); /** MySQL hostname */ define( 'DB_HOST', '172.20.30.20' ); @@ -81,6 +78,11 @@ $table_prefix = 'wp_'; * @link https://wordpress.org/support/article/debugging-in-wordpress/ */ define( 'WP_DEBUG', false ); +define( 'WP_REDIS_HOST', '172.20.30.50' ); +define( 'WP_REDIS_PORT', 6379 ); +define( 'WP_REDIS_TIMEOUT', 1 ); +define( 'WP_REDIS_READ_TIMEOUT', 1 ); +define( 'WP_REDIS_DATABASE', 0 ); /* That's all, stop editing! Happy publishing. */ /** Absolute path to the WordPress directory. */