new deployer command
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Exceptions\DatabaseStageException;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use RuntimeException;
|
||||
|
||||
class DatabaseStage extends Command
|
||||
{
|
||||
@@ -133,13 +133,13 @@ class DatabaseStage extends Command
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"pg_dump failed:\n" . $result->errorOutput(),
|
||||
);
|
||||
}
|
||||
|
||||
if (! file_exists($localDump) || filesize($localDump) === 0) {
|
||||
throw new RuntimeException('Database dump was not created or is empty.');
|
||||
throw new DatabaseStageException('Database dump was not created or is empty.');
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -166,7 +166,7 @@ class DatabaseStage extends Command
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"Invalid PostgreSQL archive:\n" . $result->errorOutput(),
|
||||
);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class DatabaseStage extends Command
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"Upload failed:\n" . $result->errorOutput(),
|
||||
);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ SQL;
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"Unable to recreate stage database:\n" .
|
||||
$result->errorOutput(),
|
||||
);
|
||||
@@ -299,7 +299,7 @@ SQL;
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"Database restore failed:\n" .
|
||||
$result->errorOutput(),
|
||||
);
|
||||
@@ -345,7 +345,7 @@ SQL;
|
||||
]);
|
||||
|
||||
if ($result->failed()) {
|
||||
throw new RuntimeException(
|
||||
throw new DatabaseStageException(
|
||||
"Database verification failed:\n" .
|
||||
$result->errorOutput(),
|
||||
);
|
||||
|
||||
+15
-12
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Deployer;
|
||||
|
||||
require_once 'recipe/laravel.php';
|
||||
require 'recipe/laravel.php';
|
||||
|
||||
set('writable_use_sudo', true);
|
||||
set('clear_use_sudo', true);
|
||||
@@ -12,6 +12,9 @@ set('repository', 'git@git.absdev.net:mag/WMS.git');
|
||||
set('node_version', '22.12.0');
|
||||
set('allow_anonymous_stats', false);
|
||||
|
||||
const RELEASE_CD = 'cd {{release_path}} && ';
|
||||
const DEPLOY_SYMLINK = 'deploy:symlink';
|
||||
|
||||
add('shared_files', ['.env']);
|
||||
add('shared_dirs', ['storage']);
|
||||
add('writable_dirs', ['storage', 'bootstrap/cache']);
|
||||
@@ -70,30 +73,30 @@ task('build', function (): void {
|
||||
});
|
||||
|
||||
task('queue:restart', function (): void {
|
||||
run('cd {{release_path}} && php artisan queue:restart');
|
||||
run(RELEASE_CD . 'php artisan queue:restart');
|
||||
});
|
||||
|
||||
task('deploy:write_revision_file', function (): void {
|
||||
run('cd {{release_path}} && echo "{{branch}}" > BRANCH');
|
||||
run('cd {{release_path}} && date -u +"%Y-%m-%dT%H:%M:%SZ" > DEPLOYED_AT');
|
||||
run(RELEASE_CD . 'echo "{{branch}}" > BRANCH');
|
||||
run(RELEASE_CD . 'date -u +"%Y-%m-%dT%H:%M:%SZ" > DEPLOYED_AT');
|
||||
});
|
||||
|
||||
task('artisan:clear', function (): void {
|
||||
run('cd {{release_path}} && php artisan view:clear');
|
||||
run('cd {{release_path}} && php artisan optimize:clear');
|
||||
run('cd {{release_path}} && php artisan config:clear');
|
||||
run('cd {{release_path}} && php artisan route:clear');
|
||||
run(RELEASE_CD . 'php artisan view:clear');
|
||||
run(RELEASE_CD . 'php artisan optimize:clear');
|
||||
run(RELEASE_CD . 'php artisan config:clear');
|
||||
run(RELEASE_CD . 'php artisan route:clear');
|
||||
});
|
||||
|
||||
task('services:restart', function (): void {
|
||||
run('sudo -n nginx -t');
|
||||
run('sudo -n systemctl reload nginx');
|
||||
run('sudo -n systemctl restart php8.3-fpm');
|
||||
run('sudo -n systemctl restart php8.4-fpm');
|
||||
});
|
||||
|
||||
after('deploy:update_code', 'deploy:write_revision_file');
|
||||
after('deploy:vendors', 'build');
|
||||
after('deploy:symlink', 'artisan:clear');
|
||||
after('deploy:symlink', 'queue:restart');
|
||||
after(DEPLOY_SYMLINK, 'artisan:clear');
|
||||
after(DEPLOY_SYMLINK, 'queue:restart');
|
||||
after('deploy:failed', 'deploy:unlock');
|
||||
after('deploy:symlink', 'services:restart');
|
||||
after(DEPLOY_SYMLINK, 'services:restart');
|
||||
|
||||
Reference in New Issue
Block a user