From 05ace8cff2ef02d19abd40097ac5546dca6a54ca Mon Sep 17 00:00:00 2001
From: Yassine Doghri <yassine@doghri.fr>
Date: Fri, 9 Apr 2021 13:43:37 +0000
Subject: [PATCH] perf(docker): add redis caching service for development

update Dockerfile to include php redis extension
- update development docs
---
 Dockerfile                |  4 ++++
 docker-compose.yml        | 12 ++++++++++++
 docs/setup-development.md | 35 ++++++++++++++++++++++++++++-------
 3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 5b64fb8483..e181870043 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,6 +17,10 @@ RUN apt-get update && apt-get install -y \
 RUN docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ \
     && docker-php-ext-install gd
 
+RUN pecl install -o -f redis \
+    &&  rm -rf /tmp/pear \
+    &&  docker-php-ext-enable redis
+
 RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
 
 RUN echo "file_uploads = On\n" \
diff --git a/docker-compose.yml b/docker-compose.yml
index c7f46e488e..3c442ac019 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -16,10 +16,21 @@ services:
     volumes:
       - .:/castopod
     depends_on:
+      - redis
       - mariadb
     networks:
       - castopod
 
+  redis:
+    image: "redis:alpine"
+    container_name: "castopod_redis"
+    ports:
+      - 6379:6379
+    volumes:
+      - redis:/data
+    networks:
+      - castopod
+
   mariadb:
     image: mariadb:latest
     container_name: castopod_mariadb
@@ -69,5 +80,6 @@ services:
       - castopod
 
 volumes:
+  redis:
   mariadb:
   phpmyadmin:
diff --git a/docs/setup-development.md b/docs/setup-development.md
index 6423818d7c..4a78bb47d1 100644
--- a/docs/setup-development.md
+++ b/docs/setup-development.md
@@ -36,15 +36,29 @@ git clone https://code.podlibre.org/podlibre/castopod.git
 ```
 
 2. Create a `.env` file with the minimum required config to connect the app to
-   the database:
+   the database and use redis as a cache handler:
 
 ```ini
 CI_ENVIRONMENT="development"
 
+app.baseURL="http://localhost:8080/"
+app.mediaBaseURL="http://localhost:8080/"
+
+app.adminGateway="cp-admin"
+app.authGateway="cp-auth"
+
 database.default.hostname="mariadb"
 database.default.database="castopod"
 database.default.username="podlibre"
 database.default.password="castopod"
+
+cache.handler="redis"
+cache.redis.host = "redis"
+
+# You may not want to use redis as your cache handler
+# Comment/remove the two lines above and uncomment
+# the next line for file caching.
+#cache.handler="file"
 ```
 
 > _NB._ You can tweak your environment by setting more environment variables in
@@ -99,18 +113,19 @@ docker-compose ps
 
 # Alternatively, you can check all docker processes (you should see composer and npm with an Exited status)
 docker ps -a
+
 ```
 
-> The `docker-compose up -d` command will boot 3 containers in the background:
+> The `docker-compose up -d` command will boot 4 containers in the background:
 >
-> - `castopod_app`: a php based container with codeigniter requirements
+> - `castopod_app`: a php based container with CodeIgniter4 requirements
 >   installed
+> - `castopod_redis`: a [redis](https://redis.io/) database to handle queries
+>   and pages caching
 > - `castopod_mariadb`: a [mariadb](https://mariadb.org/) server for persistent
 >   data
-> - `castopod_phpmyadmin`: a phpmyadmin server to visualize the mariadb database
->
-> _NB._ `./mariadb`, `./phpmyadmin` folders will be mounted in the project's
-> root directory to persist data and logs.
+> - `castopod_phpmyadmin`: a phpmyadmin server to visualize the mariadb
+>   database.
 
 ## Initialize and populate database
 
@@ -221,6 +236,12 @@ To see your changes, go to:
 # monitor the app container
 docker-compose logs --tail 50 --follow --timestamps app
 
+# interact with redis server using included redis-cli command
+docker exec -it castopod_redis redis-cli
+
+# monitor the redis container
+docker-compose logs --tail 50 --follow --timestamps redis
+
 # monitor the mariadb container
 docker-compose logs --tail 50 --follow --timestamps mariadb
 
-- 
GitLab