Skip to content

Commit

Permalink
Merge 901a753 into 911e586
Browse files Browse the repository at this point in the history
  • Loading branch information
kilip committed Nov 9, 2018
2 parents 911e586 + 901a753 commit b307085
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 70 deletions.
1 change: 1 addition & 0 deletions .env.dist
@@ -1,2 +1,3 @@
APPLICATION_ENV=development
TIMEZONE=Europe/Berlin
DOCKER_CONTAINER_NAME=yawik.dev
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -83,7 +83,7 @@ after_script:
# process coverage
- 'if [[ $COVERAGE = yes ]]; then
composer require php-coveralls/php-coveralls --no-scripts;
travis-retry vendor/bin/php-coveralls -vvv;
travis_retry vendor/bin/php-coveralls -vvv;
wget https://scrutinizer-ci.com/ocular.phar;
travis-retry ocular.phar code-coverage:upload --format=php-clover build/logs/clover.serialized;
travis_retry ocular.phar code-coverage:upload --format=php-clover build/logs/clover.serialized;
fi'
9 changes: 4 additions & 5 deletions docker-compose.yml
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
nginx:
image: nginx:alpine
container_name: yawik.nginx
container_name: ${DOCKER_CONTAINER_NAME}.nginx
volumes:
- ./etc/docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
- ./:/var/www/yawik
Expand All @@ -15,15 +15,14 @@ services:
- UMASK="0000"

php:
container_name: yawik.php
container_name: ${DOCKER_CONTAINER_NAME}.php
env_file:
- .env
build:
context: etc/docker/php
args:
TIMEZONE: ${TIMEZONE}
volumes:
- ./etc/docker/php/php-ini-overrides.ini:/usr/local/etc/php/conf.d/99-overrides.ini
- ./:/var/www/yawik
links:
- mongo
Expand All @@ -32,12 +31,12 @@ services:

mongo:
image: mongo:3.4.10
container_name: yawik.mongo
container_name: ${DOCKER_CONTAINER_NAME}.mongo
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/dev/null
volumes:
- ./var/mongodb:/data/db
- ./etc/docker/mongodb/data:/data/db
ports:
- "27017:27017"
command: mongod --smallfiles --logpath=/dev/null # --quiet
1 change: 1 addition & 0 deletions etc/docker/mongodb/.gitignore
@@ -0,0 +1 @@
/data
1 change: 1 addition & 0 deletions etc/docker/php/.gitignore
@@ -0,0 +1 @@
/php-ini-overrides.ini
16 changes: 14 additions & 2 deletions etc/docker/php/docker-entrypoint.sh
@@ -1,13 +1,25 @@
#!/bin/sh
set -e

echo $PWD
PHP_INI_OVERRIDE="etc/docker/php/php-ini-overrides.ini"
if [ ! -f ${PHP_INI_OVERRIDE} ]; then
# just using default configuration
PHP_INI_OVERRIDE="etc/docker/php/php-ini-overrides.ini.dist";
fi

TARGET=/usr/local/etc/php/conf.d/99-overrides.ini
cp -v ${PHP_INI_OVERRIDE} ${TARGET}

export DOCKER_ENV="yes"

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi

# start selenium server
#./bin/start-selenium > /dev/null 2>&1 &
./bin/start-selenium > /dev/null 2>&1 &
./bin/console clear-cache
umask 0000
chmod 777 var/cache -Rf
chmod 777 var/log -Rf
Expand Down
6 changes: 3 additions & 3 deletions etc/docker/php/php-ini-overrides.ini
@@ -1,8 +1,8 @@
upload_max_filesize = 10000M
post_max_size = 10008M
xdebug.remote_host="172.23.0.1"
xdebug.remote_host="172.30.0.1"
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=PHPSTORM
8 changes: 8 additions & 0 deletions etc/docker/php/php-ini-overrides.ini.dist
@@ -0,0 +1,8 @@
upload_max_filesize = 10000M
post_max_size = 10008M
xdebug.remote_host="172.23.0.1"
xdebug.remote_port=9001
xdebug.idekey=PHPSTORM
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
1 change: 1 addition & 0 deletions module/Behat/src/CoreContext.php
Expand Up @@ -31,6 +31,7 @@ class CoreContext extends RawMinkContext

