Skip to content

Commit

Permalink
fix(command): Cache configuration on Update in production (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Aug 24, 2018
1 parent f6cad52 commit de3f391
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"scripts": {
"postdeploy": "php artisan monica:update --force"
"postdeploy": "php artisan monica:update --force -vvv"
},
"env": {
"APP_KEY": {
Expand Down
15 changes: 6 additions & 9 deletions app/Console/Commands/Helpers/CommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@ public function exec($message, $commandline)

public function artisan($message, $commandline, array $arguments = [])
{
$this->command->info($message);
$info = '';
foreach ($arguments as $key => $value) {
$info = $info.' '.$key.'='.$value;
}
$this->command->line('php artisan '.$commandline.$info);
if ($this->command->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->command->call($commandline, $arguments);
} else {
$this->command->callSilent($commandline, $arguments);
if (is_string($key)) {
$info .= ' '.$key.'="'.$value.'"';
} else {
$info .= ' '.$value;
}
}
$this->command->line('');
$this->exec($message, 'php artisan '.$commandline.$info);
}
}
15 changes: 11 additions & 4 deletions app/Console/Commands/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public function handle()
]);

// Clear or rebuild all cache
if (config('cache.default') != 'database' || Schema::hasTable('cache')) {
if (config('cache.default') != 'database' || Schema::hasTable(config('cache.stores.database.table'))) {
$this->commandExecutor->artisan('✓ Resetting application cache', 'cache:clear');
}

if ($this->getLaravel()->environment() == 'production') {
$this->commandExecutor->artisan('✓ Clear config cache', 'config:clear');
$this->commandExecutor->artisan('✓ Resetting route cache', 'route:cache');
if ($this->getLaravel()->version() > '5.6') {
$this->commandExecutor->artisan('✓ Resetting view cache', 'view:cache');
Expand All @@ -86,12 +87,18 @@ public function handle()
}

if ($this->migrateCollationTest()) {
$this->commandExecutor->artisan('✓ Performing collation migrations', 'migrate:collation', ['--force' => 'true']);
$this->commandExecutor->artisan('✓ Performing collation migrations', 'migrate:collation', ['--force']);
}

$this->commandExecutor->artisan('✓ Performing migrations', 'migrate', ['--force' => 'true']);
$this->commandExecutor->artisan('✓ Performing migrations', 'migrate', ['--force']);

$this->commandExecutor->artisan('✓ Ping for new version', 'monica:ping', ['--force']);

$this->commandExecutor->artisan('✓ Ping for new version', 'monica:ping', ['--force' => 'true']);
// Cache config
if ($this->getLaravel()->environment() == 'production'
&& (config('cache.default') != 'database' || Schema::hasTable(config('cache.stores.database.table')))) {
$this->commandExecutor->artisan('✓ Cache configuraton', 'config:cache');
}
} finally {
$this->commandExecutor->artisan('✓ Maintenance mode: off', 'up');
}
Expand Down
2 changes: 1 addition & 1 deletion config/trustedproxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
/*
* Enable cloudflare trusted proxies
*/
'cloudflare' => env('APP_TRUSTED_CLOUDFLARE', false),
'cloudflare' => (bool) env('APP_TRUSTED_CLOUDFLARE', false),

];
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up()
{
$timezone = env('APP_DEFAULT_TIMEZONE', 'UTC');

if ($timezone == 'UTC') {
if ($timezone == null || $timezone == 'UTC') {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions docs/installation/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ exit
1. Run `php artisan setup:production` to run the migrations, seed the database and symlink folders.
1. Optional: run `php artisan passport:install` to create the access tokens required for the API (Optional).

The `setup:production` command will run migrations scripts for database, and flush all cache for config, route, and view, as an optimization process.
As the configuration of the application is cached, any update on the `.env` file will not be detected after that. You may have to run `php artisan config:cache` manually after every update of `.env` file.

### 4. Configure cron job

Monica requires some background processes to continuously run. The list of things Monica does in the background is described [here](https://github.com/monicahq/monica/blob/master/app/Console/Kernel.php#L33).
Expand Down
4 changes: 4 additions & 0 deletions docs/installation/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ steps below to update it, **every single time**, or you will run into problems.
php artisan monica:update --force
```

The `monica:update` command will run migrations scripts for database, and flush all cache for config, route, and view, as an optimization process.
As the configuration of the application is cached, any update on the `.env` file will not be detected after that. You may have to run `php artisan config:cache` manually after every update of `.env` file.


Your instance should be updated.

## Importing vCards (CLI only)
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker/test-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
fi

# Run migrations
${ARTISAN} monica:update --force
${ARTISAN} monica:update --force -v

# Run cron
crond -b &
Expand Down
2 changes: 1 addition & 1 deletion scripts/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else
fi
# Run migrations
${ARTISAN} monica:update --force
${ARTISAN} monica:update --force -v
echo -e "\n\n\033[1;32mDone! You can access Monica by visiting \033[4;96mhttp://localhost:8080\033[0;40m\033[1;32m from your host machine\033[0;40m"
Expand Down

0 comments on commit de3f391

Please sign in to comment.