diff --git a/.kube/app/values.development.yaml b/.kube/app/values.development.yaml index 5a09a678f..ea3fd8638 100644 --- a/.kube/app/values.development.yaml +++ b/.kube/app/values.development.yaml @@ -19,6 +19,7 @@ env: SAIL_XDEBUG_MODE: "develop,debug,coverage" FILES_PATH: "/opt/data/storage" VIEW_COMPILED_PATH: "/app/bootstrap/views" + MINIO_DRIVER: "s3" # CACHE_PATH: "/opt/data/cache" removed per https://github.com/accessibility-exchange/platform/issues/1596 ### Place those values in Vault diff --git a/.kube/app/values.production.yaml b/.kube/app/values.production.yaml index 51059e93a..b587b99ae 100644 --- a/.kube/app/values.production.yaml +++ b/.kube/app/values.production.yaml @@ -19,6 +19,8 @@ env: SAIL_XDEBUG_MODE: "develop,debug,coverage" FILES_PATH: "/opt/data/storage" VIEW_COMPILED_PATH: "/app/bootstrap/views" + MINIO_DRIVER: "s3" + # CACHE_PATH: "/opt/data/cache" removed per https://github.com/accessibility-exchange/platform/issues/1596 ### Place those values in Vault # secrets: diff --git a/.kube/app/values.staging.yaml b/.kube/app/values.staging.yaml index 55bc1215c..019f27aba 100644 --- a/.kube/app/values.staging.yaml +++ b/.kube/app/values.staging.yaml @@ -19,6 +19,8 @@ env: SAIL_XDEBUG_MODE: "develop,debug,coverage" FILES_PATH: "/opt/data/storage" VIEW_COMPILED_PATH: "/app/bootstrap/views" + MINIO_DRIVER: "s3" + # CACHE_PATH: "/opt/data/cache" removed per https://github.com/accessibility-exchange/platform/issues/1596 ### Place those values in Vault # secrets: diff --git a/README.md b/README.md index 221d6a673..17f65da4e 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ Takes filament tables and backs them up to JSON files so that they can be used b | option | Description | | --- | ---- | -| `--env` | Override the environment tag that is being handled. | +| `--from` | Override the environment tag that is being handled. | * Available environments are found in config **backup.filament_seeders.environments**. * When used by default backup it will tag the json files with environment tag. diff --git a/app/Console/Commands/RefreshDev.php b/app/Console/Commands/RefreshDev.php new file mode 100644 index 000000000..53a370c19 --- /dev/null +++ b/app/Console/Commands/RefreshDev.php @@ -0,0 +1,35 @@ +call('down'); + $this->call('migrate:fresh --seeder=DevSeeder'); + $this->call('db:seed:backup --all --restore --from=production'); + $this->call('up'); + } + } +} diff --git a/app/Console/Commands/SeederBackupData.php b/app/Console/Commands/SeederBackupData.php index 4a2f78f2f..8e25f8108 100644 --- a/app/Console/Commands/SeederBackupData.php +++ b/app/Console/Commands/SeederBackupData.php @@ -15,7 +15,7 @@ class SeederBackupData extends Command */ protected $signature = 'db:seed:backup {--a|all : Whether to run through all available backups/restores in config}? - {--env= : Specify an environment configured in backup.filament_seeders.environments}? + {--from= : Specify an environment configured in backup.filament_seeders.environments}? {--remove : Remove backed up files}? {--restore : Restore the filament table}? {--t|table=* : Create/remove specific table file}? @@ -38,15 +38,15 @@ public function handle() $options = $this->options(); // option to use environment to restore or backup to different environment files - if (isset($options['env']) && in_array($options['env'], config('backup.filament_seeders.environments')) === true) { - $environment = $options['env']; + if (isset($options['from']) && in_array($options['from'], config('backup.filament_seeders.environments')) === true) { + $environment = $options['from']; } else { $environment = config('app.env'); } $available_tables = config('backup.filament_seeders.tables'); - // removes backuped up files + // removes backed up files if ($options['remove']) { // if the table option is set only remove that tables file // else remove all found in the config @@ -54,7 +54,7 @@ public function handle() foreach ($options['table'] as $table) { if (in_array($table, $available_tables)) { printf("Deleting table: %s, for environment: %s\r\n", $table, $environment); - Storage::disk('seeds')->delete(sprintf('%s.%s.json', $table, $environment)); + Storage::disk('seeds')->delete(sprintf('%s/%s.%s.json', config('filesystems.disks.seeds.path'), $table, $environment)); } else { printf("You have might have misspelled the tablename.\r\nTable %s not found.\r\nAvailable tables: %s\r\n", $table, implode(', ', $available_tables)); @@ -66,7 +66,7 @@ public function handle() } else { foreach ($available_tables as $table) { printf("Deleting table: %s, for environment: %s\r\n", $table, $environment); - Storage::disk('seeds')->delete(sprintf('%s.%s.json', $table, $environment)); + Storage::disk('seeds')->delete(sprintf('%s/%s.%s.json', config('filesystems.disks.seeds.path'), $table, $environment)); } } @@ -115,7 +115,7 @@ public function handle() } elseif ($options['all']) { foreach ($available_tables as $table) { printf("Backing up table seeder: %s for environment: %s\r\n", $table, $environment); - Storage::disk('seeds')->put(sprintf('%s.%s.json', $table, $environment), DB::table($table)->get()->toJson()); + Storage::disk('seeds')->put(sprintf('%s/%s.%s.json', config('filesystems.disks.seeds.path'), $table, $environment), DB::table($table)->get()->toJson()); } return 0; @@ -125,7 +125,7 @@ public function handle() foreach ($options['table'] as $table) { if (in_array($table, $available_tables)) { printf("Backing up table seeder %s\r\n", $table); - Storage::disk('seeds')->put(sprintf('%s.%s.json', $table, $environment), DB::table($table)->get()->toJson()); + Storage::disk('seeds')->put(sprintf('%s/%s.%s.json', config('filesystems.disks.seeds.path'), $table, $environment), DB::table($table)->get()->toJson()); } else { printf("You have might have misspelled the tablename.\r\nTable %s not found.\r\nAvailable tables: %s\r\n", $table, implode(', ', $available_tables)); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5eea331b6..078eaad00 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -25,11 +25,19 @@ protected function schedule(Schedule $schedule) { $schedule->command('db:seed:backup --all') // use custom command to make sure that the commands are chained ->daily() // Run daily at midnight - ->environments(['staging', 'dev', 'local']) // only run for APP_ENV tagged staging, dev, or local + ->environments(['staging', 'dev', 'local', 'production']) // only run for APP_ENV tagged staging, dev, local, or production + ->timezone('America/Los_Angeles') // Run as PST timezone + ->onOneServer(); // run only on a single server at once + + $schedule->command('app:refresh-dev') // use custom command to make sure that te commands are chained + ->dailyAt('00:15') // Run daily at 12:15 am + ->environments(['dev']) // only run for APP_ENV tagged dev + ->timezone('America/Los_Angeles') // Run as PST timezone ->onOneServer(); // run only on a single server at once $schedule->command('notifications:remove:old --days=30') // remove notifications older than 30 days old and read ->daily() // Run daily at midnight + ->timezone('America/Los_Angeles') // Run as PST timezone ->onOneServer(); // run only on a single server at once } diff --git a/config/filesystems.php b/config/filesystems.php index df82b648e..16d46eb11 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -36,8 +36,14 @@ ], 'seeds' => [ - 'driver' => 'local', - 'root' => storage_path('app/seeds'), + 'driver' => env('MINIO_DRIVER', 'local'), + 'root' => storage_path('seeds'), + 'key' => env('MINIO_ACCESS_KEY'), + 'secret' => env('MINIO_SECRET_KEY'), + 'region' => env('MINIO_REGION'), + 'bucket' => env('MINIO_PROJECT_BUCKET'), + 'use_path_style_endpoint' => true, + 'endpoint' => 'https://'.env('MINIO_ENDPOINT'), ], 'public' => [ diff --git a/database/seeders/IdentitySeeder.php b/database/seeders/IdentitySeeder.php index b47a28f9d..4bbe3e1d6 100644 --- a/database/seeders/IdentitySeeder.php +++ b/database/seeders/IdentitySeeder.php @@ -18,15 +18,15 @@ public function run() $environment = config('app.env'); } - if (Storage::disk('seeds')->exists(sprintf('identities.%s.json', $environment))) { - // if trucate was set via seeder restore command then truncate the table prior to seeding data + if (Storage::disk('seeds')->has(sprintf('%s/identities.%s.json', config('filesystems.disks.seeds.path'), $environment))) { + // if truncate was set via seeder restore command then truncate the table prior to seeding data if (config('seeder.truncate')) { DB::statement('SET foreign_key_checks=0'); Identity::truncate(); DB::statement('SET foreign_key_checks=1'); } - $identities = json_decode(Storage::disk('seeds')->get(sprintf('identities.%s.json', $environment)), true); + $identities = json_decode(Storage::disk('seeds')->get(sprintf('%s/identities.%s.json', config('filesystems.disks.seeds.path'), $environment)), true); foreach ($identities as $identity) { Identity::firstOrCreate([ diff --git a/database/seeders/InterpretationSeeder.php b/database/seeders/InterpretationSeeder.php index 067bee4fb..b045b0a42 100644 --- a/database/seeders/InterpretationSeeder.php +++ b/database/seeders/InterpretationSeeder.php @@ -31,8 +31,7 @@ public function run() } if (Storage::disk('seeds')->exists(sprintf('interpretations.%s.json', $environment))) { - $interpretations = json_decode(Storage::disk('seeds')->get(sprintf('interpretations.%s.json', $environment)), true); - + $interpretations = json_decode(Storage::disk('seeds')->get(sprintf('%s/interpretations.%s.json', config('filesystems.disks.seeds.path'), $environment)), true); foreach ($interpretations as $interpretation) { Interpretation::firstOrCreate([ 'name' => $interpretation['name'], diff --git a/database/seeders/ResourceCollectionSeeder.php b/database/seeders/ResourceCollectionSeeder.php index e33ae9a09..c173b7fa6 100644 --- a/database/seeders/ResourceCollectionSeeder.php +++ b/database/seeders/ResourceCollectionSeeder.php @@ -26,15 +26,15 @@ public function run() } // TODO need to write handling of attachments - if (false && Storage::disk('seeds')->exists(sprintf('resource_collections.%s.json', $environment))) { - // if trucate was set via seeder restore command then truncate the table prior to seeding data + if (false && Storage::disk('seeds')->exists(sprintf('%s/resource_collections.%s.json', config('filesystems.disks.seeds.path'), $environment))) { + // if truncate was set via seeder restore command then truncate the table prior to seeding data if (config('seeder.truncate')) { DB::statement('SET foreign_key_checks=0'); ResourceCollection::truncate(); DB::statement('SET foreign_key_checks=1'); } - $resourceCollections = json_decode(Storage::disk('seeds')->get(sprintf('resource_collections.%s.json', $environment)), true); + $resourceCollections = json_decode(Storage::disk('seeds')->get(sprintf('%s/resource_collections.%s.json', config('filesystems.disks.seeds.path'), $environment)), true); foreach ($resourceCollections as $resourceCollection) { ResourceCollection::firstOrCreate([ diff --git a/database/seeders/ResourceSeeder.php b/database/seeders/ResourceSeeder.php index 57cced071..ac48c62cd 100644 --- a/database/seeders/ResourceSeeder.php +++ b/database/seeders/ResourceSeeder.php @@ -29,7 +29,7 @@ public function run() } // TODO need to write handling of attachments - if (false && Storage::disk('seeds')->exists(sprintf('resources.%s.json', $environment))) { + if (false && Storage::disk('seeds')->exists(sprintf('%s/resources.%s.json', config('filesystems.disks.seeds.path'), $environment))) { // if truncate was set via seeder restore command then truncate the table prior to seeding data if (config('seeder.truncate')) { DB::statement('SET foreign_key_checks=0'); @@ -37,7 +37,7 @@ public function run() DB::statement('SET foreign_key_checks=1'); } - $resources = json_decode(Storage::disk('seeds')->get(sprintf('resources.%s.json', $environment)), true); + $resources = json_decode(Storage::disk('seeds')->get(sprintf('%s/resources.%s.json', config('filesystems.disks.seeds.path'), $environment)), true); foreach ($resources as $resource) { if ($resource['content_type_id']) { diff --git a/database/seeders/TopicSeeder.php b/database/seeders/TopicSeeder.php index 538a22906..7715123c5 100644 --- a/database/seeders/TopicSeeder.php +++ b/database/seeders/TopicSeeder.php @@ -23,15 +23,15 @@ public function run() $environment = config('app.env'); } - if (Storage::disk('seeds')->exists(sprintf('topics.%s.json', $environment))) { - // if trucate was set via seeder restore command then truncate the table prior to seeding data + if (Storage::disk('seeds')->exists(sprintf('%s/topics.%s.json', config('filesystems.disks.seeds.path'), $environment))) { + // if truncate was set via seeder restore command then truncate the table prior to seeding data if (config('seeder.truncate')) { DB::statement('SET foreign_key_checks=0'); Topic::truncate(); DB::statement('SET foreign_key_checks=1'); } - $topics = json_decode(Storage::disk('seeds')->get(sprintf('topics.%s.json', $environment)), true); + $topics = json_decode(Storage::disk('seeds')->get(sprintf('%s/topics.%s.json', config('filesystems.disks.seeds.path'), $environment)), true); foreach ($topics as $topic) { Topic::firstOrCreate([