From ffd17ace2c90e14b0d0acbfe7b10d75361a7a641 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 15 Sep 2016 18:52:07 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20Docker=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=20=D1=81=D0=B8=D0=BB=D1=83=20=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B7=D0=BD=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 +++- docker/mariadb/Dockerfile | 3 +++ docker/nginx/Dockerfile | 3 ++- docker/nginx/run.sh | 3 ++- docker/phpmyadmin/Dockerfile | 3 +++ docker/rabbitmq/Dockerfile | 3 +++ 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0f6d4d..cb36528 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ RUN apt-get update \ libicu-dev \ libmcrypt-dev \ zlib1g-dev \ + openssh-server \ --no-install-recommends \ # Install PHP extensions @@ -59,7 +60,8 @@ RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux- && ln -s /usr/local/bin/node /usr/local/bin/nodejs # Поставим xdebug отдельно, т.к. потом его потенциально придётся отсюда убирать -RUN yes | pecl install xdebug \ +# фиксируем версию, т.к. 2.4.1 не собирается под 7.1 +RUN yes | pecl install xdebug-2.4.0 \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.default_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ diff --git a/docker/mariadb/Dockerfile b/docker/mariadb/Dockerfile index ae236a8..20afa74 100644 --- a/docker/mariadb/Dockerfile +++ b/docker/mariadb/Dockerfile @@ -1,3 +1,6 @@ FROM mariadb:10.0 COPY mariadb.cnf /etc/mysql/conf.d + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["mysqld"] diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index ed15437..d524401 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -7,4 +7,5 @@ COPY run.sh /run.sh RUN rm /etc/nginx/conf.d/default.conf \ && chmod a+x /run.sh -CMD ["/run.sh"] +ENTRYPOINT ["/run.sh"] +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx/run.sh b/docker/nginx/run.sh index 364e6e7..a4d80cf 100644 --- a/docker/nginx/run.sh +++ b/docker/nginx/run.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash envsubst '$AUTHSERVER_HOST:$PHP_LINK' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf -nginx -g 'daemon off;' + +exec "$@" diff --git a/docker/phpmyadmin/Dockerfile b/docker/phpmyadmin/Dockerfile index c054f47..62e24d4 100644 --- a/docker/phpmyadmin/Dockerfile +++ b/docker/phpmyadmin/Dockerfile @@ -3,3 +3,6 @@ FROM phpmyadmin/phpmyadmin RUN printf "\n\nrequire('./config.local.php');\n" >> /www/config.inc.php COPY config.local.php /www/ + +ENTRYPOINT [ "/run.sh" ] +CMD ["phpmyadmin"] diff --git a/docker/rabbitmq/Dockerfile b/docker/rabbitmq/Dockerfile index 27005d8..8e27027 100644 --- a/docker/rabbitmq/Dockerfile +++ b/docker/rabbitmq/Dockerfile @@ -3,3 +3,6 @@ FROM rabbitmq:3.6 RUN rabbitmq-plugins enable rabbitmq_management \ && rabbitmq-plugins enable rabbitmq_web_stomp \ && rabbitmq-plugins enable rabbitmq_mqtt + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["rabbitmq-server"] From e76a8324fb9cc5b43d51e51ba703d27517d10c2c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 15 Sep 2016 18:55:30 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BC?= =?UTF-8?q?=20=D1=81=D0=B5=D1=82=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D1=81=D1=83?= =?UTF-8?q?=D0=BF=D0=BF=D0=BE=D1=80=D1=82=20nginx-proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 773afd9..530402d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,9 @@ services: volumes: - ./:/var/www/html/ env_file: .env + networks: + - default + - nginx-proxy web: build: ./docker/nginx @@ -19,8 +22,12 @@ services: volumes_from: - app environment: - - AUTHSERVER_HOST=authserver.ely.by + - AUTHSERVER_HOST=authserver.ely.by.local - PHP_LINK=app + - VIRTUAL_HOST=account.ely.by.local,authserver.ely.by.local + networks: + - default + - nginx-proxy node-dev-server: build: ./frontend @@ -35,7 +42,7 @@ services: build: . volumes: - ./:/var/www/html/ - command: ./docker/wait-for-it.sh rabbitmq:5672 -- ./yii account-queue + command: ["./docker/wait-for-it.sh", "rabbitmq:5672", "--", "./yii account-queue"] links: - db - redis @@ -72,3 +79,8 @@ services: - "8181:80" links: - db + +networks: + nginx-proxy: + external: + name: nginx-proxy From 54485b2271beb421361fe98232f07fc6d0ea382d Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 16 Sep 2016 01:28:28 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=9E=D0=B3=D1=80=D0=BE=D0=BC=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=20=D0=B2=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=20?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=BE=D1=82=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=85=D0=B0=D0=BD=D0=B8=D0=B7=D0=BC=D0=B0=20environment?= =?UTF-8?q?=20=D0=B8=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20.env=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=B0=20=D0=9D=D0=B0=D0=B9=D0=B4=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BC=D1=83=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 +- .env | 26 ++- .env-dist | 26 +++ .gitignore | 10 +- api/config/.gitignore | 1 - api/config/main-dev.php | 19 ++ api/config/main.php | 30 ++- api/config/params.php | 1 - .../session/controllers/SessionController.php | 1 + api/modules/session/filters/RateLimiter.php | 5 +- api/web/.gitignore | 2 - api/web/favicon.ico | Bin 318 -> 0 bytes api/web/index.php | 16 ++ common/config/.gitignore | 1 - common/config/config-loader.php | 43 ++++ common/config/main-dev.php | 8 + common/config/main.php | 16 +- common/config/params.php | 5 +- console/config/.gitignore | 1 - .../config/main-dev.php | 0 console/config/main.php | 12 +- console/config/params.php | 1 - docker-compose.yml | 32 +-- docker/nginx/account.ely.by.conf.template | 2 +- docker/nginx/run.sh | 2 +- environments/dev/api/config/main-local.php | 26 --- environments/dev/api/config/params-local.php | 5 - environments/dev/api/web/index-test.php | 18 -- environments/dev/api/web/index.php | 18 -- environments/dev/common/config/main-local.php | 29 --- .../dev/common/config/params-local.php | 5 - .../dev/console/config/params-local.php | 3 - environments/dev/yii | 28 --- environments/docker/.env | 2 - environments/docker/api/config/main-local.php | 25 --- .../docker/api/config/params-local.php | 5 - environments/docker/api/web/index-test.php | 18 -- environments/docker/api/web/index.php | 18 -- .../docker/common/config/main-local.php | 26 --- .../docker/common/config/params-local.php | 5 - .../docker/console/config/main-local.php | 7 - .../docker/console/config/params-local.php | 3 - environments/docker/yii | 28 --- environments/index.php | 73 ------ environments/prod/api/config/main-local.php | 13 -- environments/prod/api/config/params-local.php | 5 - environments/prod/api/web/index.php | 18 -- .../prod/common/config/main-local.php | 23 -- .../prod/common/config/params-local.php | 5 - .../prod/console/config/main-local.php | 3 - .../prod/console/config/params-local.php | 3 - environments/prod/yii | 28 --- init | 209 ------------------ init.bat | 20 -- yii | 18 ++ yii.bat | 20 -- 56 files changed, 209 insertions(+), 763 deletions(-) create mode 100644 .env-dist create mode 100644 api/config/main-dev.php delete mode 100644 api/web/.gitignore delete mode 100644 api/web/favicon.ico create mode 100644 api/web/index.php create mode 100644 common/config/config-loader.php create mode 100644 common/config/main-dev.php rename environments/dev/console/config/main-local.php => console/config/main-dev.php (100%) delete mode 100644 environments/dev/api/config/main-local.php delete mode 100644 environments/dev/api/config/params-local.php delete mode 100644 environments/dev/api/web/index-test.php delete mode 100644 environments/dev/api/web/index.php delete mode 100644 environments/dev/common/config/main-local.php delete mode 100644 environments/dev/common/config/params-local.php delete mode 100644 environments/dev/console/config/params-local.php delete mode 100644 environments/dev/yii delete mode 100644 environments/docker/.env delete mode 100644 environments/docker/api/config/main-local.php delete mode 100644 environments/docker/api/config/params-local.php delete mode 100644 environments/docker/api/web/index-test.php delete mode 100644 environments/docker/api/web/index.php delete mode 100644 environments/docker/common/config/main-local.php delete mode 100644 environments/docker/common/config/params-local.php delete mode 100644 environments/docker/console/config/main-local.php delete mode 100644 environments/docker/console/config/params-local.php delete mode 100644 environments/docker/yii delete mode 100644 environments/index.php delete mode 100644 environments/prod/api/config/main-local.php delete mode 100644 environments/prod/api/config/params-local.php delete mode 100644 environments/prod/api/web/index.php delete mode 100644 environments/prod/common/config/main-local.php delete mode 100644 environments/prod/common/config/params-local.php delete mode 100644 environments/prod/console/config/main-local.php delete mode 100644 environments/prod/console/config/params-local.php delete mode 100644 environments/prod/yii delete mode 100644 init delete mode 100644 init.bat create mode 100755 yii delete mode 100644 yii.bat diff --git a/.dockerignore b/.dockerignore index 9690815..f95a9d8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -5,9 +5,8 @@ vendor # node_modules для этого контейнера не нужны frontend/node_modules - -# Все -local файлы -*/config/*-local.php +frontend/webpack/node_modules +frontend/scripts/node_modules # Все временные файлы */runtime diff --git a/.env b/.env index 3a6845c..5f0eb80 100644 --- a/.env +++ b/.env @@ -1,2 +1,26 @@ -XDEBUG_CONFIG=remote_host=192.168.99.1 +# Основные параметры +YII_DEBUG=true +YII_ENV=dev +JWT_USER_SECRET=edee109cad8b323d6d9edbcf406d945a989af6b6d251e4953a48df756695963a + +# Web +VIRTUAL_HOST=account.ely.by.local,authserver.ely.by.local +AUTHSERVER_HOST=authserver.ely.by.local +# LETSENCRYPT_HOST=account.ely.by +# LETSENCRYPT_EMAIL=erickskrauch@ely.by + +# MySQL +MYSQL_ALLOW_EMPTY_PASSWORD=yes +MYSQL_ROOT_PASSWORD= +MYSQL_DATABASE=ely_accounts +MYSQL_USER=ely_accounts_user +MYSQL_PASSWORD=ely_accounts_password + +# RabbitMQ +RABBITMQ_DEFAULT_USER=ely-accounts-app +RABBITMQ_DEFAULT_PASS=ely-accounts-app-password +RABBITMQ_DEFAULT_VHOST=/ely.by + +# Конфигурация для Dev. +XDEBUG_CONFIG=remote_host=10.254.254.254 PHP_IDE_CONFIG=serverName=docker diff --git a/.env-dist b/.env-dist new file mode 100644 index 0000000..04e853f --- /dev/null +++ b/.env-dist @@ -0,0 +1,26 @@ +# Основные параметры +YII_DEBUG=true +YII_ENV=dev +JWT_USER_SECRET= + +# Web +VIRTUAL_HOST=account.ely.by,authserver.ely.by +AUTHSERVER_HOST=authserver.ely.by +# LETSENCRYPT_HOST=account.ely.by +# LETSENCRYPT_EMAIL=erickskrauch@ely.by + +# MySQL +MYSQL_ALLOW_EMPTY_PASSWORD=yes +MYSQL_ROOT_PASSWORD= +MYSQL_DATABASE=ely_accounts +MYSQL_USER=ely_accounts_user +MYSQL_PASSWORD=ely_accounts_password + +# RabbitMQ +RABBITMQ_DEFAULT_USER=ely-accounts-app +RABBITMQ_DEFAULT_PASS=ely-accounts-app-password +RABBITMQ_DEFAULT_VHOST=/ely.by + +# Конфигурация для Dev. +XDEBUG_CONFIG=remote_host=10.254.254.254 +PHP_IDE_CONFIG=serverName=docker diff --git a/.gitignore b/.gitignore index a218a54..8ce4e28 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# yii console command -/yii - # phpstorm project files .idea @@ -19,8 +16,8 @@ Thumbs.db /vendor # composer itself is not needed -composer.phar -composer.lock +/composer.phar +/composer.lock # Mac DS_Store Files .DS_Store @@ -35,3 +32,6 @@ npm-debug* # Docker override file docker-compose.override.yml + +# Локальный .env +/.env diff --git a/api/config/.gitignore b/api/config/.gitignore index 20da318..e7d849d 100644 --- a/api/config/.gitignore +++ b/api/config/.gitignore @@ -1,2 +1 @@ main-local.php -params-local.php \ No newline at end of file diff --git a/api/config/main-dev.php b/api/config/main-dev.php new file mode 100644 index 0000000..b6f714e --- /dev/null +++ b/api/config/main-dev.php @@ -0,0 +1,19 @@ + ['debug', 'gii'], + 'components' => [ + 'reCaptcha' => [ + 'public' => '6LfwqCYTAAAAAJlaJpqCdzESCjAXUC81Ca6jBHR7', + 'secret' => '6LfwqCYTAAAAAFPjHmgwmnjSMFeAOJh7Lk5xxDMC', + ], + ], + 'modules' => [ + 'debug' => [ + 'class' => yii\debug\Module::class, + 'allowedIPs' => ['*'], + ], + 'gii' => [ + 'class' => yii\gii\Module::class, + ], + ], +]; diff --git a/api/config/main.php b/api/config/main.php index ef82de5..ae816f3 100644 --- a/api/config/main.php +++ b/api/config/main.php @@ -1,9 +1,7 @@ $params, 'components' => [ 'user' => [ - 'class' => \api\components\User\Component::class, - 'secret' => $params['userSecret'], + 'class' => api\components\User\Component::class, + 'secret' => getenv('JWT_USER_SECRET'), ], 'apiUser' => [ - 'class' => \api\components\ApiUser\Component::class, + 'class' => api\components\ApiUser\Component::class, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ - 'class' => \yii\log\FileTarget::class, + 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'warning'], 'except' => [ 'legacy-authserver', @@ -34,13 +32,13 @@ return [ ], ], [ - 'class' => \yii\log\FileTarget::class, + 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'info'], 'categories' => ['legacy-authserver'], 'logFile' => '@runtime/logs/authserver.log', ], [ - 'class' => \yii\log\FileTarget::class, + 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'info'], 'categories' => ['session'], 'logFile' => '@runtime/logs/session.log', @@ -56,26 +54,26 @@ return [ 'rules' => require __DIR__ . '/routes.php', ], 'reCaptcha' => [ - 'class' => \api\components\ReCaptcha\Component::class, + 'class' => api\components\ReCaptcha\Component::class, ], 'response' => [ - 'format' => \yii\web\Response::FORMAT_JSON, + 'format' => yii\web\Response::FORMAT_JSON, ], 'oauth' => [ - 'class' => \common\components\oauth\Component::class, + 'class' => common\components\oauth\Component::class, 'grantTypes' => ['authorization_code'], ], 'errorHandler' => [ - 'class' => \api\components\ErrorHandler::class, + 'class' => api\components\ErrorHandler::class, ], ], 'modules' => [ 'authserver' => [ - 'class' => \api\modules\authserver\Module::class, - 'baseDomain' => $params['authserverDomain'], + 'class' => api\modules\authserver\Module::class, + 'baseDomain' => getenv('AUTHSERVER_HOST'), ], 'session' => [ - 'class' => \api\modules\session\Module::class, + 'class' => api\modules\session\Module::class, ], ], ]; diff --git a/api/config/params.php b/api/config/params.php index 7f754b9..d0b9c34 100644 --- a/api/config/params.php +++ b/api/config/params.php @@ -1,4 +1,3 @@ 'admin@example.com', ]; diff --git a/api/modules/session/controllers/SessionController.php b/api/modules/session/controllers/SessionController.php index 56475c4..f335fa2 100644 --- a/api/modules/session/controllers/SessionController.php +++ b/api/modules/session/controllers/SessionController.php @@ -25,6 +25,7 @@ class SessionController extends ApiController { $behaviors['rateLimiting'] = [ 'class' => RateLimiter::class, 'only' => ['has-joined', 'has-joined-legacy'], + 'authserverDomain' => getenv('AUTHSERVER_HOST'), ]; return $behaviors; diff --git a/api/modules/session/filters/RateLimiter.php b/api/modules/session/filters/RateLimiter.php index cc912b8..b5eb490 100644 --- a/api/modules/session/filters/RateLimiter.php +++ b/api/modules/session/filters/RateLimiter.php @@ -18,10 +18,6 @@ class RateLimiter extends \yii\filters\RateLimiter { public function init() { parent::init(); - if ($this->authserverDomain === null) { - $this->authserverDomain = Yii::$app->params['authserverDomain'] ?? null; - } - if ($this->authserverDomain === null) { throw new InvalidConfigException('authserverDomain param is required'); } @@ -45,6 +41,7 @@ class RateLimiter extends \yii\filters\RateLimiter { * @inheritdoc */ public function checkRateLimit($user, $request, $response, $action) { + // TODO: теперь в authserverDomain хранится hostname без schema, а getHostInfo() возвращает с http(s). if ($request->getHostInfo() === $this->authserverDomain) { return; } diff --git a/api/web/.gitignore b/api/web/.gitignore deleted file mode 100644 index 25c74e6..0000000 --- a/api/web/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/index.php -/index-test.php diff --git a/api/web/favicon.ico b/api/web/favicon.ico deleted file mode 100644 index 580ed732e86556ec57f3f3395a210246d679c076..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 318 zcmZQzU<5(|0RbS%!l1#(z#zuJz@P!d0zj+)#2|4HXaJKC0wf0lAEr2iX{M9K3=BR0 y!E90pK{x=K$Oz&POT#sS8N$ZKhC)h8ip0_|-T#43{vnSYgXBQCu@O54$pHYIza?e> diff --git a/api/web/index.php b/api/web/index.php new file mode 100644 index 0000000..e94ef6e --- /dev/null +++ b/api/web/index.php @@ -0,0 +1,16 @@ +run(); diff --git a/common/config/.gitignore b/common/config/.gitignore index 97c0f01..e7d849d 100644 --- a/common/config/.gitignore +++ b/common/config/.gitignore @@ -1,2 +1 @@ main-local.php -params-local.php diff --git a/common/config/config-loader.php b/common/config/config-loader.php new file mode 100644 index 0000000..906fee0 --- /dev/null +++ b/common/config/config-loader.php @@ -0,0 +1,43 @@ + [ + 'mailer' => [ + 'useFileTransport' => true, + ], + ], +]; diff --git a/common/config/main.php b/common/config/main.php index 6ef7bfe..3df1fbb 100644 --- a/common/config/main.php +++ b/common/config/main.php @@ -8,6 +8,9 @@ return [ ], 'db' => [ 'class' => yii\db\Connection::class, + 'dsn' => 'mysql:host=db;dbname=' . getenv('MYSQL_DATABASE'), + 'username' => getenv('MYSQL_USER'), + 'password' => getenv('MYSQL_PASSWORD'), 'charset' => 'utf8', ], 'mailer' => [ @@ -19,12 +22,21 @@ return [ ], 'redis' => [ 'class' => yii\redis\Connection::class, + 'hostname' => 'redis', + 'password' => null, + 'port' => 6379, + 'database' => 0, ], 'amqp' => [ - 'class' => \common\components\RabbitMQ\Component::class, + 'class' => common\components\RabbitMQ\Component::class, + 'host' => 'rabbitmq', + 'port' => 5672, + 'user' => getenv('RABBITMQ_DEFAULT_USER'), + 'password' => getenv('RABBITMQ_DEFAULT_PASS'), + 'vhost' => getenv('RABBITMQ_DEFAULT_VHOST'), ], 'guzzle' => [ - 'class' => \GuzzleHttp\Client::class, + 'class' => GuzzleHttp\Client::class, ], ], 'aliases' => [ diff --git a/common/config/params.php b/common/config/params.php index 4ec9ba6..525df3a 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -1,6 +1,5 @@ 'admin@example.com', - 'supportEmail' => 'support@example.com', - 'user.passwordResetTokenExpire' => 3600, + 'fromEmail' => 'account@ely.by', + 'supportEmail' => 'support@ely.by', ]; diff --git a/console/config/.gitignore b/console/config/.gitignore index 20da318..e7d849d 100644 --- a/console/config/.gitignore +++ b/console/config/.gitignore @@ -1,2 +1 @@ main-local.php -params-local.php \ No newline at end of file diff --git a/environments/dev/console/config/main-local.php b/console/config/main-dev.php similarity index 100% rename from environments/dev/console/config/main-local.php rename to console/config/main-dev.php diff --git a/console/config/main.php b/console/config/main.php index f6cdd06..f7c04cf 100644 --- a/console/config/main.php +++ b/console/config/main.php @@ -1,21 +1,20 @@ 'app-console', + 'id' => 'accounts-console', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'console\controllers', + 'params' => $params, 'components' => [ 'log' => [ 'targets' => [ [ - 'class' => 'yii\log\FileTarget', + 'class' => yii\log\FileTarget::class, 'levels' => ['error', 'warning'], ], ], @@ -23,9 +22,8 @@ return [ ], 'controllerMap' => [ 'migrate' => [ - 'class' => 'yii\console\controllers\MigrateController', + 'class' => yii\console\controllers\MigrateController::class, 'templateFile' => '@console/views/migration.php', ], ], - 'params' => $params, ]; diff --git a/console/config/params.php b/console/config/params.php index 7f754b9..d0b9c34 100644 --- a/console/config/params.php +++ b/console/config/params.php @@ -1,4 +1,3 @@ 'admin@example.com', ]; diff --git a/docker-compose.yml b/docker-compose.yml index 530402d..991b9bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,29 +2,21 @@ version: '2' services: app: build: . - links: + depends_on: - db - redis - rabbitmq - depends_on: - - app-console-account-queue volumes: - ./:/var/www/html/ env_file: .env - networks: - - default - - nginx-proxy web: build: ./docker/nginx - links: - - app volumes_from: - app - environment: - - AUTHSERVER_HOST=authserver.ely.by.local - - PHP_LINK=app - - VIRTUAL_HOST=account.ely.by.local,authserver.ely.by.local + links: + - app:php + env_file: .env networks: - default - nginx-proxy @@ -42,7 +34,7 @@ services: build: . volumes: - ./:/var/www/html/ - command: ["./docker/wait-for-it.sh", "rabbitmq:5672", "--", "./yii account-queue"] + command: ["docker/wait-for-it.sh", "rabbitmq:5672", "--", "php", "yii", "account-queue"] links: - db - redis @@ -50,22 +42,14 @@ services: db: build: ./docker/mariadb - environment: - MYSQL_ROOT_PASSWORD: "" - MYSQL_ALLOW_EMPTY_PASSWORD: "yes" - MYSQL_DATABASE: "ely_accounts" - MYSQL_USER: "ely_accounts_user" - MYSQL_PASSWORD: "ely_accounts_password" + env_file: .env redis: image: redis:3.0 rabbitmq: build: ./docker/rabbitmq - environment: - RABBITMQ_DEFAULT_USER: "ely-accounts-app" - RABBITMQ_DEFAULT_PASS: "ely-accounts-app-password" - RABBITMQ_DEFAULT_VHOST: "/ely.by" + env_file: .env ports: - "15672:15672" # Manager interface @@ -77,7 +61,7 @@ services: - PMA_PASSWORD= ports: - "8181:80" - links: + depends_on: - db networks: diff --git a/docker/nginx/account.ely.by.conf.template b/docker/nginx/account.ely.by.conf.template index 67410fd..3670e88 100644 --- a/docker/nginx/account.ely.by.conf.template +++ b/docker/nginx/account.ely.by.conf.template @@ -34,7 +34,7 @@ server { } location ~* \.php$ { - fastcgi_pass ${PHP_LINK}:9000; + fastcgi_pass php:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SERVER_NAME $host; diff --git a/docker/nginx/run.sh b/docker/nginx/run.sh index a4d80cf..2c2bfa8 100644 --- a/docker/nginx/run.sh +++ b/docker/nginx/run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -envsubst '$AUTHSERVER_HOST:$PHP_LINK' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf +envsubst '$AUTHSERVER_HOST' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf exec "$@" diff --git a/environments/dev/api/config/main-local.php b/environments/dev/api/config/main-local.php deleted file mode 100644 index 70b921d..0000000 --- a/environments/dev/api/config/main-local.php +++ /dev/null @@ -1,26 +0,0 @@ - [ - 'request' => [ - // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation - 'cookieValidationKey' => '', - 'enableCsrfValidation' => false, - ], - 'reCaptcha' => [ - 'public' => '', - 'secret' => '', - ], - ], -]; - -if (!YII_ENV_TEST) { - // configuration adjustments for 'dev' environment - $config['bootstrap'][] = 'debug'; - $config['modules']['debug'] = 'yii\debug\Module'; - - $config['bootstrap'][] = 'gii'; - $config['modules']['gii'] = 'yii\gii\Module'; -} - -return $config; diff --git a/environments/dev/api/config/params-local.php b/environments/dev/api/config/params-local.php deleted file mode 100644 index 597a2dc..0000000 --- a/environments/dev/api/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'some-long-secret-key', - 'authserverDomain' => 'http://authserver.ely.by.local', -]; diff --git a/environments/dev/api/web/index-test.php b/environments/dev/api/web/index-test.php deleted file mode 100644 index 1a1d417..0000000 --- a/environments/dev/api/web/index-test.php +++ /dev/null @@ -1,18 +0,0 @@ -run(); diff --git a/environments/dev/api/web/index.php b/environments/dev/api/web/index.php deleted file mode 100644 index 6038167..0000000 --- a/environments/dev/api/web/index.php +++ /dev/null @@ -1,18 +0,0 @@ -run(); diff --git a/environments/dev/common/config/main-local.php b/environments/dev/common/config/main-local.php deleted file mode 100644 index c33945a..0000000 --- a/environments/dev/common/config/main-local.php +++ /dev/null @@ -1,29 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=ely_accounts', - 'username' => 'root', - 'password' => '', - ], - 'mailer' => [ - // send all mails to a file by default. You have to set - // 'useFileTransport' to false and configure a transport - // for the mailer to send real emails. - 'useFileTransport' => true, - ], - 'redis' => [ - 'hostname' => 'localhost', - 'password' => null, - 'port' => 6379, - 'database' => 0, - ], - 'amqp' => [ - 'host' => 'localhost', - 'port' => 5672, - 'user' => 'ely-accounts-app', - 'password' => 'app-password', - 'vhost' => '/account.ely.by', - ], - ], -]; diff --git a/environments/dev/common/config/params-local.php b/environments/dev/common/config/params-local.php deleted file mode 100644 index 525df3a..0000000 --- a/environments/dev/common/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'account@ely.by', - 'supportEmail' => 'support@ely.by', -]; diff --git a/environments/dev/console/config/params-local.php b/environments/dev/console/config/params-local.php deleted file mode 100644 index d0b9c34..0000000 --- a/environments/dev/console/config/params-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); -exit($exitCode); diff --git a/environments/docker/.env b/environments/docker/.env deleted file mode 100644 index 3a6845c..0000000 --- a/environments/docker/.env +++ /dev/null @@ -1,2 +0,0 @@ -XDEBUG_CONFIG=remote_host=192.168.99.1 -PHP_IDE_CONFIG=serverName=docker diff --git a/environments/docker/api/config/main-local.php b/environments/docker/api/config/main-local.php deleted file mode 100644 index 05a72f3..0000000 --- a/environments/docker/api/config/main-local.php +++ /dev/null @@ -1,25 +0,0 @@ - [ - 'request' => [ - // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation - 'cookieValidationKey' => '', - ], - 'reCaptcha' => [ - 'public' => '', - 'secret' => '', - ], - ], -]; - -if (!YII_ENV_TEST) { - // configuration adjustments for 'dev' environment - $config['bootstrap'][] = 'debug'; - $config['modules']['debug'] = \yii\debug\Module::class; - - $config['bootstrap'][] = 'gii'; - $config['modules']['gii'] = \yii\gii\Module::class; -} - -return $config; diff --git a/environments/docker/api/config/params-local.php b/environments/docker/api/config/params-local.php deleted file mode 100644 index 4c73d0d..0000000 --- a/environments/docker/api/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'some-long-secret-key', - 'authserverDomain' => 'https://authserver.ely.by', -]; diff --git a/environments/docker/api/web/index-test.php b/environments/docker/api/web/index-test.php deleted file mode 100644 index 1a1d417..0000000 --- a/environments/docker/api/web/index-test.php +++ /dev/null @@ -1,18 +0,0 @@ -run(); diff --git a/environments/docker/api/web/index.php b/environments/docker/api/web/index.php deleted file mode 100644 index 6038167..0000000 --- a/environments/docker/api/web/index.php +++ /dev/null @@ -1,18 +0,0 @@ -run(); diff --git a/environments/docker/common/config/main-local.php b/environments/docker/common/config/main-local.php deleted file mode 100644 index e94510d..0000000 --- a/environments/docker/common/config/main-local.php +++ /dev/null @@ -1,26 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=db;dbname=ely_accounts', - 'username' => 'ely_accounts_user', - 'password' => 'ely_accounts_password', - ], - 'mailer' => [ - 'useFileTransport' => true, - ], - 'redis' => [ - 'hostname' => 'redis', - 'password' => null, - 'port' => 6379, - 'database' => 0, - ], - 'amqp' => [ - 'host' => 'rabbitmq', - 'port' => 5672, - 'user' => 'ely-accounts-app', - 'password' => 'ely-accounts-app-password', - 'vhost' => '/ely.by', - ], - ], -]; diff --git a/environments/docker/common/config/params-local.php b/environments/docker/common/config/params-local.php deleted file mode 100644 index 525df3a..0000000 --- a/environments/docker/common/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'account@ely.by', - 'supportEmail' => 'support@ely.by', -]; diff --git a/environments/docker/console/config/main-local.php b/environments/docker/console/config/main-local.php deleted file mode 100644 index 96bd118..0000000 --- a/environments/docker/console/config/main-local.php +++ /dev/null @@ -1,7 +0,0 @@ - ['gii'], - 'modules' => [ - 'gii' => \yii\gii\Module::class, - ], -]; diff --git a/environments/docker/console/config/params-local.php b/environments/docker/console/config/params-local.php deleted file mode 100644 index d0b9c34..0000000 --- a/environments/docker/console/config/params-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); -exit($exitCode); diff --git a/environments/index.php b/environments/index.php deleted file mode 100644 index fc854f2..0000000 --- a/environments/index.php +++ /dev/null @@ -1,73 +0,0 @@ - [ - * 'path' => 'directory storing the local files', - * 'skipFiles' => [ - * // list of files that should only copied once and skipped if they already exist - * ], - * 'setWritable' => [ - * // list of directories that should be set writable - * ], - * 'setExecutable' => [ - * // list of files that should be set executable - * ], - * 'setCookieValidationKey' => [ - * // list of config files that need to be inserted with automatically generated cookie validation keys - * ], - * 'createSymlink' => [ - * // list of symlinks to be created. Keys are symlinks, and values are the targets. - * ], - * ], - * ]; - * ``` - */ -return [ - 'Development' => [ - 'path' => 'dev', - 'setWritable' => [ - 'api/runtime', - 'api/web/assets', - ], - 'setExecutable' => [ - 'yii', - 'tests/codeception/bin/yii', - ], - 'setCookieValidationKey' => [ - 'api/config/main-local.php', - ], - ], - 'Docker' => [ - 'path' => 'docker', - 'setWritable' => [ - 'api/runtime', - 'api/web/assets', - ], - 'setExecutable' => [ - 'yii', - 'tests/codeception/bin/yii', - ], - 'setCookieValidationKey' => [ - 'api/config/main-local.php', - ], - ], - 'Production' => [ - 'path' => 'prod', - 'setWritable' => [ - 'api/runtime', - 'api/web/assets', - ], - 'setExecutable' => [ - 'yii', - ], - 'setCookieValidationKey' => [ - 'api/config/main-local.php', - ], - ], -]; diff --git a/environments/prod/api/config/main-local.php b/environments/prod/api/config/main-local.php deleted file mode 100644 index 19e08c8..0000000 --- a/environments/prod/api/config/main-local.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'request' => [ - // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation - 'cookieValidationKey' => '', - ], - 'reCaptcha' => [ - 'public' => '', - 'secret' => '', - ], - ], -]; diff --git a/environments/prod/api/config/params-local.php b/environments/prod/api/config/params-local.php deleted file mode 100644 index 4c73d0d..0000000 --- a/environments/prod/api/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'some-long-secret-key', - 'authserverDomain' => 'https://authserver.ely.by', -]; diff --git a/environments/prod/api/web/index.php b/environments/prod/api/web/index.php deleted file mode 100644 index 674803a..0000000 --- a/environments/prod/api/web/index.php +++ /dev/null @@ -1,18 +0,0 @@ -run(); diff --git a/environments/prod/common/config/main-local.php b/environments/prod/common/config/main-local.php deleted file mode 100644 index 22dca7c..0000000 --- a/environments/prod/common/config/main-local.php +++ /dev/null @@ -1,23 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=ely_accounts', - 'username' => 'root', - 'password' => '', - ], - 'redis' => [ - 'hostname' => 'localhost', - 'password' => null, - 'port' => 6379, - 'database' => 0, - ], - 'amqp' => [ - 'host' => 'localhost', - 'port' => 5672, - 'user' => 'ely-accounts-app', - 'password' => 'app-password', - 'vhost' => '/account.ely.by', - ], - ], -]; diff --git a/environments/prod/common/config/params-local.php b/environments/prod/common/config/params-local.php deleted file mode 100644 index 525df3a..0000000 --- a/environments/prod/common/config/params-local.php +++ /dev/null @@ -1,5 +0,0 @@ - 'account@ely.by', - 'supportEmail' => 'support@ely.by', -]; diff --git a/environments/prod/console/config/main-local.php b/environments/prod/console/config/main-local.php deleted file mode 100644 index d0b9c34..0000000 --- a/environments/prod/console/config/main-local.php +++ /dev/null @@ -1,3 +0,0 @@ -run(); -exit($exitCode); diff --git a/init b/init deleted file mode 100644 index 1b35927..0000000 --- a/init +++ /dev/null @@ -1,209 +0,0 @@ -#!/usr/bin/env php - - * - * @link http://www.yiiframework.com/ - * @copyright Copyright (c) 2008 Yii Software LLC - * @license http://www.yiiframework.com/license/ - */ - -if (!extension_loaded('openssl')) { - die('The OpenSSL PHP extension is required by Yii2.'); -} - -$params = getParams(); -$root = str_replace('\\', '/', __DIR__); -$envs = require("$root/environments/index.php"); -$envNames = array_keys($envs); - -echo "Yii Application Initialization Tool v1.0\n\n"; - -$envName = null; -if (empty($params['env']) || $params['env'] === '1') { - echo "Which environment do you want the application to be initialized in?\n\n"; - foreach ($envNames as $i => $name) { - echo " [$i] $name\n"; - } - echo "\n Your choice [0-" . (count($envs) - 1) . ', or "q" to quit] '; - $answer = trim(fgets(STDIN)); - - if (!ctype_digit($answer) || !in_array($answer, range(0, count($envs) - 1))) { - echo "\n Quit initialization.\n"; - exit(0); - } - - if (isset($envNames[$answer])) { - $envName = $envNames[$answer]; - } -} else { - $envName = $params['env']; -} - -if (!in_array($envName, $envNames)) { - $envsList = implode(', ', $envNames); - echo "\n $envName is not a valid environment. Try one of the following: $envsList. \n"; - exit(2); -} - -$env = $envs[$envName]; - -if (empty($params['env'])) { - echo "\n Initialize the application under '{$envNames[$answer]}' environment? [yes|no] "; - $answer = trim(fgets(STDIN)); - if (strncasecmp($answer, 'y', 1)) { - echo "\n Quit initialization.\n"; - exit(0); - } -} - -echo "\n Start initialization ...\n\n"; -$files = getFileList("$root/environments/{$env['path']}"); -if (isset($env['skipFiles'])) { - $skipFiles = $env['skipFiles']; - array_walk($skipFiles, function(&$value) use($env, $root) { $value = "$root/$value"; }); - $files = array_diff($files, array_intersect_key($env['skipFiles'], array_filter($skipFiles, 'file_exists'))); -} -$all = false; -foreach ($files as $file) { - if (!copyFile($root, "environments/{$env['path']}/$file", $file, $all, $params)) { - break; - } -} - -$callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable', 'createSymlink']; -foreach ($callbacks as $callback) { - if (!empty($env[$callback])) { - $callback($root, $env[$callback]); - } -} - -echo "\n ... initialization completed.\n\n"; - -function getFileList($root, $basePath = '') -{ - $files = []; - $handle = opendir($root); - while (($path = readdir($handle)) !== false) { - if ($path === '.git' || $path === '.svn' || $path === '.' || $path === '..') { - continue; - } - $fullPath = "$root/$path"; - $relativePath = $basePath === '' ? $path : "$basePath/$path"; - if (is_dir($fullPath)) { - $files = array_merge($files, getFileList($fullPath, $relativePath)); - } else { - $files[] = $relativePath; - } - } - closedir($handle); - return $files; -} - -function copyFile($root, $source, $target, &$all, $params) -{ - if (!is_file($root . '/' . $source)) { - echo " skip $target ($source not exist)\n"; - return true; - } - if (is_file($root . '/' . $target)) { - if (file_get_contents($root . '/' . $source) === file_get_contents($root . '/' . $target)) { - echo " unchanged $target\n"; - return true; - } - if ($all) { - echo " overwrite $target\n"; - } else { - echo " exist $target\n"; - echo " ...overwrite? [Yes|No|All|Quit] "; - - - $answer = !empty($params['overwrite']) ? $params['overwrite'] : trim(fgets(STDIN)); - if (!strncasecmp($answer, 'q', 1)) { - return false; - } else { - if (!strncasecmp($answer, 'y', 1)) { - echo " overwrite $target\n"; - } else { - if (!strncasecmp($answer, 'a', 1)) { - echo " overwrite $target\n"; - $all = true; - } else { - echo " skip $target\n"; - return true; - } - } - } - } - file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); - return true; - } - echo " generate $target\n"; - @mkdir(dirname($root . '/' . $target), 0777, true); - file_put_contents($root . '/' . $target, file_get_contents($root . '/' . $source)); - return true; -} - -function getParams() -{ - $rawParams = []; - if (isset($_SERVER['argv'])) { - $rawParams = $_SERVER['argv']; - array_shift($rawParams); - } - - $params = []; - foreach ($rawParams as $param) { - if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) { - $name = $matches[1]; - $params[$name] = isset($matches[3]) ? $matches[3] : true; - } else { - $params[] = $param; - } - } - return $params; -} - -function setWritable($root, $paths) -{ - foreach ($paths as $writable) { - echo " chmod 0777 $writable\n"; - @chmod("$root/$writable", 0777); - } -} - -function setExecutable($root, $paths) -{ - foreach ($paths as $executable) { - echo " chmod 0755 $executable\n"; - @chmod("$root/$executable", 0755); - } -} - -function setCookieValidationKey($root, $paths) -{ - foreach ($paths as $file) { - echo " generate cookie validation key in $file\n"; - $file = $root . '/' . $file; - $length = 32; - $bytes = openssl_random_pseudo_bytes($length); - $key = strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.'); - $content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($file)); - file_put_contents($file, $content); - } -} - -function createSymlink($root, $links) { - foreach ($links as $link => $target) { - echo " symlink " . $root . "/" . $target . " " . $root . "/" . $link . "\n"; - //first removing folders to avoid errors if the folder already exists - @rmdir($root . "/" . $link); - @symlink($root . "/" . $target, $root . "/" . $link); - } -} diff --git a/init.bat b/init.bat deleted file mode 100644 index e50c242..0000000 --- a/init.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line init script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright (c) 2008 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%init" %* - -@endlocal diff --git a/yii b/yii new file mode 100755 index 0000000..335e8c1 --- /dev/null +++ b/yii @@ -0,0 +1,18 @@ +#!/usr/bin/env php +run(); +exit($exitCode); diff --git a/yii.bat b/yii.bat deleted file mode 100644 index d516b3a..0000000 --- a/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright (c) 2008 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal From df6d319187a008579299ee6a38f0c05ef718233b Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 19 Sep 2016 01:01:19 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=92=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81?= =?UTF-8?q?=D0=BA=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=20=D0=97=D0=B0?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=B7=D1=87=D0=B8=D0=BA=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=84=D0=B8=D0=B3=D0=BE=D0=B2=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20authserve?= =?UTF-8?q?rHost=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=20params=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20common.unit=20=D1=82=D0=B5=D1=81=D1=82=D1=8B,=20?= =?UTF-8?q?=D1=82.=D0=BA.=20=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B8=D1=81=D1=8C=20=D0=BD=D0=B5=20=D0=BE?= =?UTF-8?q?=D1=82=20=D1=82=D0=BE=D0=B3=D0=BE=20=D0=B1=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/config/{main-dev.php => config-dev.php} | 0 api/config/{main.php => config.php} | 0 api/config/params.php | 1 + .../session/controllers/SessionController.php | 2 +- api/modules/session/filters/RateLimiter.php | 3 +- api/web/index.php | 4 +- common/config/.gitignore | 2 +- common/config/ConfigLoader.php | 65 +++++++++++++++++++ .../config/{main-dev.php => config-dev.php} | 0 common/config/config-loader.php | 43 ------------ common/config/{main.php => config.php} | 0 .../config/{main-dev.php => config-dev.php} | 0 console/config/{main.php => config.php} | 0 tests/codeception/api/_bootstrap.php | 26 ++++---- tests/codeception/api/codeception.yml | 6 +- .../codeception/api/functional/_bootstrap.php | 3 +- .../authentication/RegistrationFormTest.php | 6 ++ .../RepeatAccountActivationFormTest.php | 6 ++ .../session/filters/RateLimiterTest.php | 8 ++- tests/codeception/bin/_bootstrap.php | 19 ++---- tests/codeception/bin/yii | 15 +---- tests/codeception/bin/yii.bat | 20 ------ tests/codeception/common/_bootstrap.php | 11 ++-- .../behaviors/PrimaryKeyValueBehaviorTest.php | 2 +- .../unit/models/EmailActivationTest.php | 2 +- tests/codeception/config/api/config.php | 2 +- tests/codeception/config/api/functional.php | 15 ++--- tests/codeception/config/api/unit.php | 16 ++--- tests/codeception/config/common/unit.php | 10 +-- tests/codeception/config/config.php | 2 +- tests/codeception/config/console/unit.php | 14 +--- tests/codeception/config/functional.php | 12 +--- tests/codeception/config/unit.php | 5 +- tests/codeception/console/_bootstrap.php | 13 ++-- yii | 4 +- 35 files changed, 147 insertions(+), 190 deletions(-) rename api/config/{main-dev.php => config-dev.php} (100%) rename api/config/{main.php => config.php} (100%) create mode 100644 common/config/ConfigLoader.php rename common/config/{main-dev.php => config-dev.php} (100%) delete mode 100644 common/config/config-loader.php rename common/config/{main.php => config.php} (100%) rename console/config/{main-dev.php => config-dev.php} (100%) rename console/config/{main.php => config.php} (100%) delete mode 100644 tests/codeception/bin/yii.bat diff --git a/api/config/main-dev.php b/api/config/config-dev.php similarity index 100% rename from api/config/main-dev.php rename to api/config/config-dev.php diff --git a/api/config/main.php b/api/config/config.php similarity index 100% rename from api/config/main.php rename to api/config/config.php diff --git a/api/config/params.php b/api/config/params.php index d0b9c34..5412ed8 100644 --- a/api/config/params.php +++ b/api/config/params.php @@ -1,3 +1,4 @@ getenv('AUTHSERVER_HOST'), ]; diff --git a/api/modules/session/controllers/SessionController.php b/api/modules/session/controllers/SessionController.php index f335fa2..f120ba8 100644 --- a/api/modules/session/controllers/SessionController.php +++ b/api/modules/session/controllers/SessionController.php @@ -25,7 +25,7 @@ class SessionController extends ApiController { $behaviors['rateLimiting'] = [ 'class' => RateLimiter::class, 'only' => ['has-joined', 'has-joined-legacy'], - 'authserverDomain' => getenv('AUTHSERVER_HOST'), + 'authserverDomain' => Yii::$app->params['authserverHost'], ]; return $behaviors; diff --git a/api/modules/session/filters/RateLimiter.php b/api/modules/session/filters/RateLimiter.php index b5eb490..71cbf65 100644 --- a/api/modules/session/filters/RateLimiter.php +++ b/api/modules/session/filters/RateLimiter.php @@ -41,8 +41,7 @@ class RateLimiter extends \yii\filters\RateLimiter { * @inheritdoc */ public function checkRateLimit($user, $request, $response, $action) { - // TODO: теперь в authserverDomain хранится hostname без schema, а getHostInfo() возвращает с http(s). - if ($request->getHostInfo() === $this->authserverDomain) { + if (parse_url($request->getHostInfo(), PHP_URL_HOST) === $this->authserverDomain) { return; } diff --git a/api/web/index.php b/api/web/index.php index e94ef6e..38ed822 100644 --- a/api/web/index.php +++ b/api/web/index.php @@ -3,14 +3,12 @@ require __DIR__ . '/../../vendor/autoload.php'; defined('YII_DEBUG') or define('YII_DEBUG', (boolean)getenv('YII_DEBUG')); defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV')); -defined('YII_APPLICATION_TYPE') or define('YII_APPLICATION_TYPE', 'web'); -defined('YII_APPLICATION_MODULE') or define('YII_APPLICATION_MODULE', 'api'); require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'; require __DIR__ . '/../../common/config/bootstrap.php'; require __DIR__ . '/../config/bootstrap.php'; -$config = require __DIR__ . './../../common/config/config-loader.php'; +$config = \common\config\ConfigLoader::load('api'); $application = new yii\web\Application($config); $application->run(); diff --git a/common/config/.gitignore b/common/config/.gitignore index e7d849d..059a02c 100644 --- a/common/config/.gitignore +++ b/common/config/.gitignore @@ -1 +1 @@ -main-local.php +config-local.php diff --git a/common/config/ConfigLoader.php b/common/config/ConfigLoader.php new file mode 100644 index 0000000..c94c4e1 --- /dev/null +++ b/common/config/ConfigLoader.php @@ -0,0 +1,65 @@ +application = $application; + } + + public function getEnvironment() : string { + return YII_ENV; + } + + public function getConfig() : array { + $toMerge = [ + require __DIR__ . '/config.php', + ]; + + // Общие окружение-зависимые настройки + $path = __DIR__ . '/config-' . YII_ENV . '.php'; + if (file_exists($path)) { + $toMerge[] = require $path; + } + + // Общие локальные настройки + $path = __DIR__ . '/config-local.php'; + if (file_exists($path)) { + $toMerge[] = require $path; + } + + // Настройки конкретного приложения + $path = self::ROOT_PATH . '/' . $this->application . '/config/config.php'; + if (file_exists($path)) { + $toMerge[] = require $path; + } + + // Настройки конкретного приложения для действующего окружения + $path = self::ROOT_PATH . '/' . $this->application . '/config/main-' . YII_ENV . '.php'; + if (file_exists($path)) { + $toMerge[] = require $path; + } + + // Локальные настройки конкретного приложения + $path = self::ROOT_PATH . '/' . $this->application . '/config/config-local.php'; + if (file_exists($path)) { + $toMerge[] = require $path; + } + + return ArrayHelper::merge(...$toMerge); + } + + public static function load(string $application) : array { + return (new static($application))->getConfig(); + } + +} diff --git a/common/config/main-dev.php b/common/config/config-dev.php similarity index 100% rename from common/config/main-dev.php rename to common/config/config-dev.php diff --git a/common/config/config-loader.php b/common/config/config-loader.php deleted file mode 100644 index 906fee0..0000000 --- a/common/config/config-loader.php +++ /dev/null @@ -1,43 +0,0 @@ -mockRequest(); + Yii::$container->set(Validator::class, new class extends Validator { + public function validateValue($value) { + return null; + } + }); } protected function tearDown() { diff --git a/tests/codeception/api/unit/models/authentication/RepeatAccountActivationFormTest.php b/tests/codeception/api/unit/models/authentication/RepeatAccountActivationFormTest.php index 8bcf51f..e132ace 100644 --- a/tests/codeception/api/unit/models/authentication/RepeatAccountActivationFormTest.php +++ b/tests/codeception/api/unit/models/authentication/RepeatAccountActivationFormTest.php @@ -1,6 +1,7 @@ fileTransportCallback = function () { return 'testing_message.eml'; }; + Yii::$container->set(Validator::class, new class extends Validator { + public function validateValue($value) { + return null; + } + }); } protected function tearDown() { diff --git a/tests/codeception/api/unit/modules/session/filters/RateLimiterTest.php b/tests/codeception/api/unit/modules/session/filters/RateLimiterTest.php index e99a699..a0c3710 100644 --- a/tests/codeception/api/unit/modules/session/filters/RateLimiterTest.php +++ b/tests/codeception/api/unit/modules/session/filters/RateLimiterTest.php @@ -24,6 +24,9 @@ class RateLimiterTest extends TestCase { /** @var RateLimiter|\PHPUnit_Framework_MockObject_MockObject $filter */ $filter = $this->getMockBuilder(RateLimiter::class) + ->setConstructorArgs([[ + 'authserverDomain' => Yii::$app->params['authserverHost'] + ]]) ->setMethods(['getServer']) ->getMock(); @@ -54,7 +57,9 @@ class RateLimiterTest extends TestCase { ->method('getHostInfo') ->will($this->returnValue('http://authserver.ely.by')); - $filter = new RateLimiter(); + $filter = new RateLimiter([ + 'authserverDomain' => Yii::$app->params['authserverHost'] + ]); $filter->checkRateLimit(null, $request, null, null); } @@ -86,6 +91,7 @@ class RateLimiterTest extends TestCase { $filter = $this->getMockBuilder(RateLimiter::class) ->setConstructorArgs([[ 'limit' => 3, + 'authserverDomain' => Yii::$app->params['authserverHost'], ]]) ->setMethods(['getServer']) ->getMock(); diff --git a/tests/codeception/bin/_bootstrap.php b/tests/codeception/bin/_bootstrap.php index f1fbb72..8b78584 100644 --- a/tests/codeception/bin/_bootstrap.php +++ b/tests/codeception/bin/_bootstrap.php @@ -1,19 +1,10 @@ -rem @link http://www.yiiframework.com/ -rem @copyright Copyright (c) 2008 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/tests/codeception/common/_bootstrap.php b/tests/codeception/common/_bootstrap.php index eee8f45..577fef2 100644 --- a/tests/codeception/common/_bootstrap.php +++ b/tests/codeception/common/_bootstrap.php @@ -1,12 +1,11 @@ [ - 'authserverDomain' => 'http://authserver.ely.by', + 'authserverHost' => 'authserver.ely.by', ], ]; diff --git a/tests/codeception/config/api/functional.php b/tests/codeception/config/api/functional.php index 8d2efde..d515572 100644 --- a/tests/codeception/config/api/functional.php +++ b/tests/codeception/config/api/functional.php @@ -2,16 +2,9 @@ $_SERVER['SCRIPT_FILENAME'] = API_ENTRY_FILE; $_SERVER['SCRIPT_NAME'] = API_ENTRY_URL; -/** - * Application configuration for api functional tests - */ return yii\helpers\ArrayHelper::merge( - require(YII_APP_BASE_PATH . '/common/config/main.php'), - require(YII_APP_BASE_PATH . '/common/config/main-local.php'), require(YII_APP_BASE_PATH . '/api/config/main.php'), - require(YII_APP_BASE_PATH . '/api/config/main-local.php'), - require(dirname(__DIR__) . '/config.php'), - require(dirname(__DIR__) . '/functional.php'), - require(__DIR__ . '/config.php'), - [ - ] + \common\config\ConfigLoader::load('api'), + require __DIR__ . '/../config.php', + require __DIR__ . '/../functional.php', + require __DIR__ . '/config.php' ); diff --git a/tests/codeception/config/api/unit.php b/tests/codeception/config/api/unit.php index 5bdca09..2e2ab12 100644 --- a/tests/codeception/config/api/unit.php +++ b/tests/codeception/config/api/unit.php @@ -1,15 +1,7 @@ 'app-common', 'basePath' => dirname(__DIR__), diff --git a/tests/codeception/config/config.php b/tests/codeception/config/config.php index 395f425..3fbe89e 100644 --- a/tests/codeception/config/config.php +++ b/tests/codeception/config/config.php @@ -3,7 +3,7 @@ return [ 'language' => 'en-US', 'controllerMap' => [ 'fixture' => [ - 'class' => 'yii\faker\FixtureController', + 'class' => yii\faker\FixtureController::class, 'fixtureDataPath' => '@tests/codeception/common/fixtures/data', 'templatePath' => '@tests/codeception/common/templates/fixtures', 'namespace' => 'tests\codeception\common\fixtures', diff --git a/tests/codeception/config/console/unit.php b/tests/codeception/config/console/unit.php index 4d3aeb0..b0ad993 100644 --- a/tests/codeception/config/console/unit.php +++ b/tests/codeception/config/console/unit.php @@ -1,14 +1,6 @@ [ 'request' => [ // it's not recommended to run functional tests with CSRF validation enabled + // TODO: у нас вроде и без того нет проверки csrf 'enableCsrfValidation' => false, + 'enableCookieValidation' => false, // but if you absolutely need it set cookie domain to localhost - /* - 'csrfCookie' => [ - 'domain' => 'localhost', - ], - */ ], ], -]; \ No newline at end of file +]; diff --git a/tests/codeception/config/unit.php b/tests/codeception/config/unit.php index 6bd08d3..bee73cf 100644 --- a/tests/codeception/config/unit.php +++ b/tests/codeception/config/unit.php @@ -1,7 +1,4 @@ run(); From 01b68afc193b396fcf7a809804cbc0fd60cf7a15 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 19 Sep 2016 01:16:07 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20authse?= =?UTF-8?q?rver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/codeception/config/api/config.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/codeception/config/api/config.php b/tests/codeception/config/api/config.php index 981cae2..ff84813 100644 --- a/tests/codeception/config/api/config.php +++ b/tests/codeception/config/api/config.php @@ -9,6 +9,11 @@ return [ 'secret' => 'private-key', ], ], + 'modules' => [ + 'authserver' => [ + 'baseDomain' => 'http://localhost', + ], + ], 'params' => [ 'authserverHost' => 'authserver.ely.by', ], From 264cb25ddc63d1c67cb7df24d4dd303ea3b9ca5a Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 19 Sep 2016 02:13:17 +0300 Subject: [PATCH 6/8] =?UTF-8?q?Upgrade=20Codeception=20=D0=B4=D0=BE=202.2?= =?UTF-8?q?=20(=D0=BF=D0=B0=D0=B4=D0=B0=D0=B5=D1=82=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=20=D0=B2=20AccountIdentity=20=D0=BF=D1=80=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D0=BE=D0=B2=D0=BE=D0=BC=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=D0=BD=D0=B5,=20=D1=82.=D0=BA.=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=BB=D1=81=D1=8F=20=D0=B4=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD,=20=D0=BF=D0=BE=D1=85=D0=BE=D0=B4=D1=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +++-- tests/codeception/api/_bootstrap.php | 3 +-- tests/codeception/bin/_bootstrap.php | 3 +-- tests/codeception/common/_bootstrap.php | 3 +-- tests/codeception/common/_support/FixtureHelper.php | 8 ++++---- tests/codeception/console/_bootstrap.php | 3 +-- 6 files changed, 11 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index e3f4eed..a9de380 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,11 @@ "yiisoft/yii2-gii": "*", "yiisoft/yii2-faker": "*", "flow/jsonpath": "^0.3.1", - "codeception/codeception": "~2.1.10", + "codeception/codeception": "~2.2.4", "codeception/specify": "*", "codeception/verify": "*", - "phploc/phploc": "^3.0.1" + "phploc/phploc": "^3.0.1", + "predis/predis": "^1.0" }, "config": { "process-timeout": 1800 diff --git a/tests/codeception/api/_bootstrap.php b/tests/codeception/api/_bootstrap.php index 9c2d2aa..03865c3 100644 --- a/tests/codeception/api/_bootstrap.php +++ b/tests/codeception/api/_bootstrap.php @@ -3,8 +3,7 @@ use Codeception\Configuration; use Codeception\Specify\Config; defined('YII_DEBUG') or define('YII_DEBUG', true); -defined('YII_ENV_TEST') or define('YII_ENV_TEST', true); -defined('YII_ENV') or define('YII_ENV', 'dev'); +defined('YII_ENV') or define('YII_ENV', 'test'); defined('API_ENTRY_URL') or define('API_ENTRY_URL', parse_url(Configuration::config()['config']['test_entry_url'], PHP_URL_PATH)); defined('API_ENTRY_FILE') or define('API_ENTRY_FILE', __DIR__ . '/../../../api/web/index.php'); diff --git a/tests/codeception/bin/_bootstrap.php b/tests/codeception/bin/_bootstrap.php index 8b78584..abbeded 100644 --- a/tests/codeception/bin/_bootstrap.php +++ b/tests/codeception/bin/_bootstrap.php @@ -1,7 +1,6 @@ loadFixtures(); } - public function _after(TestCase $test) { + public function _after(TestInterface $test) { $this->unloadFixtures(); } public function globalFixtures() { return [ - InitDbFixture::className(), + InitDbFixture::class, ]; } diff --git a/tests/codeception/console/_bootstrap.php b/tests/codeception/console/_bootstrap.php index 98f4993..97426fc 100644 --- a/tests/codeception/console/_bootstrap.php +++ b/tests/codeception/console/_bootstrap.php @@ -1,7 +1,6 @@ Date: Mon, 19 Sep 2016 11:18:52 +0300 Subject: [PATCH 7/8] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?AccountIdentity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/components/User/Component.php | 3 +-- tests/codeception/api/codeception.yml | 4 ++-- .../api/unit/models/AccountIdentityTest.php | 14 +++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/components/User/Component.php b/api/components/User/Component.php index 7407a55..336c083 100644 --- a/api/components/User/Component.php +++ b/api/components/User/Component.php @@ -7,7 +7,6 @@ use Emarref\Jwt\Algorithm\AlgorithmInterface; use Emarref\Jwt\Algorithm\Hs256; use Emarref\Jwt\Claim; use Emarref\Jwt\Encryption\Factory as EncryptionFactory; -use Emarref\Jwt\Encryption\Factory; use Emarref\Jwt\Exception\VerificationException; use Emarref\Jwt\Jwt; use Emarref\Jwt\Token; @@ -122,7 +121,7 @@ class Component extends YiiUserComponent { $jwt = new Jwt(); $token = $jwt->deserialize($jwtString); - $context = new VerificationContext(Factory::create($this->getAlgorithm())); + $context = new VerificationContext(EncryptionFactory::create($this->getAlgorithm())); $context->setAudience($hostInfo); $context->setIssuer($hostInfo); $jwt->verify($token, $context); diff --git a/tests/codeception/api/codeception.yml b/tests/codeception/api/codeception.yml index 68640dd..4318152 100644 --- a/tests/codeception/api/codeception.yml +++ b/tests/codeception/api/codeception.yml @@ -12,7 +12,7 @@ settings: memory_limit: 1024M log: true config: - test_entry_url: http://localhost:8080/api/web/index.php + test_entry_url: http://localhost/api/web/index.php coverage: enabled: true remote: true @@ -24,4 +24,4 @@ coverage: - ../../../api/mails/* - ../../../api/web/* - ../../../api/runtime/* - c3url: 'http://localhost:8080/api/web/index.php' + c3url: 'http://localhost/api/web/index.php' diff --git a/tests/codeception/api/unit/models/AccountIdentityTest.php b/tests/codeception/api/unit/models/AccountIdentityTest.php index ad542bc..b501604 100644 --- a/tests/codeception/api/unit/models/AccountIdentityTest.php +++ b/tests/codeception/api/unit/models/AccountIdentityTest.php @@ -3,6 +3,10 @@ namespace codeception\api\unit\models; use api\models\AccountIdentity; use Codeception\Specify; +use Emarref\Jwt\Claim; +use Emarref\Jwt\Encryption\Factory as EncryptionFactory; +use Emarref\Jwt\Jwt; +use Emarref\Jwt\Token; use tests\codeception\api\unit\DbTestCase; use tests\codeception\common\_support\ProtectedCaller; use tests\codeception\common\fixtures\AccountFixture; @@ -33,9 +37,13 @@ class AccountIdentityTest extends DbTestCase { * @expectedExceptionMessage Token expired */ public function testFindIdentityByAccessTokenWithExpiredToken() { - $expiredToken = 'eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImlzcyI6Imh0d' . - 'HA6XC9cL2xvY2FsaG9zdDo4MDgwIiwiaWF0IjoxNDY0NTkzMTkzLCJleHAiOjE0NjQ1OTY3OTN9.DV' . - '8uwh0OQhBYXkrNvxwJeO-kEjb9MQeLr3-6GoHM7RY'; + $token = new Token(); + $token->addClaim(new Claim\Audience('http://localhost')); + $token->addClaim(new Claim\Issuer('http://localhost')); + $token->addClaim(new Claim\IssuedAt(1464593193)); + $token->addClaim(new Claim\Expiration(1464596793)); + $token->addClaim(new Claim\JwtId($this->accounts['admin']['id'])); + $expiredToken = (new Jwt())->serialize($token, EncryptionFactory::create(Yii::$app->user->getAlgorithm())); AccountIdentity::findIdentityByAccessToken($expiredToken); } From 53ca5915f71cb27b67bb9d671025d9d87747042c Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Sun, 2 Oct 2016 01:20:40 +0300 Subject: [PATCH 8/8] =?UTF-8?q?=D0=A1=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=BD=D1=87=D0=B0=D1=82=D0=B5=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B7=D0=B0=D0=B3=D0=BD=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=20Docker=20=D0=94=D0=B5=D0=B3=D1=80=D0=B5=D0=B9=D0=B4=20?= =?UTF-8?q?PHP=20=D0=B4=D0=BE=207.0=20(=D0=B2=D1=81=D1=91=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B1=D0=B5=D0=B7=20xdebug=20=D0=BD=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=B1=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?)=20=D0=94=D0=B5=D0=B3=D1=80=D0=B5=D0=B9=D0=B4=20Node.js=20?= =?UTF-8?q?=D0=B4=D0=BE=205.12=20(=D0=BD=D0=B0=206.5=20=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0=D0=BB=D1=81=D1=8F=20=D1=84?= =?UTF-8?q?=D1=80=D0=BE=D0=BD=D1=82)=20=D0=A3=D0=BF=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=91=D0=BD=20app-console=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=20(=D0=BE=D0=BD=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B6=D0=B8=D0=B2=D1=91=D1=82?= =?UTF-8?q?=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=BE=D1=81=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BD=D0=BE=D0=B3=D0=BE=20php=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=D0=BD=D0=B5=D1=80=D0=B0=20=D0=B8=20=D1=80?= =?UTF-8?q?=D1=83=D0=BB=D0=B8=D1=82=D1=81=D1=8F=20=D1=81=D0=B8=D0=BB=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8=20supervisor)=20=D0=A3=D0=BF=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=B4=D0=BD=D1=91=D0=BD=20node-dev-server=20(=D0=B2=D1=81?= =?UTF-8?q?=D1=91=20=D1=80=D0=B0=D0=B2=D0=BD=D0=BE=20=D0=BE=D0=BD=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BF=D0=BB=D0=BE=D1=85?= =?UTF-8?q?=D0=BE)=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B1=D0=B0=D0=B3=D0=B0?= =?UTF-8?q?=20=D0=B2=20ConfigLoader=20(=D0=BD=D0=B5=20=D0=B7=D0=B0=D0=B3?= =?UTF-8?q?=D1=80=D1=83=D0=B6=D0=B0=D0=BB=20config-{env}=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D1=8B)=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B2=20LangMenu=20(=D0=B4=D0=B2=D0=BE=D0=B9=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20default=20=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82)?= =?UTF-8?q?=20=D0=98=D0=B7=20package.json=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D1=91=D0=BD=20Pha?= =?UTF-8?q?ntomJS=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=91=D0=BD=20REA?= =?UTF-8?q?DME.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 5 +- .gitignore | 29 ++---- Dockerfile | 137 +++++++++++++++++++--------- Dockerfile-dev | 162 +++++++++++++++++++++++++++++++++ README.md | 72 ++++++--------- common/config/ConfigLoader.php | 2 +- composer.json | 2 +- data/mysql/.gitignore | 2 + data/redis/.gitignore | 2 + docker-compose.dev.yml | 74 +++++++++++++++ docker-compose.prod.yml | 40 ++++++++ docker-compose.yml | 45 ++++----- docker/nginx/Dockerfile | 2 +- docker/nginx/run.sh | 2 +- docker/php/entrypoint.sh | 33 +++++++ docker/php/supervisord.conf | 36 ++++++++ docker/rabbitmq/Dockerfile | 8 -- tests/docker-compose.yml | 20 ++-- 18 files changed, 515 insertions(+), 158 deletions(-) create mode 100644 Dockerfile-dev create mode 100644 data/mysql/.gitignore create mode 100644 data/redis/.gitignore create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.prod.yml create mode 100644 docker/php/entrypoint.sh create mode 100644 docker/php/supervisord.conf delete mode 100644 docker/rabbitmq/Dockerfile diff --git a/.dockerignore b/.dockerignore index f95a9d8..3d38865 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,10 +3,9 @@ # vendor будет заполнен уже внутри контейнера vendor -# node_modules для этого контейнера не нужны +# Всё, что динамично на фронте frontend/node_modules -frontend/webpack/node_modules -frontend/scripts/node_modules +frontend/dist # Все временные файлы */runtime diff --git a/.gitignore b/.gitignore index 8ce4e28..441d98f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,37 +1,22 @@ # phpstorm project files .idea -# netbeans project files -nbproject - -# zend studio for eclipse project files -.buildpath -.project -.settings - -# windows thumbnail cache -Thumbs.db - -# composer vendor dir +# Composer /vendor - -# composer itself is not needed -/composer.phar /composer.lock # Mac DS_Store Files .DS_Store -# phpunit itself is not needed -phpunit.phar -# local phpunit config -/phpunit.xml - # npm debug npm-debug* -# Docker override file -docker-compose.override.yml +# Docker и его override файлы +/docker-compose.yml +/docker-compose.override.yml # Локальный .env /.env + +# id_rsa +/id_rsa diff --git a/Dockerfile b/Dockerfile index cb36528..69be73d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM php:7.1-fpm +FROM php:7.0-fpm ENV PATH $PATH:/root/.composer/vendor/bin -# PHP extensions come first, as they are less likely to change between Yii releases +# Сначала настраиваем всё, что нам нужно на системном уровне RUN apt-get update \ && apt-get -y install \ git \ @@ -10,46 +10,53 @@ RUN apt-get update \ libicu-dev \ libmcrypt-dev \ zlib1g-dev \ + bzip2 \ + libbz2-dev \ + liblzma-dev \ + xz-utils \ openssh-server \ + supervisor \ --no-install-recommends \ + --force-yes \ - # Install PHP extensions + # PHP расширения && docker-php-ext-install intl \ && docker-php-ext-install pdo_mysql \ && docker-php-ext-install mbstring \ && docker-php-ext-install mcrypt \ && docker-php-ext-install zip \ && docker-php-ext-install bcmath \ + && docker-php-ext-install opcache \ && apt-get purge -y g++ \ && apt-get autoremove -y \ && rm -r /var/lib/apt/lists/* \ - # Don't clear our valuable environment vars in PHP + # Отключаем сброс глобальных env переменных внутри PHP && echo "\nclear_env = no" >> /usr/local/etc/php-fpm.conf \ - # Fix write permissions with shared folders + # Фикс прав на запись для расшаренных папок && usermod -u 1000 www-data -# copy-paste from https://github.com/nodejs/docker-node/blob/910443c39c80291f0bf24712d8d94279cf15b7b5/6.5/wheezy/Dockerfile +# Копипаста из https://github.com/nodejs/docker-node/blob/50b56d39a236fd519eda2231757aa2173e270807/5.12/Dockerfile # gpg keys listed at https://github.com/nodejs/node RUN set -ex \ - && for key in \ - 9554F04D7259F04124DE6B476D5A82AC7E37093B \ - 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ - 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ - FD3A5288F042B6850C66B31F09FE44734EB7990E \ - 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ - DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ - B9AE9905FFD7803F25714661B63B535A4C206CA9 \ - C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ - ; do \ - gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ - done + && for key in \ + 9554F04D7259F04124DE6B476D5A82AC7E37093B \ + 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ + 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ + FD3A5288F042B6850C66B31F09FE44734EB7990E \ + 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ + DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ + B9AE9905FFD7803F25714661B63B535A4C206CA9 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + ; do \ + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ + done ENV NPM_CONFIG_LOGLEVEL info -ENV NODE_VERSION 6.5.0 +ENV NODE_VERSION 5.12.0 RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ @@ -59,44 +66,84 @@ RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux- && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ && ln -s /usr/local/bin/node /usr/local/bin/nodejs -# Поставим xdebug отдельно, т.к. потом его потенциально придётся отсюда убирать -# фиксируем версию, т.к. 2.4.1 не собирается под 7.1 -RUN yes | pecl install xdebug-2.4.0 \ - && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.default_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_mode=req" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.cli_color=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ - && echo "xdebug.var_display_max_depth=10" >> /usr/local/etc/php/conf.d/xdebug.ini - ENV COMPOSER_NO_INTERACTION 1 +ENV COMPOSER_ALLOW_SUPERUSER 1 +ENV COMPOSER_DISCARD_CHANGES true -# Next composer and global composer package, as their versions may change from time to time +# Composer и его глобальные зависимости RUN curl -sS https://getcomposer.org/installer | php \ && mv composer.phar /usr/local/bin/composer.phar \ && echo '{"github-oauth": {"github.com": "***REMOVED***"}}' > ~/.composer/auth.json \ - && composer.phar global require --no-progress "hirak/prestissimo:>=0.3.1" + && composer.phar global require --no-progress "hirak/prestissimo:>=0.3.4" COPY ./docker/php/composer.sh /usr/local/bin/composer -RUN chmod a+x /usr/local/bin/composer + +# Конфиг для php +COPY ./docker/php/php.ini /usr/local/etc/php/ + +# Конфиг для supervisor +COPY ./docker/php/supervisord.conf /etc/supervisord.conf + +# wait-for-it +COPY ./docker/wait-for-it.sh /usr/local/bin/wait-for-it + +# Наша кавайная точка входа +COPY ./docker/php/entrypoint.sh /usr/local/bin/ + +RUN chmod a+x /usr/local/bin/composer \ + && chmod a+x /usr/local/bin/entrypoint.sh \ + && chmod a+x /usr/local/bin/wait-for-it \ + && ln -s /usr/local/bin/entrypoint.sh / \ + && mkdir /root/.ssh + +COPY id_rsa /root/.ssh + +# Включаем поддержку ssh +RUN eval $(ssh-agent -s) \ + && ssh-add /root/.ssh/id_rsa \ + && touch /root/.ssh/known_hosts \ + && ssh-keyscan gitlab.com >> /root/.ssh/known_hosts WORKDIR /var/www/html -# Custorm php configuration -COPY ./docker/php/php.ini /usr/local/etc/php/ +# Копируем composer.json в родительскую директорию, которая не будет синкатся с хостом через +# volume на dev окружении. В entrypoint эта папка будет скопирована обратно. +COPY ./composer.json /var/www/composer.json -# Copy the working dir to the image's web root +# Устанавливаем зависимости PHP +RUN cd .. \ + && composer install --no-interaction --no-suggest --no-dev --optimize-autoloader \ + && cd - + +# Устанавливаем зависимости для Node.js +# Делаем это отдельно, чтобы можно было воспользоваться кэшем, если от предыдущего билда +# ничего не менялось в зависимостях +RUN mkdir -p /var/www/frontend + +COPY ./frontend/package.json /var/www/frontend/ +COPY ./frontend/scripts /var/www/frontend/scripts +COPY ./frontend/webpack-utils /var/www/frontend/webpack-utils + +RUN cd ../frontend \ + && npm install \ + && cd - + +# Наконец переносим все сорцы внутрь контейнера COPY . /var/www/html -# The following directories are .dockerignored to not pollute the docker images -# with local logs and published assets from development. So we need to create -# empty dirs and set right permissions inside the container. RUN mkdir -p api/runtime api/web/assets console/runtime \ - && chown www-data:www-data api/runtime api/web/assets console/runtime + && chown www-data:www-data api/runtime api/web/assets console/runtime \ + # Билдим фронт + && cd frontend \ + && ln -s /var/www/frontend/node_modules $PWD/node_modules \ + && npm run build \ + && rm node_modules \ + # Копируем билд наружу, чтобы его не затёрло volume в dev режиме + && cp -r ./dist /var/www/dist \ + && cd - -# Expose everything under /var/www (vendor + html) -VOLUME ["/var/www"] +# Экспозим всё под /var/www/html для дальнейшей связки с nginx +VOLUME ["/var/www/html"] + +ENTRYPOINT ["entrypoint.sh"] +CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"] diff --git a/Dockerfile-dev b/Dockerfile-dev new file mode 100644 index 0000000..fa42b98 --- /dev/null +++ b/Dockerfile-dev @@ -0,0 +1,162 @@ +FROM php:7.0-fpm + +ENV PATH $PATH:/root/.composer/vendor/bin + +# Сначала настраиваем всё, что нам нужно на системном уровне +RUN apt-get update \ + && apt-get -y install \ + git \ + g++ \ + libicu-dev \ + libmcrypt-dev \ + zlib1g-dev \ + bzip2 \ + libbz2-dev \ + liblzma-dev \ + xz-utils \ + openssh-server \ + supervisor \ + --no-install-recommends \ + --force-yes \ + + # PHP расширения + && docker-php-ext-install intl \ + && docker-php-ext-install pdo_mysql \ + && docker-php-ext-install mbstring \ + && docker-php-ext-install mcrypt \ + && docker-php-ext-install zip \ + && docker-php-ext-install bcmath \ + && docker-php-ext-install opcache \ + + && apt-get purge -y g++ \ + && apt-get autoremove -y \ + && rm -r /var/lib/apt/lists/* \ + + # Отключаем сброс глобальных env переменных внутри PHP + && echo "\nclear_env = no" >> /usr/local/etc/php-fpm.conf \ + + # Фикс прав на запись для расшаренных папок + && usermod -u 1000 www-data + +# Копипаста из https://github.com/nodejs/docker-node/blob/50b56d39a236fd519eda2231757aa2173e270807/5.12/Dockerfile + +# gpg keys listed at https://github.com/nodejs/node +RUN set -ex \ + && for key in \ + 9554F04D7259F04124DE6B476D5A82AC7E37093B \ + 94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \ + 0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \ + FD3A5288F042B6850C66B31F09FE44734EB7990E \ + 71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \ + DD8F2338BAE7501E3DD5AC78C273792F7D83545D \ + B9AE9905FFD7803F25714661B63B535A4C206CA9 \ + C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \ + ; do \ + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ + done + +ENV NPM_CONFIG_LOGLEVEL info +ENV NODE_VERSION 5.12.0 + +RUN curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \ + && curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \ + && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \ + && grep " node-v$NODE_VERSION-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c - \ + && tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 \ + && rm "node-v$NODE_VERSION-linux-x64.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs + +# Поставим xdebug отдельно, т.к. потом его потенциально придётся отсюда убирать +RUN yes | pecl install xdebug \ + && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.default_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_mode=req" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.cli_color=1" >> /usr/local/etc/php/conf.d/xdebug.ini \ + && echo "xdebug.var_display_max_depth=10" >> /usr/local/etc/php/conf.d/xdebug.ini + +ENV COMPOSER_NO_INTERACTION 1 +ENV COMPOSER_ALLOW_SUPERUSER 1 +ENV COMPOSER_DISCARD_CHANGES true + +# Composer и его глобальные зависимости +RUN curl -sS https://getcomposer.org/installer | php \ + && mv composer.phar /usr/local/bin/composer.phar \ + && echo '{"github-oauth": {"github.com": "***REMOVED***"}}' > ~/.composer/auth.json \ + && composer.phar global require --no-progress "hirak/prestissimo:>=0.3.4" + +COPY ./docker/php/composer.sh /usr/local/bin/composer + +# Конфиг для php +COPY ./docker/php/php.ini /usr/local/etc/php/ + +# Конфиг для supervisor +COPY ./docker/php/supervisord.conf /etc/supervisord.conf + +# wait-for-it +COPY ./docker/wait-for-it.sh /usr/local/bin/wait-for-it + +# Наша кавайная точка входа +COPY ./docker/php/entrypoint.sh /usr/local/bin/ + +RUN chmod a+x /usr/local/bin/composer \ + && chmod a+x /usr/local/bin/entrypoint.sh \ + && chmod a+x /usr/local/bin/wait-for-it \ + && ln -s /usr/local/bin/entrypoint.sh / \ + && mkdir /root/.ssh + +COPY id_rsa /root/.ssh + +# Включаем поддержку ssh +RUN eval $(ssh-agent -s) \ + && ssh-add /root/.ssh/id_rsa \ + && touch /root/.ssh/known_hosts \ + && ssh-keyscan gitlab.com >> /root/.ssh/known_hosts + +WORKDIR /var/www/html + +# Копируем composer.json в родительскую директорию, которая не будет синкатся с хостом через +# volume на dev окружении. В entrypoint эта папка будет скопирована обратно. +COPY ./composer.json /var/www/composer.json + +# Устанавливаем зависимости PHP +RUN cd .. \ + && composer install --no-interaction --no-suggest \ + && cd - + +# Устанавливаем зависимости для Node.js +# Делаем это отдельно, чтобы можно было воспользоваться кэшем, если от предыдущего билда +# ничего не менялось в зависимостях +RUN mkdir -p /var/www/frontend + +COPY ./frontend/package.json /var/www/frontend/ +COPY ./frontend/scripts /var/www/frontend/scripts +COPY ./frontend/webpack-utils /var/www/frontend/webpack-utils + +RUN cd ../frontend \ + && npm install \ + && cd - + +# Наконец переносим все сорцы внутрь контейнера +COPY . /var/www/html + +RUN mkdir -p api/runtime api/web/assets console/runtime \ + && chown www-data:www-data api/runtime api/web/assets console/runtime \ + # Билдим фронт + && cd frontend \ + && ln -s /var/www/frontend/node_modules $PWD/node_modules \ + && npm run build \ + && rm node_modules \ + # Копируем билд наружу, чтобы его не затёрло volume в dev режиме + && cp -r ./dist /var/www/dist \ + && cd - + +# Экспозим всё под /var/www/html для дальнейшей связки с nginx +VOLUME ["/var/www/html"] + +ENTRYPOINT ["entrypoint.sh"] +CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"] diff --git a/README.md b/README.md index 4c3cd23..fb019f3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Account Ely.by +# Accounts Ely.by ## Развёртывание dev @@ -6,61 +6,49 @@ [docker](https://docs.docker.com/engine/installation/) и его [docker-compose](https://docs.docker.com/compose/install/). -Сливаем репозиторий: +Кроме того, нужно установить, настроить и запустить [nginx-proxy](https://gitlab.com/elyby/nginx-proxy) +контейнер. Это делается один раз в рамках системы и в дальнейшем используется и для других проектов. + +За тем сливаем репозиторий: ```sh -git clone git@bitbucket.org:ErickSkrauch/ely.by-account.git account.ely.by.local +git clone git@gitlab.com:elyby/account.git account.ely.by cd account.ely.by.local ``` -Выполняем первый запуск контейнеров: +Далее нужно создать `.env`, `docker-compose.yml` и `id_rsa` файлы: + +```sh +cp .env-dist .env +cp docker-compose.dev.yml docker-compose.yml +cp ~/.ssh/id_rsa id_rsa # Использовать ссылку нельзя +``` + +Касательно файла id_rsa: часть зависимостей находятся в наших приватных репозиториях, получить +доступ куда можно только в том случае, если в контейнере окажется ключ, который имеет доступ к этим +репозиториям. + +Все вышеперечисленные файла находятся под gitignore, так что с полученными файлами можно произвести +все необходимые манипуляции под конкретный кейс использования. **В файле `.env` обязательно следует +задать `JWT_USER_SECRET`, иначе авторизация на бекенде не заработает.** + +После этого просто выполняем старт всех контейнеров: ```sh docker-compose up -d ``` -Далее нужно влезть в работающие контейнеры и сделать что-нибудь, что их настроит. +Они автоматически сбилдятся и начнут свою работу. ### Как влезть в работающий контейнер -Сперва, с помощью команды `docker ps` мы увидим все запущенные контейнеры. Нас интересуют значения из первой колонки -CONTAINER ID. Узнать, чему они соответствуют можно прочитав название IMAGE из 2 колонки. Чтобы выполнить команду -внутри работабщего контейнера, нужно выполнить: +Сперва, с помощью команды `docker ps` мы увидим все запущенные контейнеры. Нас интересуют значения +из первой колонки CONTAINER ID или NAMES. Узнать, чему они соответствуют можно прочитав название IMAGE +из 2 колонки. Чтобы выполнить команду внутри работабщего контейнера, нужно выполнить: ``` -docker exec -it a7c267b27f49 /bin/bash +docker exec -it accountelyby_app_1 bash ``` -Где `a7c267b27f49` - одно из значений из первой колонки. Для выхода из контейнера используем `exit`. - -------------------------- - -Так вот, нам нужно выполнить ряд команд. Здесь и далее я буду писать имена контейнеров в их соответствии с compose -файлом, но в реалиях их нужно будет заменить на реальные значения: - -```sh -# Настройка php контейнера -docker exec -it app php init --env=Docker -docker exec -it app php composer install -docker exec -it app php ./yii migrate --interactive=0 - -# Настройка node контейнера -docker exec -it node-dev-server npm i -docker exec -it node-dev-server npm --prefix ./webpack i ./webpack -docker exec -it node-dev-server npm --prefix ./scripts i ./scripts - -# Настройка rabbitmq контейнера -docker exec -it rabbitmq /init.sh -``` - -После этого перезапускаем все контейнеры командой: - -```sh -docker-compose restart -``` - -## Тестирование php бэкэнда - -```sh -./tests/run-tests.sh -``` +Где `accountelyby_app_1` - одно из значений CONTAINER ID или NAMES. Для выхода из контейнера +используем `exit`. diff --git a/common/config/ConfigLoader.php b/common/config/ConfigLoader.php index c94c4e1..d4683ec 100644 --- a/common/config/ConfigLoader.php +++ b/common/config/ConfigLoader.php @@ -44,7 +44,7 @@ class ConfigLoader { } // Настройки конкретного приложения для действующего окружения - $path = self::ROOT_PATH . '/' . $this->application . '/config/main-' . YII_ENV . '.php'; + $path = self::ROOT_PATH . '/' . $this->application . '/config/config-' . YII_ENV . '.php'; if (file_exists($path)) { $toMerge[] = require $path; } diff --git a/composer.json b/composer.json index a9de380..429f227 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "ely/yii2-tempmail-validator": "~1.0.0", "emarref/jwt": "~1.0.3", "ely/amqp-controller": "^0.1.0", - "ely/email-renderer": "dev-master#10e77d7a60403e87ca6e8c7d9e62a36fc5e08565" + "ely/email-renderer": "dev-master#4a751652b5a325d44d3bc79a464dda9232486cbc" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/data/mysql/.gitignore b/data/mysql/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/mysql/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/data/redis/.gitignore b/data/redis/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/data/redis/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..9dce11c --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,74 @@ +version: '2' +services: + app: + build: + dockerfile: Dockerfile-dev + context: . + depends_on: + - db + - redis + - rabbitmq + volumes: + - ./:/var/www/html/ + env_file: .env + + web: + build: ./docker/nginx + volumes_from: + - app + links: + - app:php + env_file: .env + networks: + - default + - nginx-proxy + + db: + build: ./docker/mariadb + env_file: .env + volumes: + - ./data/mysql:/var/lib/mysql + + redis: + image: redis:3.0-alpine + volumes: + - ./data/redis:/data + + rabbitmq: + image: rabbitmq:3.6-management + env_file: .env + environment: + - VIRTUAL_HOST=rabbitmq.account.ely.by.local + - VIRTUAL_PORT=15672 + networks: + - default + - nginx-proxy + + phpmyadmin: + build: ./docker/phpmyadmin + environment: + - PMA_ARBITRARY=1 + - PMA_USER=root + - PMA_PASSWORD= + - VIRTUAL_HOST=pma.account.ely.by.local + depends_on: + - db + networks: + - default + - nginx-proxy + + # Эта штука работает дико медленно, грузит процессор и т.д. и т.п. + # Раскоментировать только в случае лютой надобности + #node-dev-server: + # build: ./frontend + # ports: + # - "8080:8080" + # volumes: + # - ./frontend/:/usr/src/app/ + # environment: + # DOCKERIZED: "true" + +networks: + nginx-proxy: + external: + name: nginx-proxy diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..01589ad --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,40 @@ +version: '2' +services: + app: + build: . + depends_on: + - db + - redis + - rabbitmq + env_file: .env + + web: + build: ./docker/nginx + volumes_from: + - app + links: + - app:php + env_file: .env + networks: + - default + - nginx-proxy + + db: + build: ./docker/mariadb + env_file: .env + volumes: + - ./data/mysql:/var/lib/mysql + + redis: + image: redis:3.0-alpine + volumes: + - ./data/redis:/data + + rabbitmq: + image: rabbitmq:3.6 + env_file: .env + +networks: + nginx-proxy: + external: + name: nginx-proxy diff --git a/docker-compose.yml b/docker-compose.yml index 991b9bc..0298f6d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,9 @@ version: '2' services: app: - build: . + build: + dockerfile: Dockerfile-dev + context: . depends_on: - db - redis @@ -21,37 +23,26 @@ services: - default - nginx-proxy - node-dev-server: - build: ./frontend - ports: - - "8080:8080" - volumes: - - ./frontend/:/usr/src/app/ - environment: - DOCKERIZED: "true" - - app-console-account-queue: - build: . - volumes: - - ./:/var/www/html/ - command: ["docker/wait-for-it.sh", "rabbitmq:5672", "--", "php", "yii", "account-queue"] - links: - - db - - redis - - rabbitmq - db: build: ./docker/mariadb env_file: .env + volumes: + - ./data/mysql:/var/lib/mysql redis: - image: redis:3.0 + image: redis:3.0-alpine + volumes: + - ./data/redis:/data rabbitmq: - build: ./docker/rabbitmq + image: rabbitmq:3.6-management env_file: .env - ports: - - "15672:15672" # Manager interface + environment: + - VIRTUAL_HOST=rabbitmq.account.ely.by.local + - VIRTUAL_PORT=15672 + networks: + - default + - nginx-proxy phpmyadmin: build: ./docker/phpmyadmin @@ -59,10 +50,12 @@ services: - PMA_ARBITRARY=1 - PMA_USER=root - PMA_PASSWORD= - ports: - - "8181:80" + - VIRTUAL_HOST=pma.account.ely.by.local depends_on: - db + networks: + - default + - nginx-proxy networks: nginx-proxy: diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile index d524401..3c47e59 100644 --- a/docker/nginx/Dockerfile +++ b/docker/nginx/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:1.11 +FROM nginx:1.11-alpine COPY nginx.conf /etc/nginx/nginx.conf COPY account.ely.by.conf.template /etc/nginx/conf.d/account.ely.by.conf.template diff --git a/docker/nginx/run.sh b/docker/nginx/run.sh index 2c2bfa8..7365afe 100644 --- a/docker/nginx/run.sh +++ b/docker/nginx/run.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh envsubst '$AUTHSERVER_HOST' < /etc/nginx/conf.d/account.ely.by.conf.template > /etc/nginx/conf.d/default.conf diff --git a/docker/php/entrypoint.sh b/docker/php/entrypoint.sh new file mode 100644 index 0000000..a001700 --- /dev/null +++ b/docker/php/entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +cd /var/www/html + +if [ "$1" = 'bash' ] +then + exec "$@" + exit 0 +fi + +# Переносим vendor, если его нету или он изменился (или затёрся силами volume) +if ! cmp -s ./../vendor/autoload.php ./vendor/autoload.php +then + echo "vendor have diffs..." + echo "removing exists vendor" + rm -rf ./vendor + echo "copying new one" + cp -r ./../vendor ./vendor +fi + +# Переносим dist, если его нету или он изменился (или затёрся силами volume) +if ! cmp -s ./../dist/index.html ./frontend/dist/index.html +then + echo "frontend dist have diffs..." + echo "removing exists dist" + rm -rf ./frontend/dist + echo "copying new one" + cp -r ./../dist ./frontend/dist +fi + +wait-for-it db:3306 -- "./yii migrate/up --interactive=0" + +exec "$@" diff --git a/docker/php/supervisord.conf b/docker/php/supervisord.conf new file mode 100644 index 0000000..22c385c --- /dev/null +++ b/docker/php/supervisord.conf @@ -0,0 +1,36 @@ +[supervisord] +logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) +logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) +logfile_backups=10 ; (num of main logfile rotation backups;default 10) +loglevel=info ; (log level;default info; others: debug,warn,trace) +pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) +nodaemon=false ; (start in foreground if true;default false) +minfds=1024 ; (min. avail startup file descriptors;default 1024) +minprocs=200 ; (min. avail process descriptors;default 200) +user=root + +; the below section must remain in the config file for RPC +; (supervisorctl/web interface) to work, additional interfaces may be +; added by defining them in separate rpcinterface: sections +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl=unix:///dev/shm/supervisor.sock ; use a unix:// URL for a unix socket + +[program:php-fpm] +command=php-fpm +autostart=true +autorestart=true +priority=5 +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stderr +stderr_logfile_maxbytes=0 + +[program:account-queue-worker] +directory=/var/www/html +command=wait-for-it rabbitmq:5672 -- php yii account-queue +autostart=true +autorestart=true +priority=10 diff --git a/docker/rabbitmq/Dockerfile b/docker/rabbitmq/Dockerfile deleted file mode 100644 index 8e27027..0000000 --- a/docker/rabbitmq/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM rabbitmq:3.6 - -RUN rabbitmq-plugins enable rabbitmq_management \ - && rabbitmq-plugins enable rabbitmq_web_stomp \ - && rabbitmq-plugins enable rabbitmq_mqtt - -ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["rabbitmq-server"] diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 3b01b9e..e2faa61 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -1,17 +1,17 @@ version: '2' services: testphp: - build: ./.. - links: - - testdb - - testredis - - testrabbit + extends: + file: ../docker-compose.dev.yml + service: app volumes: - ./../:/var/www/html/ env_file: ./../.env testdb: - build: ./../docker/mariadb + extends: + file: ../docker-compose.dev.yml + service: db environment: MYSQL_ROOT_PASSWORD: "" MYSQL_ALLOW_EMPTY_PASSWORD: "yes" @@ -20,10 +20,14 @@ services: MYSQL_PASSWORD: "ely_accounts_tester_password" testredis: - image: redis:3.0 + extends: + file: ../docker-compose.dev.yml + service: redis testrabbit: - build: ./../docker/rabbitmq + extends: + file: ../docker-compose.dev.yml + service: rabbitmq environment: RABBITMQ_DEFAULT_USER: "ely-accounts-tester" RABBITMQ_DEFAULT_PASS: "tester-password"