add redis cache to wordpress

This commit is contained in:
Arnaud Lier 2025-01-25 17:58:23 +01:00
parent 41e05fdb12
commit 10c9645099
5 changed files with 39 additions and 1 deletions

View file

@ -42,6 +42,15 @@ services:
aliases:
- $DOMAIN_NAME
env_file: .env
redis:
restart: on-failure
build:
context: ./requirements/bonus/redis
dockerfile: Dockerfile
networks:
- inception
secrets:
- redis_password
wordpress:
restart: on-failure
depends_on:
@ -58,6 +67,7 @@ services:
secrets:
- db_password
- admin_password
- redis_password
env_file: .env
adminer:
restart: on-failure
@ -81,6 +91,8 @@ secrets:
file: ../secrets/db_root_password.txt
admin_password:
file: ../secrets/credentials.txt
redis_password:
file: ../secrets/redis_password.txt
networks:
inception:

View file

@ -0,0 +1,14 @@
FROM alpine:3.21.2
LABEL org.opencontainers.image.authors="alier@student.42mulhouse.fr"
RUN apk add redis
HEALTHCHECK --start-period=5s \
CMD [ "$(cat /run/secrets/redis_password | redis-cli --askpass ping)" = "PONG" ]
COPY tools/setup_redis.sh /setup_redis.sh
EXPOSE 6379
ENTRYPOINT ["sh", "setup_redis.sh"]

View file

@ -0,0 +1,6 @@
#!/bin/sh
echo "requirepass $(cat /run/secrets/redis_password)
bind * -::*" >> /etc/redis.conf
exec redis-server /etc/redis.conf

View file

@ -3,7 +3,7 @@ FROM alpine:3.21.2
LABEL org.opencontainers.image.authors="alier@student.42mulhouse.fr"
RUN apk add php84 php84-phar php84-fpm php84-mysqli php84-iconv php84-curl php84-dom php84-exif \
php84-fileinfo php84-pecl-imagick php84-mbstring php84-zip php84-gd php84-intl fcgi curl
php84-fileinfo php84-pecl-imagick php84-mbstring php84-zip php84-gd php84-intl php84-tokenizer fcgi curl
RUN ln -s /usr/bin/php84 /usr/bin/php && \
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \

View file

@ -5,8 +5,14 @@ if [ ! -e '/var/www/wordpress/wp-config.php' ]; then
cd /var/www/wordpress
wp config create --dbname="$DB_DB" --dbuser="$DB_USER" --dbpass="$(cat /run/secrets/db_password)" --dbhost=mariadb
wp config set WP_REDIS_HOST "redis"
wp config set WP_REDIS_PORT "6379"
wp config set WP_REDIS_DATABASE "0"
wp config set WP_REDIS_PASSWORD "$(cat /run/secrets/redis_password)"
wp core install --url="$DOMAIN_NAME" --title="$TITLE" --admin_user="$ADMIN_USER" --admin_email="$ADMIN_EMAIL" \
--admin_password="$(cat /run/secrets/admin_password)"
wp plugin install redis-cache --activate
wp redis enable
wp option update siteurl "https://$DOMAIN_NAME"
wp option update home "https://$DOMAIN_NAME"
wp user create bob bob@example.org