Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Docker: Select persistence cache and session handler #4

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Draft
51 changes: 49 additions & 2 deletions docker-compose.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
#!/usr/bin/env bash

# Stop on error
#set -e;
set -e;

# Persistence Cache and Session Handler
CACHE_AND_SESSION_HANDLER=tagaware.filesystem

while (( "$#" )); do
case "$1" in
-h|--help)
echo "Usage: $0 [--cache-and-session-handler=(redis|memcached)]";
echo "";
echo "\t-c,\t--cache-and-session-handler\tCache and session handler; redis, memcached or tagaware.filesystem (default)"
exit 0
;;
-c=*|--cache-and-session-handler=*)
CACHE_AND_SESSION_HANDLER="${1#*=}"
shift 1
;;
-c|--cache-and-session-handler)
CACHE_AND_SESSION_HANDLER=$2
shift 2
;;
*)
echo "Error: Unsupported argument '$1'" >&2
exit 1
;;
esac
done

# eZ Platform logs removal
rm -f var/logs/*.log;

# Docker Containers Cluster Build (except Solr which needs vendor/ezsystems/ezplatform-solr-search-engine/)
docker-compose up --build --detach varnish apache redis mariadb;
docker-compose up --build --detach varnish mariadb $CACHE_AND_SESSION_HANDLER;
docker-compose build --build-arg session_save_handler=$CACHE_AND_SESSION_HANDLER apache;

# MariaDB: Server Wait & Version Fetch
GET_MARIADB_VERSION_CMD="docker-compose exec mariadb mysql -proot -BNe 'SELECT VERSION();' | cut -d '-' -f 1 | head -n 1;";
Expand All @@ -19,9 +46,29 @@ while [ -n "`echo $MARIADB_VERSION | grep 'ERROR';`" ]; do
done;
echo "MariaDB version: $MARIADB_VERSION";

UNUSED_CONTAINER_LIST="memcached redis";

# Apache: Symfony parameters.yml
cp docker/apache/parameters.yml app/config/parameters.yml;
sed -i '' -e "s/MARIADB_VERSION/$MARIADB_VERSION/" app/config/parameters.yml;
if [[ 'redis' == "$CACHE_AND_SESSION_HANDLER" ]]; then
sed -i '' -e "s/CACHE_AND_SESSION_HOST/redis/" app/config/parameters.yml;
sed -i '' -e "s/CACHE_AND_SESSION_PORT/6379/" app/config/parameters.yml;
UNUSED_CONTAINER_LIST="memcached";
elif [[ 'memcached' == "$CACHE_AND_SESSION_HANDLER" ]]; then
sed -i '' -e "s/CACHE_AND_SESSION_HOST/memcached/" app/config/parameters.yml;
sed -i '' -e "s/CACHE_AND_SESSION_PORT/11211/" app/config/parameters.yml;
UNUSED_CONTAINER_LIST="redis";
else # tagaware.filesystem
sed -i '' -e "s/imports://" app/config/parameters.yml;
sed -i '' -e "s/.*resource: cache_pool/.*//" app/config/parameters.yml;
sed -i '' -e "s/env(CACHE_.*): .*//g" app/config/parameters.yml;
sed -i '' -e "s/env(SESSION_.*): .*//g" app/config/parameters.yml;
sed -i '' -e "s/ezplatform\.session\..*: .*//g" app/config/parameters.yml;
fi

# May remove unused Docker containers
docker-compose rm -sv $UNUSED_CONTAINER_LIST;

# Apache: Composer Authentication
if [ ! -f auth.json ]; then
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ services:
apache:
build: ./docker/apache
depends_on:
- redis
#- redis
#- memcached
- mariadb
#- solr
ports:
Expand All @@ -24,6 +25,8 @@ services:

redis:
image: redis:3.2
memcached:
image: memcached

