Skip to content

Commit

Permalink
EZP-30750: Added possibility to set purge_type with environmental var…
Browse files Browse the repository at this point in the history
…iables (#490)
  • Loading branch information
webhdx authored and lserwatka committed Jan 16, 2020
1 parent 14adbf6 commit dd7a676
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 21 deletions.
7 changes: 6 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ CACHE_DSN=localhost

# eZ Platform HTTP Cache
HTTPCACHE_DEFAULT_TTL=86400
HTTPCACHE_PURGE_SERVER=http://localhost:
HTTPCACHE_PURGE_SERVER=http://localhost:80
HTTPCACHE_VARNISH_INVALIDATE_TOKEN=~

# Uncomment following line if you want to change the purge type.
# By default it will use `local` purge when running locally
# and `varnish` for Platform.sh installations.
# HTTPCACHE_PURGE_TYPE=local

# Doctrine DBAL
DATABASE_USER=ezp
DATABASE_PASSWORD=SetYourOwnPassword
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ matrix:
env: BEHAT_OPTS="--mode=behat --profile=content-forms --tags=~@broken --non-strict"
- name: "Admin UI on Clean Platform"
env: BEHAT_OPTS="--profile=adminui --suite=adminui"
- name: "Admin UI on Clean Platform with Varnish and Redis"
env:
- COMPOSE_FILE="doc/docker/base-dev.yml:doc/docker/varnish.yml:doc/docker/redis.yml:doc/docker/selenium.yml"
- BEHAT_OPTS="--profile=adminui --suite=adminui"
- WEB_HOST="varnish"
- if: type in (cron, api)
name: "Admin UI tests using different personas"
env:
Expand Down
File renamed without changes.
29 changes: 14 additions & 15 deletions config/packages/ezplatform.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
imports:
- { resource: cache_pool/cache.tagaware.filesystem.yaml }
# Uncomment following cache pools if you want to use redis or memcached
# - { resource: cache_pool/cache.redis.yaml }
# - { resource: cache_pool/cache.memcached.yaml }
# Or if you have more special needs create your own Symfony cache service

parameters:
locale_fallback: en

# One of `legacy` (default) or `solr`
search_engine: '%env(SEARCH_ENGINE)%'

## Session handler, by default set to file based (instead of ~) in order to be able to use %ezplatform.session.save_path%
ezplatform.session.handler_id: session.handler.native_file

# Session save path as used by symfony session handlers (eg. used for dsn with redis)
ezplatform.session.save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'

Expand All @@ -29,15 +19,24 @@ parameters:
# Settings for HttpCache
purge_server: '%env(HTTPCACHE_PURGE_SERVER)%'

## Purge type used by HttpCache system ("local", "varnish"/"http", and on ee also "fastly")
purge_type: local
# Identifier used to generate the CSRF token. Commenting this line will result in authentication
# issues both in AdminUI and REST calls
ezpublish_rest.csrf_token_intention: authenticate

# Varnish invalidation/purge token (for use on platform.sh, eZ Platform Cloud and other places you can't use IP for ACL)
# varnish_invalidate_token: '%env(HTTPCACHE_VARNISH_INVALIDATE_TOKEN)%' # @todo option is not available for some reason

# Identifier used to generate the CSRF token. Commenting this line will result in authentication
# issues both in AdminUI and REST calls
ezpublish_rest.csrf_token_intention: authenticate
# Compile time handlers
## These are defined at compile time, and hence can't be set at runtime using env()
## config/env/generic.php takes care about letting you set them by env variables

## Session handler, by default set to file based (instead of ~) in order to be able to use %ezplatform.session.save_path%
# env: SESSION_HANDLER_ID
ezplatform.session.handler_id: session.handler.native_file

## Purge type used by HttpCache system ("local", "varnish"/"http", and on ee also "fastly")
# env: HTTPCACHE_PURGE_TYPE
purge_type: local

ezplatform:
# HttpCache settings, By default 'local' (Symfony HttpCache Proxy), by setting it to 'http' you can point it to Varnish
Expand Down
78 changes: 78 additions & 0 deletions config/packages/overrides/generic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

// On Symfony container compilation*, reads parameters from env variables if defined and overrides the yml parameters.
// * For typical use cases like Docker, make sure to recompile Symfony container on run to refresh settings.

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader;

if ($dfsNfsPath = getenv('DFS_NFS_PATH')) {
$container->setParameter('dfs_nfs_path', $dfsNfsPath);

if ($value = getenv('DFS_DATABASE_DRIVER')) {
$container->setParameter('dfs_database_driver', $value);
} else {
$container->setParameter('dfs_database_driver', $container->getParameter('database_driver'));
}

if ($value = getenv('DFS_DATABASE_HOST')) {
$container->setParameter('dfs_database_host', $value);
} else {
$container->setParameter('dfs_database_host', $container->getParameter('database_host'));
}

if ($value = getenv('DFS_DATABASE_PORT')) {
$container->setParameter('dfs_database_port', $value);
} else {
$container->setParameter('dfs_database_port', $container->getParameter('database_port'));
}

if ($value = getenv('DFS_DATABASE_NAME')) {
$container->setParameter('dfs_database_name', $value);
} else {
$container->setParameter('dfs_database_name', $container->getParameter('database_name'));
}

if ($value = getenv('DFS_DATABASE_USER')) {
$container->setParameter('dfs_database_user', $value);
} else {
$container->setParameter('dfs_database_user', $container->getParameter('database_user'));
}

if ($value = getenv('DFS_DATABASE_PASSWORD')) {
$container->setParameter('dfs_database_password', $value);
} else {
$container->setParameter('dfs_database_password', $container->getParameter('database_password'));
}

$loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/dfs'));
$loader->load('dfs.yml');
}

// Cache settings
// If CACHE_POOL env variable is set, check if there is a yml file that needs to be loaded for it
if (($pool = getenv('CACHE_POOL')) && file_exists(dirname(__DIR__)."/cache_pool/${pool}.yaml")) {
$loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/cache_pool'));
$loader->load($pool.'.yaml');
}

// Params that needs to be set at compile time and thus can't use Symfony's env()
if ($purgeType = getenv('HTTPCACHE_PURGE_TYPE')) {
$container->setParameter('purge_type', $purgeType);
}

if ($value = getenv('MAILER_TRANSPORT')) {
$container->setParameter('mailer_transport', $value);
}

if ($value = getenv('LOG_TYPE')) {
$container->setParameter('log_type', $value);
}

if ($value = getenv('SESSION_HANDLER_ID')) {
$container->setParameter('ezplatform.session.handler_id', $value);
}

if ($value = getenv('SESSION_SAVE_PATH')) {
$container->setParameter('ezplatform.session.save_path', $value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
$container->setParameter('dfs_database_password', $container->getParameter('database_password'));
}

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/dfs'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/dfs'));
$loader->load('dfs.yaml');
}
// Use Redis-based caching if possible.
Expand All @@ -57,11 +57,11 @@
continue;
}

$loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/cache_pool'));
$loader->load('cache.redis.yaml');

$container->setParameter('cache_pool', 'cache.redis');
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']) . '?retry_interval=3');

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/cache_pool'));
$loader->load('cache.redis.yaml');
}
} elseif (isset($relationships['cache'])) {
// Fallback to memcached if here (deprecated, we will only handle redis here in the future)
Expand All @@ -75,7 +75,7 @@
$container->setParameter('cache_pool', 'cache.memcached');
$container->setParameter('cache_dsn', sprintf('%s:%d', $endpoint['host'], $endpoint['port']));

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/cache_pool'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(dirname(__DIR__).'/cache_pool'));
$loader->load('cache.memcached.yaml');
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
$confDir = $this->getProjectDir().'/config';

$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/overrides/**/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
Expand Down

0 comments on commit dd7a676

Please sign in to comment.