Skip to content

Commit

Permalink
add checker to check availability of redis (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidOstrozlik authored Feb 14, 2019
2 parents 6caa485 + f36de69 commit 72cdd28
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 20 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"shopsys/jparser": "0.1",
"shopsys/postgres-search-bundle": "0.1",
"slevomat/coding-standard": "^4.6.0",
"snc/redis-bundle": "2.1.4",
"snc/redis-bundle": "2.1.8",
"squizlabs/php_codesniffer": "^3.2.0",
"stof/doctrine-extensions-bundle": "^1.3.0",
"superbalist/flysystem-google-storage": "^7.1",
Expand All @@ -128,6 +128,7 @@
"symfony-cmf/routing-bundle": "^2.0.3",
"symfony/monolog-bridge": "^3.0.0",
"symfony/monolog-bundle": "^3.1.2",
"symfony/proxy-manager-bridge": "^3.4",
"symfony/swiftmailer-bundle": "^3.2.2",
"symfony/symfony": "^3.4.8",
"tracy/tracy": "^2.4.13",
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/required-php-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ opcache.use_cwd=1
| pdo | required by package `doctrine/orm` |
| pdo_pgsql | required to support `pdo_pgsql` database driver |
| pgsql | used in acceptance for fast repopulating of database using `COPY` command |
| redis | required by package `snc/redis-bundle` and sessions stored in Redis |
| redis | required by package `snc/redis-bundle` and sessions stored in Redis (minimal version is 4.1.1 because of lazyloading) |
| simplexml | used by Heureka product feed module in `\Shopsys\ProductFeed\HeurekaBundle\Model\HeurekaCategory\HeurekaCategoryCronModule` |
| tokenizer | used for `T_*` constants by `shopsys\coding-standards` package |
| xml | used by Phing for XML parsing |
Expand Down
16 changes: 16 additions & 0 deletions docs/upgrade/UPGRADE-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ for instance:
- *(optional)* add a new [script](https://github.com/shopsys/shopsys/pull/759/files#diff-e5f46a7c45e95214037078344ce17721) to `scripts/install.sh`
- this script serves as a fast way to install demo instance of Shopsys Framework.
- also this script can be used if you change the configuration of docker or app, script will apply all the changes done in these files and rebuild images.
- add a way to check if Redis is running [#815](https://github.com/shopsys/shopsys/pull/815)
- upgrade redis extension version in your `DockerFile` to version `4.1.1`
```diff
- RUN pecl install redis-4.0.2 && \
+ RUN pecl install redis-4.1.1 && \
```
- add a new phing target `redis-check` to your `build-dev.xml` and use it before any call to Redis like `clear-redis`
- You can find inspiration in [#815](https://github.com/shopsys/shopsys/pull/815/files)
```xml
<target name="redis-check" description="Checks availability of Redis">
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}" />
<arg value="shopsys:redis:check-availability" />
</exec>
</target>
```

### Database migrations
- after running database migrations, all your countries across domains will be merged together and original names will be added as translations
Expand Down
3 changes: 2 additions & 1 deletion packages/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
"shopsys/migrations": "dev-master",
"shopsys/form-types-bundle": "dev-master",
"shopsys/plugin-interface": "dev-master",
"snc/redis-bundle": "2.1.4",
"snc/redis-bundle": "2.1.8",
"stof/doctrine-extensions-bundle": "^1.3.0",
"swiftmailer/swiftmailer": "^6.0",
"symfony/assetic-bundle": "^2.8.2",
"symfony/monolog-bundle": "^3.1.2",
"symfony/proxy-manager-bridge": "^3.4",
"symfony/swiftmailer-bundle": "^3.2.2",
"symfony/symfony": "^3.4.8",
"symfony-cmf/routing": "^2.0.3",
Expand Down
53 changes: 53 additions & 0 deletions packages/framework/src/Command/CheckRedisCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Shopsys\FrameworkBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CheckRedisCommand extends Command
{
/**
* @var string
*/
protected static $defaultName = 'shopsys:redis:check-availability';

/**
* @var \Redis
*/
protected $cacheClients;

/**
* @param \Redis[] $cacheClients
*/
public function __construct(array $cacheClients)
{
$this->cacheClients = $cacheClients;

parent::__construct();
}

protected function configure()
{
$this
->setDescription('Checks availability of Redis');
}

/**
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Checks availability of Redis...');
foreach ($this->cacheClients as $cacheClient) {
try {
$cacheClient->ping();
} catch (\RedisException $e) {
throw new \Shopsys\FrameworkBundle\Command\Exception\RedisNotRunningException('Redis is not available.');
}
}
$output->writeln('Redis is available');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Shopsys\FrameworkBundle\Command\Exception;

use Exception;
use Throwable;

class RedisNotRunningException extends Exception
{
/**
* @param string $message
* @param int $code
* @param \Throwable|null $previous
*/
public function __construct($message = '', $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
8 changes: 8 additions & 0 deletions packages/framework/src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,3 +1015,11 @@ services:
Shopsys\FrameworkBundle\Model\Product\Search\Export\ProductSearchExporter: ~

Shopsys\FrameworkBundle\Model\Product\Search\ProductElasticsearchConverter: ~

Shopsys\FrameworkBundle\Command\CheckRedisCommand:
arguments:
$cacheClients:
- '@snc_redis.bestselling_products'
- '@snc_redis.doctrine_metadata'
- '@snc_redis.doctrine_query'
- '@snc_redis.session'
24 changes: 12 additions & 12 deletions project-base/build-dev.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="Shopsys Framework (dev)" default="build-demo-ci">

<target name="build-dev" depends="clean,clean-redis,composer-dev,npm,timezones-check,dirs-create,test-dirs-create,assets,db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,tests-acceptance-build,checks-diff" description="Builds application for development preserving your DB and runs checks on changed files."/>
<target name="build-dev-quick" depends="clean,clean-redis,composer-dev,npm,dirs-create,test-dirs-create,assets,db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls,grunt,tests-acceptance-build" description="Builds application for development preserving your DB while skipping nonessential steps."/>
<target name="build-demo-dev" depends="wipe-excluding-logs,clean-redis,composer-dev,npm,timezones-check,dirs-create,test-dirs-create,assets,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,tests-acceptance-build,checks-diff" description="Builds application for development with clean demo DB and runs checks on changed files."/>
<target name="build-demo-dev-quick" depends="wipe-excluding-logs,clean-redis,composer-dev,npm,dirs-create,test-dirs-create,assets,db-demo,product-search-recreate-structure,product-search-export-products,grunt,tests-acceptance-build" description="Builds application for development with clean demo DB while skipping nonessential steps."/>
<target name="build-demo-ci" depends="wipe-excluding-logs,clean-redis,timezones-check,dirs-create,test-dirs-create,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,checks-ci" description="Builds application for development with clean demo DB and runs CI checks."/>
<target name="build-demo-ci-diff" depends="wipe-excluding-logs,clean-redis,timezones-check,dirs-create,test-dirs-create,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,checks-ci-diff" description="Builds application for development with clean demo DB and runs CI checks on changed files."/>
<target name="build-dev" depends="clean,redis-check,clean-redis,composer-dev,npm,timezones-check,dirs-create,test-dirs-create,assets,db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,tests-acceptance-build,checks-diff" description="Builds application for development preserving your DB and runs checks on changed files."/>
<target name="build-dev-quick" depends="clean,redis-check,clean-redis,composer-dev,npm,dirs-create,test-dirs-create,assets,db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls,grunt,tests-acceptance-build" description="Builds application for development preserving your DB while skipping nonessential steps."/>
<target name="build-demo-dev" depends="wipe-excluding-logs,redis-check,clean-redis,composer-dev,npm,timezones-check,dirs-create,test-dirs-create,assets,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,tests-acceptance-build,checks-diff" description="Builds application for development with clean demo DB and runs checks on changed files."/>
<target name="build-demo-dev-quick" depends="wipe-excluding-logs,redis-check,clean-redis,composer-dev,npm,dirs-create,test-dirs-create,assets,db-demo,product-search-recreate-structure,product-search-export-products,grunt,tests-acceptance-build" description="Builds application for development with clean demo DB while skipping nonessential steps."/>
<target name="build-demo-ci" depends="wipe-excluding-logs,redis-check,clean-redis,timezones-check,dirs-create,test-dirs-create,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,checks-ci" description="Builds application for development with clean demo DB and runs CI checks."/>
<target name="build-demo-ci-diff" depends="wipe-excluding-logs,redis-check,clean-redis,timezones-check,dirs-create,test-dirs-create,db-demo,product-search-recreate-structure,product-search-export-products,grunt,error-pages-generate,checks-ci-diff" description="Builds application for development with clean demo DB and runs CI checks on changed files."/>

<target name="checks" depends="db-check-mapping,standards,tests" description="Checks ORM mapping, coding standards and runs unit, DB and smoke tests."/>
<target name="checks-diff" depends="db-check-mapping,standards-diff,tests" description="Checks ORM mapping, coding standards on changed files and runs unit, DB and smoke tests."/>
Expand All @@ -16,12 +16,12 @@
<target name="standards" depends="phplint,ecs,phpstan,twig-lint,yaml-lint,eslint-check" description="Checks coding standards."/>
<target name="standards-diff" depends="phplint-diff,ecs-diff,phpstan,twig-lint-diff,yaml-lint,eslint-check-diff" description="Checks coding standards on changed files."/>

<target name="test-db-demo" depends="clean,clean-redis,test-db-wipe-public-schema,test-db-import-basic-structure,test-db-migrations,test-create-domains-data,test-db-fixtures-demo,test-generate-friendly-urls,test-load-plugin-demo-data,test-replace-domains-urls" description="Drops all data in test database and creates a new one with demo data."/>
<target name="test-db-demo" depends="clean,redis-check,clean-redis,test-db-wipe-public-schema,test-db-import-basic-structure,test-db-migrations,test-create-domains-data,test-db-fixtures-demo,test-generate-friendly-urls,test-load-plugin-demo-data,test-replace-domains-urls" description="Drops all data in test database and creates a new one with demo data."/>
<target name="test-db-performance" depends="test-db-demo,test-db-fixtures-performance" description="Drops all data in test database and creates a new one with performance data."/>
<target name="tests-static" depends="tests-unit" description="Runs unit tests."/>
<target name="tests" depends="test-db-demo,tests-static,tests-functional,tests-smoke" description="Runs unit, functional and smoke tests on a newly built test database."/>

<target name="tests-performance-run" depends="clean,clean-redis,test-db-performance,tests-performance-warmup,tests-performance" description="Runs performance tests on a newly built test database with performance data."/>
<target name="tests-performance-run" depends="clean,redis-check,clean-redis,test-db-performance,tests-performance-warmup,tests-performance" description="Runs performance tests on a newly built test database with performance data."/>

<target name="composer-check" description="Checks if Composer lock file is valid.">
<exec
Expand Down Expand Up @@ -360,7 +360,7 @@
<phingcall target="eslint-fix-diff" />
</target>

<target name="tests-acceptance" depends="clean,clean-redis,test-db-dump" description="Runs acceptance tests. Running Selenium server is required.">
<target name="tests-acceptance" depends="clean,redis-check,clean-redis,test-db-dump" description="Runs acceptance tests. Running Selenium server is required.">
<available file="${path.env.test}" type="file" property="path.env.test.existed" />
<if>
<not>
Expand Down Expand Up @@ -408,7 +408,7 @@
</exec>
</target>

<target name="tests-smoke" depends="clean,clean-redis" description="Runs smoke tests.">
<target name="tests-smoke" depends="clean,redis-check,clean-redis" description="Runs smoke tests.">
<if>
<istrue value="${is-multidomain}" />
<then>
Expand Down Expand Up @@ -447,7 +447,7 @@
</if>
</target>

<target name="tests-functional" depends="clean,clean-redis" description="Runs functional tests.">
<target name="tests-functional" depends="clean,redis-check,clean-redis" description="Runs functional tests.">
<if>
<istrue value="${is-multidomain}" />
<then>
Expand Down Expand Up @@ -485,7 +485,7 @@
</if>
</target>

<target name="tests-performance" depends="clean,clean-redis" description="Runs performance tests.">
<target name="tests-performance" depends="clean,redis-check,clean-redis" description="Runs performance tests.">
<exec
executable="${path.phpunit.executable}"
logoutput="true"
Expand Down
15 changes: 11 additions & 4 deletions project-base/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
</if>

<target name="build" depends="build-deploy-part-1-db-independent, build-deploy-part-2-db-dependent" description="Builds application for production preserving your DB."/>
<target name="build-deploy-part-1-db-independent" depends="clean,clean-redis,composer,npm,dirs-create,assets" description="First part of application build for production preserving your DB (can be run without maintenance page)."/>
<target name="build-deploy-part-1-db-independent" depends="clean,redis-check,clean-redis,composer,npm,dirs-create,assets" description="First part of application build for production preserving your DB (can be run without maintenance page)."/>
<target name="build-deploy-part-2-db-dependent" depends="db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls,grunt,error-pages-generate,warmup" description="Second part of application build for production preserving your DB (must be run with maintenance page when containing DB migrations)."/>
<target name="build-new" depends="wipe,clean-redis,composer,npm,dirs-create,assets,db-rebuild,grunt,error-pages-generate,warmup,product-search-create-structure" description="Builds application for production with clean DB (with base data only)."/>
<target name="build-demo" depends="wipe,clean-redis,composer,npm,dirs-create,assets,db-demo,grunt,error-pages-generate,warmup,product-search-recreate-structure" description="Builds application for production with clean demo DB."/>
<target name="build-new" depends="wipe,redis-check,clean-redis,composer,npm,dirs-create,assets,db-rebuild,grunt,error-pages-generate,warmup,product-search-create-structure" description="Builds application for production with clean DB (with base data only)."/>
<target name="build-demo" depends="wipe,redis-check,clean-redis,composer,npm,dirs-create,assets,db-demo,grunt,error-pages-generate,warmup,product-search-recreate-structure" description="Builds application for production with clean demo DB."/>
<target name="db-demo" depends="db-wipe-public-schema,db-import-basic-structure,db-migrations,create-domains-data,db-fixtures-demo,load-plugin-demo-data,generate-friendly-urls,replace-domains-urls" description="Creates DB and fills it with demo data"/>
<target name="db-rebuild" depends="db-wipe-public-schema,db-import-basic-structure,db-migrations,create-domains-data,generate-friendly-urls,replace-domains-urls" description="Drops all data in database and creates a new one with base data only."/>
<target name="product-search-recreate-structure" depends="product-search-delete-structure,product-search-create-structure" description="Recreates structure for searching via elasticsearch (deletes existing structure and creates new one)" />
Expand Down Expand Up @@ -96,6 +96,13 @@
</exec>
</target>

<target name="redis-check" description="Checks availability of Redis">
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}" />
<arg value="shopsys:redis:check-availability" />
</exec>
</target>

<target name="clean-styles" description="Cleans up directories with CSS generated by Grunt.">
<delete failonerror="false" includeemptydirs="true">
<fileset dir="${path.web.styles.admin}/">
Expand Down Expand Up @@ -253,7 +260,7 @@
</exec>
</target>

<target name="error-pages-generate" depends="prod-warmup" description="Generates error pages displayed in production environment.">
<target name="error-pages-generate" depends="prod-warmup, redis-check" description="Generates error pages displayed in production environment.">
<exec executable="${path.php.executable}" passthru="true" checkreturn="true">
<arg value="${path.bin-console}" />
<arg value="shopsys:error-page:generate-all" />
Expand Down
2 changes: 1 addition & 1 deletion project-base/docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-k
apt-get update && apt-get install -y postgresql-10 postgresql-client-10 && apt-get clean

# install redis extension
RUN pecl install redis-4.0.2 && \
RUN pecl install redis-4.1.1 && \
docker-php-ext-enable redis

# install locales and switch to en_US.utf8 in order to enable UTF-8 support
Expand Down

0 comments on commit 72cdd28

Please sign in to comment.