Skip to content

Commit

Permalink
Merge pull request #29 from yii2mod/add_environments
Browse files Browse the repository at this point in the history
Add environments
  • Loading branch information
Igor Chepurnoy authored Mar 5, 2017
2 parents 51bfc9c + 6933247 commit 0beb70b
Show file tree
Hide file tree
Showing 32 changed files with 555 additions and 100 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# yii console commands
/yii

# phpstorm project files
.idea

Expand All @@ -12,11 +15,6 @@ nbproject
# windows thumbnail cache
Thumbs.db

# local configs
config/common.local.php
config/console.local.php
config/main.local.php

# composer vendor dir
/vendor

Expand Down
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ install:
- travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0"
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer create-project
# setup application:
- |
./init --env=Development
before_script:
- mysql -e 'CREATE DATABASE yii2mod_base_test;';
- mysql -e 'CREATE DATABASE yii2mod_base_test;'
- cd tests/bin && php yii migrate --interactive=0 && php yii rbac/migrate --interactive=0 && cd ../..
- php -S localhost:8080 -t web > /dev/null 2>&1 &

script:
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ CONFIGURATION
After you install the application, you have to conduct the following steps to initialize
the installed application. You only need to do these once for all.

1. Create a new database and adjust the `components['db']` configuration in `config/common-local.php` accordingly.
1) Init the application by the following command:
```bash
./init --env=Development
```

2) Create a new database and adjust the `components['db']` configuration in `config/common-local.php` accordingly.

2. Apply migrations:
- `php yii migrate` - create default tables for application
- `php yii rbac/migrate` - create roles, permissions and rules
- `php yii fixture "*"` - load fixtures (cms pages and users)
3) Apply migrations:

3. Set document root of your web server to `/path/to/application/web/` folder.
- `php yii migrate` - create default tables for application
- `php yii rbac/migrate` - create roles, permissions and rules
- `php yii fixture "*"` - load fixtures (cms pages and users)

4) Set document root of your web server to `/path/to/application/web/` folder.


Installing using Docker
Expand All @@ -93,10 +99,14 @@ You can install the application using the following commands:
```sh
composer create-project --no-install yii2mod/base yii2mod-base
cd yii2mod-base
./init --env=Development
cp .env{.dist,}
cp docker-compose.override.yml{.dist,}
docker-compose up --build
```
> In `.env` file your need to set your UID.
> You can get your UID by the following command in the terminal: `id -u <username>`
It may take some minutes to download the required docker images. When
done, you need to install vendors as follows:

Expand All @@ -106,7 +116,7 @@ composer install
chown -R www-data:www-data runtime web/assets vendor
```

After this steps, you need to update `common.local.php` file in the config directory as follows:
After this steps, you need to update `common-local.php` file in the config directory as follows:
```php
<?php

Expand Down
21 changes: 0 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,7 @@
"process-timeout": 1800,
"bin-dir": "bin"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
],
"copyFiles": [
{
"config/deploy/console.local.php": "config/console.local.php",
"config/deploy/main.local.php": "config/main.local.php",
"config/deploy/common.local.php": "config/common.local.php"
}
]
},
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
Expand Down
6 changes: 6 additions & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
common-local.php
main-local.php
console-local.php
params-local.php
test_db.php
test.php
10 changes: 6 additions & 4 deletions config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Yii::setAlias('@tests', dirname(__DIR__) . '/tests');

$params = array_merge(
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);

$config = [
'name' => 'Yii2 Basic Template',
'language' => 'en-US',
Expand Down Expand Up @@ -42,10 +47,7 @@
],
],
],
'params' => [
'adminEmail' => '[email protected]',
'user.passwordResetTokenExpire' => 3600,
],
'params' => $params,
];

return $config;
9 changes: 1 addition & 8 deletions config/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'controllerMap' => [
'migrate' => [
'class' => 'cyberz\migrations\controllers\MigrationsController',
'templateFile' => '@app/views/migration.php',
'migrationLookup' => [
'@vendor/yii2mod/yii2-cms/migrations',
'@vendor/yii2mod/yii2-cron-log/migrations',
Expand Down Expand Up @@ -38,12 +39,4 @@
],
];

if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}

return $config;
6 changes: 0 additions & 6 deletions config/deploy/main.local.php

This file was deleted.

13 changes: 0 additions & 13 deletions config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,4 @@
],
];

if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}

return $config;
6 changes: 6 additions & 0 deletions config/params.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [
'adminEmail' => '[email protected]',
'user.passwordResetTokenExpire' => 3600,
];
2 changes: 0 additions & 2 deletions docker-compose.override.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ services:
web:
ports:
- "80:80"
environment:
APPLICATION_ENV: dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
'password' => '',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'useFileTransport' => true,
],
],
'params' => [
],
];

return $config;
8 changes: 8 additions & 0 deletions environments/dev/config/console-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'bootstrap' => ['gii'],
'modules' => [
'gii' => 'yii\gii\Module',
],
];
23 changes: 23 additions & 0 deletions environments/dev/config/main-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

$config = [
'components' => [
'request' => [
'cookieValidationKey' => '',
],
],
];

if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}

return $config;
4 changes: 4 additions & 0 deletions environments/dev/config/params-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

return [
];
4 changes: 2 additions & 2 deletions config/test.php → environments/dev/config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
return yii\helpers\ArrayHelper::merge(
require __DIR__ . '/main.php',
require __DIR__ . '/main.local.php',
require __DIR__ . '/main-local.php',
require __DIR__ . '/common.php',
require __DIR__ . '/common.local.php',
require __DIR__ . '/common-local.php',
[
'id' => 'basic-tests',
'components' => [
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions environments/dev/web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/common.php'),
require(__DIR__ . '/../config/common-local.php'),
require(__DIR__ . '/../config/main.php'),
require(__DIR__ . '/../config/main-local.php')
);

(new yii\web\Application($config))->run();
9 changes: 3 additions & 6 deletions yii → environments/dev/yii
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
*/

defined('YII_DEBUG') or define('YII_DEBUG', true);

// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
defined('YII_ENV') or define('YII_ENV', 'dev');

require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');

$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/config/common.php'),
require(__DIR__ . '/config/common.local.php'),
require(__DIR__ . '/config/common-local.php'),
require(__DIR__ . '/config/console.php'),
require(__DIR__ . '/config/console.local.php')
require(__DIR__ . '/config/console-local.php')
);

$application = new yii\console\Application($config);
Expand Down
58 changes: 58 additions & 0 deletions environments/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* The manifest of files that are local to specific environment.
* This file returns a list of environments that the application
* may be installed under. The returned data must be in the following
* format:
*
* ```php
* return [
* 'environment name' => [
* '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' => [
'runtime',
'web/assets',
],
'setExecutable' => [
'yii',
],
'setCookieValidationKey' => [
'config/main-local.php',
],
],
'Production' => [
'path' => 'prod',
'setWritable' => [
'runtime',
'web/assets',
],
'setExecutable' => [
'yii',
],
'setCookieValidationKey' => [
'config/main-local.php',
],
],
];
16 changes: 16 additions & 0 deletions environments/prod/config/common-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$config = [
'components' => [
'db' => [
'dsn' => 'mysql:host=;dbname=',
'username' => '',
'password' => '',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
],
],
];

return $config;
File renamed without changes.
11 changes: 11 additions & 0 deletions environments/prod/config/main-local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$config = [
'components' => [
'request' => [
'cookieValidationKey' => '',
],
],
];

return $config;
Loading

0 comments on commit 0beb70b

Please sign in to comment.