public function __construct($config=null)
{
umask(0000);
if (is_null($config)) {
$config = __DIR__.'/../../../config/config.php';
}
Expand Down
98 changes: 69 additions & 29 deletions module/Core/src/Application.php
Expand Up @@ -16,7 +16,6 @@
use Zend\ModuleManager\Listener\ListenerOptions;
use Zend\Mvc\Application as BaseApplication;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Glob;

/**
* Yawik Custom MVC Application
Expand All @@ -27,12 +26,36 @@
*/
class Application extends BaseApplication
{
public static $VERSION;
const VERSION = '0.32-dev';

public static $env = 'production';
/**
* Current yawik revision
* @var string
*/
public static $revision;

/**
* Current yawik environment
* @var string
*/
public static $env;

/**
* Current yawik config directory
* @var string
*/
private static $configDir;

public static function getCompleteVersion()
{
//@TODO: provide better way to handle git versioning
//$isVendor = strpos(__FILE__, 'modules')!==false || strpos(__FILE__, 'vendor') !== false;
//$version = getenv('TRAVIS') || $isVendor ? "undefined":exec('git describe');
//$branch = getenv('TRAVIS') || $isVendor ? "undefined":exec('git rev-parse --abbrev-ref HEAD', $output, $retVal);
//static::$revision = $version.'['.$branch.']';
return static::VERSION;
}

/**
* Get required modules for Yawik
*
Expand Down Expand Up @@ -71,11 +94,11 @@ public static function getRequiredModules()
*/
public static function generateModuleConfiguration($loadModules=[])
{
$modules = ArrayUtils::merge(
$modules = array_merge(
static::getRequiredModules(),
$loadModules,
static::scanAdditionalModule()
);
$modules = ArrayUtils::merge($modules, $loadModules);
return $modules;
}

Expand Down Expand Up @@ -123,19 +146,17 @@ public static function init($configuration = [])
ini_set('display_errors', true);
ini_set('error_reporting', E_ALL | E_STRICT);

if (php_sapi_name() == 'cli-server') {
if (!static::setupCliServerEnv()) {
return false;
}
}

static::loadDotEnv();

$configuration = static::loadConfig($configuration);
static::checkCache($configuration);
return parent::init($configuration);
}

/**
* Check current cache status
* @param array $configuration
*/
private static function checkCache(array $configuration)
{
$config = $configuration['module_listener_options'];
Expand Down Expand Up @@ -175,7 +196,7 @@ private static function scanAdditionalModule()
* @return bool
* @codeCoverageIgnore
*/
private static function setupCliServerEnv()
public static function setupCliServerEnv()
{
$parseUrl = parse_url(substr($_SERVER["REQUEST_URI"], 1));
$route = isset($parseUrl['path']) ? $parseUrl['path']:null;
Expand All @@ -201,23 +222,12 @@ public static function loadDotEnv()
return;
}

$env = getcwd().'/.env';
if (!is_file($env)) {
$env = getcwd().'/.env.dist';
}
if (is_file($env)) {
$dotenv = new Dotenv();
$dotenv->load($env);
$dotenv = new Dotenv();
$dotenv->load(getcwd().'/.env.dist');
if (is_file($file = getcwd().'/.env')) {
$dotenv->load($file);
}

//@TODO: should move this version loading to somewhere else
$isVendor = strpos(__FILE__, 'modules')!==false || strpos(__FILE__, 'vendor') !== false;
$version = getenv('TRAVIS') || $isVendor ? "undefined":exec('git describe');
$branch = getenv('TRAVIS') || $isVendor ? "undefined":exec('git rev-parse --abbrev-ref HEAD', $output, $retVal);
static::$VERSION = $version.'['.$branch.']';


//@TODO: default timezone turns error when used
if (!is_string(getenv('TIMEZONE'))) {
putenv('TIMEZONE=Europe/Berlin');
}
Expand Down Expand Up @@ -275,11 +285,11 @@ public static function loadConfig($configuration = [])

// Use the $env value to determine the state of the flag
// caching disabled during install mode
'config_cache_enabled' => ($env == 'production') && !$installMode,
'config_cache_enabled' => ($env == 'production'),


// Use the $env value to determine the state of the flag
'module_map_cache_enabled' => ($env == 'production') && !$installMode,
'module_map_cache_enabled' => ($env == 'production'),

'module_map_cache_key' => 'module_map',

Expand Down Expand Up @@ -311,6 +321,36 @@ public static function loadConfig($configuration = [])
// force override modules to load only install module in installation mode
$modules = static::generateModuleConfiguration($modules);
$configuration['modules'] = $modules;

// force disabled cache when in install mode
if ($installMode) {
$configuration['module_listener_options']['config_cache_enabled'] = false;
$configuration['module_listener_options']['module_map_cache_enabled'] = false;
}

// setup docker environment
if (getenv('DOCKER_ENV')=='yes') {
$configuration = ArrayUtils::merge($configuration, static::getDockerEnv($configuration));
}
return $configuration;
}

/**
* Override configuration in docker environment
* @param $configuration
* @return array
*/
private static function getDockerEnv($configuration)
{
$cacheDir = $configuration['module_listener_options']['cache_dir'].'/docker';
$configDir = static::getConfigDir();
return [
'module_listener_options' => [
'cache_dir' => $cacheDir,
'config_glob_paths' => [
$configDir.'/autoload/*.docker.php',
]
]
];
}
}
2 changes: 1 addition & 1 deletion module/Core/src/Module.php
Expand Up @@ -40,7 +40,7 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte

public function getConsoleBanner(Console $console)
{
$name = Yawik::$VERSION;
$name = Application::getCompleteVersion();
$width = $console->getWidth();
return sprintf(
"==%1\$s==\n%2\$s%3\$s\n**%1\$s**\n",
Expand Down
28 changes: 21 additions & 7 deletions module/Core/src/Service/ClearCacheService.php
Expand Up @@ -63,24 +63,38 @@ public static function factory(ContainerInterface $container)
}

/**
* Clear all cache files
* Clear all cache files in cache directory.
* Only cleans cache file in path/to/yawik/var/cache/*.php.
* Files in sub cache directory will not be removed
*
* @throws \Exception when cache directory is null
* @throws \Exception when cache directory is not exists or not writable
*/
public function clearCache()
{
// do not clear cache when cache directory not exists
if (is_null($cacheDir = $this->options->getCacheDir()) || !is_dir($cacheDir)) {
return false;
$cacheDir = $this->options->getCacheDir();
if (is_null($cacheDir)) {
throw new \Exception(sprintf(
'Cache directory is not configured properly.'
));
}
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
throw new \Exception(
sprintf(
'Can not clear cache in "%s". Please be sure that directory exists and writable.',
$cacheDir
)
);
}
$finder = Finder::create()
->in($cacheDir)
->ignoreDotFiles(false)
->name('*.php')
->name('.checksum')
->files()
->depth(0)
;
$fs = $this->filesystem;
$fs->remove($finder);
return true;
$this->filesystem->remove($finder);
}

/**
Expand Down

0 comments on commit b307085

Please sign in to comment.