fix(command): Cache configuration on Update in production (#1688)

This commit is contained in:
Alexis Saettler
2018-08-24 08:36:03 +02:00
committed by GitHub
parent f6cad52758
commit de3f3917bb
9 changed files with 29 additions and 18 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
}
],
"scripts": {
"postdeploy": "php artisan monica:update --force"
"postdeploy": "php artisan monica:update --force -vvv"
},
"env": {
"APP_KEY": {
@@ -37,17 +37,14 @@ class CommandExecutor implements CommandExecutorInterface
public function artisan($message, $commandline, array $arguments = [])
{
$this->command->info($message);
$info = '';
foreach ($arguments as $key => $value) {
$info = $info.' '.$key.'='.$value;
if (is_string($key)) {
$info .= ' '.$key.'="'.$value.'"';
} else {
$info .= ' '.$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);
}
$this->command->line('');
$this->exec($message, 'php artisan '.$commandline.$info);
}
}
+11 -4
View File
@@ -60,11 +60,12 @@ class Update extends Command
]);
// 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');
@@ -86,12 +87,18 @@ class Update extends Command
}
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' => 'true']);
$this->commandExecutor->artisan('✓ Ping for new version', 'monica:ping', ['--force']);
// 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');
}
+1 -1
View File
@@ -44,6 +44,6 @@ return [
/*
* Enable cloudflare trusted proxies
*/
'cloudflare' => env('APP_TRUSTED_CLOUDFLARE', false),
'cloudflare' => (bool) env('APP_TRUSTED_CLOUDFLARE', false),
];
@@ -15,7 +15,7 @@ class UpdateTimestampsTimezone extends Migration
{
$timezone = env('APP_DEFAULT_TIMEZONE', 'UTC');
if ($timezone == 'UTC') {
if ($timezone == null || $timezone == 'UTC') {
return;
}
+3
View File
@@ -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).
+4
View File
@@ -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)
+1 -1
View File
@@ -20,7 +20,7 @@ else
fi
# Run migrations
${ARTISAN} monica:update --force
${ARTISAN} monica:update --force -v
# Run cron
crond -b &
+1 -1
View File
@@ -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"