Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(deploy): add command & queue to put site into maintenance and brin… #1981

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .kube/app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

php artisan maintenance:queue

# TODO permanent remove cache lines once testing on per/pod caching is tested

mkdir -p $FILES_PATH
Expand All @@ -26,7 +28,7 @@ ln -s $FILES_PATH /app/storage

php artisan deploy:local

flock -n -E 0 /opt/data -c "php artisan deploy:global" # run exclusively on a single instance at once
flock -n -E 0 /opt/data/deploy-global.lock -c "php artisan deploy:global" # run exclusively on a single instance at once

## fix permissions after syncing to existing storage and cache https://github.com/accessibility-exchange/platform/issues/1236
chown -R www-data:root /app/bootstrap/cache $FILES_PATH # $CACHE_PATH removed per and added path to cache in the pod https://github.com/accessibility-exchange/platform/issues/1596
Expand Down
9 changes: 9 additions & 0 deletions .kube/app/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:laravel-worker]
command=php /app/artisan queue:work --force --sleep=30 --tries=3 --max-time=900
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
2 changes: 1 addition & 1 deletion .kube/app/values.development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
LOG_LEVEL: "debug"
BROADCAST_DRIVER: "log"
CACHE_DRIVER: "file"
QUEUE_CONNECTION: "sync"
QUEUE_CONNECTION: "redis"
SESSION_DRIVER: "database"
SESSION_LIFETIME: "120"
SAIL_XDEBUG_MODE: "develop,debug,coverage"
Expand Down
2 changes: 1 addition & 1 deletion .kube/app/values.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
LOG_LEVEL: "debug"
BROADCAST_DRIVER: "log"
CACHE_DRIVER: "file"
QUEUE_CONNECTION: "sync"
QUEUE_CONNECTION: "redis"
SESSION_DRIVER: "database"
SESSION_LIFETIME: "120"
SAIL_XDEBUG_MODE: "develop,debug,coverage"
Expand Down
2 changes: 1 addition & 1 deletion .kube/app/values.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
LOG_LEVEL: "debug"
BROADCAST_DRIVER: "log"
CACHE_DRIVER: "file"
QUEUE_CONNECTION: "sync"
QUEUE_CONNECTION: "redis"
SESSION_DRIVER: "database"
SESSION_LIFETIME: "120"
SAIL_XDEBUG_MODE: "develop,debug,coverage"
Expand Down
2 changes: 1 addition & 1 deletion .kube/app/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "IRIS Accessibility Exchange"
health: /
health: /status/db
cronjobs:
- name: schedule
schedule: "* * * * *"
Expand Down
37 changes: 37 additions & 0 deletions app/Console/Commands/MaintenanceModeQueueCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Console\Commands;

use App\Jobs\BringSiteBackUp;
use Illuminate\Console\Command;

class MaintenanceModeQueueCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'maintenance:queue';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Put the site into maintenance mode and bring it back up after 5 minutes';

/**
* Execute the console command.
*/
public function handle()
{
// Put the site into maintenance mode
$this->call('down');

// Schedule bringing the site back up after 5 minutes
BringSiteBackUp::dispatch()->delay(now()->addMinutes(5));
Comment on lines +32 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you mentioned in your comment on the ticket that lifecycle hooks aren't possible at the moment in your infrastructure. I'm just wondering if there really isn't a way to know when the old pod is removed and to trigger the artisan up call then. Unfortunately adding a delay doesn't adequately address the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We weren't able to come up with an alternative.


$this->info('The site is in maintenance mode. It will be brought back up in 5 minutes.');
}
}
3 changes: 2 additions & 1 deletion app/Http/Middleware/PreventRequestsDuringMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PreventRequestsDuringMaintenance extends Middleware
* @var array<int, string>
*/
protected $except = [
//
'status',
'status/db',
];
}
31 changes: 31 additions & 0 deletions app/Jobs/BringSiteBackUp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Artisan;

class BringSiteBackUp implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
Artisan::call('up');
}
}