mariadb:
image: mariadb:10.1
Expand Down
16 changes: 14 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Use a Docker containers cluster to have a typical architecture for eZ Platform i
* Reverse Proxy Cache Server:
- Varnish 2.4
- Varnish Modules 0.15
* [Persistence Cache](https://doc.ezplatform.com/en/2.5/guide/persistence_cache/) and Session Handling Servers:
* Optional [Persistence Cache](https://doc.ezplatform.com/en/2.5/guide/persistence_cache/) and Session Handling Servers:
- Redis 3.2
- Memcached
* DataBase Server:
- MariaDB 10.1
* Search Engine:
Expand All @@ -36,6 +37,11 @@ About
URLs and Command Lines
----------------------

### Builder

* Build with Redis as cache and session handler: `./docker-compose.bash --cache-and-session-handler=redis`
* Build with Memcached as cache and session handler: `./docker-compose.bash --cache-and-session-handler=memcached`

### Usefull URLs
* eZ Home page through Varnish: http://127.0.0.1:8080/
* eZ Admin through Varnish: http://127.0.0.1:8080/admin
Expand Down Expand Up @@ -64,7 +70,9 @@ URLs and Command Lines
- See eZ Symfony Tools info: `docker-compose exec apache composer show ezsystems/symfony-tools;`
- See eZ HTTP Cache bundle info: `docker-compose exec apache composer show ezsystems/ezplatform-http-cache;`
- See eZ Solr SE bundle info: `docker-compose exec apache composer show ezsystems/ezplatform-solr-search-engine;`
- Clear eZ caches: `docker-compose exec --user www-data apache sh -c "php bin/console cache:clear; php bin/console cache:pool:clear cache.redis;";`
- Clear eZ caches: `docker-compose exec --user www-data apache sh -c "php bin/console cache:clear;";`
- Clear eZ caches when using Redis: `docker-compose exec --user www-data apache sh -c "php bin/console cache:clear; php bin/console cache:pool:clear cache.redis;";`
- Clear eZ caches when using Memcached: `docker-compose exec --user www-data apache sh -c "php bin/console cache:clear; php bin/console cache:pool:clear cache.memcached;";`
- Open a shell into container as root: `docker-compose exec apache bash;`
- Open a shell into container as www-data: `docker-compose exec --user www-data apache bash;`
* Varnish
Expand Down Expand Up @@ -94,6 +102,9 @@ URLs and Command Lines
- Delete all keys: `docker-compose exec redis redis-cli FLUSHALL;`
- Open Redis CLI: `docker-compose exec redis redis-cli;`
- Open a shell into container: `docker-compose exec redis bash;`
* Memcached
- Get stats: `expect -c 'spawn docker-compose exec apache bash; send "telnet memcached 11211\r"; send "stats\r"; expect "END"; send "quit\r"; send "exit\r";';`
- Delete all keys: `expect -c 'spawn docker-compose exec apache bash; send "telnet memcached 11211\r"; send "flush_all\r"; expect "OK"; send "quit\r"; send "exit\r";';`
* TODO: Solr
- Get Solr version: `docker-compose exec solr bin/solr version;`
- Follow Solr logs: `docker-compose logs --follow solr;`
Expand All @@ -105,6 +116,7 @@ TODO

* Switch from 120.0.0.1 to localhost in README.md to be more consistent with vhost.conf `ServerName`
* Ensure compatibility with other unixoides than Mac OS X. For example, `sed -i ''` is specific to Mac OS X and a solution could be https://formulae.brew.sh/formula/gnu-sed
* Find a simpler way to monitor Memcached server. Starting w/ installing telnet command directly into memcached container.
* Maybe:
- Build Solr at the same time than other containers and uncomment that apache depends on solr
- Use more docker-compose.yml `volumes` and less Dockerfile `COPY`
Expand Down
11 changes: 9 additions & 2 deletions docker/apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ FROM debian:10
MAINTAINER [email protected]

ARG symfony_env=dev
ARG session_save_handler=tagaware.filesystem
ENV SYMFONY_ENV=$symfony_env

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -qq update \
&& apt-get -qq install -y \
cron \
curl \
telnet \
git \
zip unzip \
# Apache
Expand All @@ -24,6 +26,7 @@ RUN apt-get -qq update \
php-curl \
php-mbstring \
php-zip \
php-memcached \
php-redis \
# GD
libfreetype6-dev \
Expand All @@ -42,8 +45,12 @@ RUN pecl install xdebug \

# PHP-FPM: UDS Directory & Log Creation
RUN mkdir /run/php && touch /var/log/php7.3-fpm.log
# PHP-FPM: Redis as session handler
RUN echo "\n; Redis as session handler\nphp_value[session.save_handler] = redis\nphp_value[session.save_path] = \"tcp://redis:6379\"" >> /etc/php/7.3/fpm/pool.d/www.conf
# PHP-FPM: Redis o memcached as session handler
RUN if [[ 'redis' == $session_save_handler ]]; then \
echo "\n; Redis as session handler\nphp_value[session.save_handler] = redis\nphp_value[session.save_path] = \"tcp://redis:6379\"" >> /etc/php/7.3/fpm/pool.d/www.conf; \
elif [[ 'memcached' == $session_save_handler ]]; then \
echo "\n; Memcached as session handler\nphp_value[session.save_handler] = memcached\nphp_value[session.save_path] = \"memcached:11211\"" >> /etc/php/7.3/fpm/pool.d/www.conf; \
fi;
# Apache: FastCGI Module & PHP-FPM Configuration
RUN a2enmod proxy_fcgi setenvif rewrite \
&& a2enconf php7.3-fpm
Expand Down
13 changes: 6 additions & 7 deletions docker/apache/parameters.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: cache_pool/cache.redis.yml }
- { resource: cache_pool/cache.CACHE_AND_SESSION_HOST.yml }

parameters:
#TODO: May move all this to .env file or Dockerfile
Expand All @@ -11,13 +11,12 @@ parameters:
env(HTTPCACHE_PURGE_SERVER): http://varnish
#env(HTTPCACHE_VARNISH_INVALIDATE_TOKEN): docker

# https://doc.ezplatform.com/en/2.5/guide/persistence_cache/#redis
env(CACHE_POOL): cache.redis
env(CACHE_DSN): redis
# https://doc.ezplatform.com/en/2.5/guide/sessions/#handling-sessions-with-redis
#env(SESSION_HANDLER_ID): ~
# https://doc.ezplatform.com/en/2.5/guide/persistence_cache/
env(CACHE_POOL): cache.CACHE_AND_SESSION_HOST
env(CACHE_DSN): CACHE_AND_SESSION_HOST
# https://doc.ezplatform.com/en/2.5/guide/sessions/
ezplatform.session.handler_id: ~
env(SESSION_SAVE_PATH): tcp://redis:6379
env(SESSION_SAVE_PATH): tcp://CACHE_AND_SESSION_HOST:CACHE_AND_SESSION_PORT

env(DATABASE_HOST): mariadb
env(DATABASE_PASSWORD): root
Expand Down