Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4ce4134a6 |
+59
-73
@@ -45,7 +45,6 @@ host('prod')
|
|||||||
->set('deploy_path', '/opt/laravel-sites/absdev-net/deploy')
|
->set('deploy_path', '/opt/laravel-sites/absdev-net/deploy')
|
||||||
->set('labels', ['stage' => 'production']);
|
->set('labels', ['stage' => 'production']);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Helpers
|
| Helpers
|
||||||
@@ -57,8 +56,8 @@ function absdevCompose(): string
|
|||||||
$root = get('absdev_root');
|
$root = get('absdev_root');
|
||||||
|
|
||||||
return 'docker compose'
|
return 'docker compose'
|
||||||
. ' -f ' . $root . '/compose.yaml'
|
.' -f '.$root.'/compose.yaml'
|
||||||
. ' -f ' . $root . '/compose.deployer.yaml';
|
.' -f '.$root.'/compose.deployer.yaml';
|
||||||
}
|
}
|
||||||
|
|
||||||
function absdevReleasePath(): string
|
function absdevReleasePath(): string
|
||||||
@@ -67,14 +66,14 @@ function absdevReleasePath(): string
|
|||||||
$deployPath = get('deploy_path');
|
$deployPath = get('deploy_path');
|
||||||
$containerRoot = get('absdev_container_root');
|
$containerRoot = get('absdev_container_root');
|
||||||
|
|
||||||
if (!str_starts_with($hostPath, $deployPath . '/releases/')) {
|
if (! str_starts_with($hostPath, $deployPath.'/releases/')) {
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
'Unexpected release path: ' . $hostPath
|
'Unexpected release path: '.$hostPath
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $containerRoot
|
return $containerRoot
|
||||||
. substr($hostPath, strlen($deployPath));
|
.substr($hostPath, strlen($deployPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
function absdevArtisan(string $command): void
|
function absdevArtisan(string $command): void
|
||||||
@@ -83,15 +82,14 @@ function absdevArtisan(string $command): void
|
|||||||
|
|
||||||
run(
|
run(
|
||||||
absdevCompose()
|
absdevCompose()
|
||||||
. ' exec -T -u www-data php'
|
.' exec -T -u www-data php'
|
||||||
. ' sh -c '
|
.' sh -c '
|
||||||
. escapeshellarg(
|
.escapeshellarg(
|
||||||
'cd ' . $path . ' && php artisan ' . $command
|
'cd '.$path.' && php artisan '.$command
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Production preflight
|
| Production preflight
|
||||||
@@ -105,30 +103,30 @@ task('absdev:preflight', function (): void {
|
|||||||
$deploy = get('deploy_path');
|
$deploy = get('deploy_path');
|
||||||
$compose = absdevCompose();
|
$compose = absdevCompose();
|
||||||
|
|
||||||
run('test -f ' . $root . '/compose.deployer.yaml');
|
run('test -f '.$root.'/compose.deployer.yaml');
|
||||||
run('test -f ' . $root . '/nginx.deployer.conf');
|
run('test -f '.$root.'/nginx.deployer.conf');
|
||||||
|
|
||||||
run('test -L ' . $deploy . '/current');
|
run('test -L '.$deploy.'/current');
|
||||||
run('test -f ' . $deploy . '/shared/.env');
|
run('test -f '.$deploy.'/shared/.env');
|
||||||
run('test -d ' . $deploy . '/shared/storage');
|
run('test -d '.$deploy.'/shared/storage');
|
||||||
|
|
||||||
run($compose . ' config --quiet');
|
run($compose.' config --quiet');
|
||||||
|
|
||||||
foreach (['php', 'web'] as $service) {
|
foreach (['php', 'web'] as $service) {
|
||||||
$check = 'test -f /var/www/deploy/current/public/index.php';
|
$check = 'test -f /var/www/deploy/current/public/index.php';
|
||||||
|
|
||||||
run(
|
run(
|
||||||
$compose
|
$compose
|
||||||
. ' exec -T ' . $service
|
.' exec -T '.$service
|
||||||
. ' sh -c ' . escapeshellarg($check)
|
.' sh -c '.escapeshellarg($check)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the PHP container is using the release tree.
|
// Ensure the PHP container is using the release tree.
|
||||||
run(
|
run(
|
||||||
$compose
|
$compose
|
||||||
. ' exec -T php sh -c '
|
.' exec -T php sh -c '
|
||||||
. escapeshellarg(
|
.escapeshellarg(
|
||||||
'test -f /var/www/deploy/current/artisan'
|
'test -f /var/www/deploy/current/artisan'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -136,14 +134,13 @@ task('absdev:preflight', function (): void {
|
|||||||
// Ensure Nginx is serving the release-aware document root.
|
// Ensure Nginx is serving the release-aware document root.
|
||||||
run(
|
run(
|
||||||
$compose
|
$compose
|
||||||
. ' exec -T web nginx -T 2>&1'
|
.' exec -T web nginx -T 2>&1'
|
||||||
. ' | grep -Fq "root /var/www/deploy/current/public;"'
|
.' | grep -Fq "root /var/www/deploy/current/public;"'
|
||||||
);
|
);
|
||||||
|
|
||||||
writeln('<info>Docker deployment preflight passed.</info>');
|
writeln('<info>Docker deployment preflight passed.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Composer
|
| Composer
|
||||||
@@ -159,17 +156,16 @@ desc('Install production Composer dependencies');
|
|||||||
task('absdev:composer', function (): void {
|
task('absdev:composer', function (): void {
|
||||||
run(
|
run(
|
||||||
'cd {{release_path}}'
|
'cd {{release_path}}'
|
||||||
. ' && composer install'
|
.' && composer install'
|
||||||
. ' --no-dev'
|
.' --no-dev'
|
||||||
. ' --prefer-dist'
|
.' --prefer-dist'
|
||||||
. ' --no-interaction'
|
.' --no-interaction'
|
||||||
. ' --no-progress'
|
.' --no-progress'
|
||||||
. ' --optimize-autoloader'
|
.' --optimize-autoloader'
|
||||||
. ' --no-scripts'
|
.' --no-scripts'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Vite
|
| Vite
|
||||||
@@ -220,7 +216,6 @@ SH;
|
|||||||
writeln('<info>Production Vite assets built.</info>');
|
writeln('<info>Production Vite assets built.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Release permissions
|
| Release permissions
|
||||||
@@ -237,32 +232,31 @@ task('absdev:permissions', function (): void {
|
|||||||
$path = escapeshellarg(absdevReleasePath());
|
$path = escapeshellarg(absdevReleasePath());
|
||||||
|
|
||||||
$script = 'set -eu; '
|
$script = 'set -eu; '
|
||||||
. 'dir=' . $path . '/bootstrap/cache; '
|
.'dir='.$path.'/bootstrap/cache; '
|
||||||
. 'mkdir -p "$dir"; '
|
.'mkdir -p "$dir"; '
|
||||||
. 'owner=$(stat -c %u ' . $path . '); '
|
.'owner=$(stat -c %u '.$path.'); '
|
||||||
. 'chown -R "$owner":33 "$dir"; '
|
.'chown -R "$owner":33 "$dir"; '
|
||||||
. 'chmod -R ug+rwX "$dir"; '
|
.'chmod -R ug+rwX "$dir"; '
|
||||||
. 'chmod g+s "$dir"';
|
.'chmod g+s "$dir"';
|
||||||
|
|
||||||
run(
|
run(
|
||||||
absdevCompose()
|
absdevCompose()
|
||||||
. ' exec -T -u root php sh -c '
|
.' exec -T -u root php sh -c '
|
||||||
. escapeshellarg($script)
|
.escapeshellarg($script)
|
||||||
);
|
);
|
||||||
|
|
||||||
run(
|
run(
|
||||||
absdevCompose()
|
absdevCompose()
|
||||||
. ' exec -T -u www-data php sh -c '
|
.' exec -T -u www-data php sh -c '
|
||||||
. escapeshellarg(
|
.escapeshellarg(
|
||||||
'test -w ' . $path . '/storage'
|
'test -w '.$path.'/storage'
|
||||||
. ' && test -w ' . $path . '/bootstrap/cache'
|
.' && test -w '.$path.'/bootstrap/cache'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
writeln('<info>Laravel permissions verified.</info>');
|
writeln('<info>Laravel permissions verified.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Laravel preparation
|
| Laravel preparation
|
||||||
@@ -283,7 +277,6 @@ task('absdev:laravel:prepare', function (): void {
|
|||||||
writeln('<info>Laravel release prepared.</info>');
|
writeln('<info>Laravel release prepared.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Revision information
|
| Revision information
|
||||||
@@ -303,23 +296,22 @@ task('absdev:revision', function (): void {
|
|||||||
|
|
||||||
run(
|
run(
|
||||||
'printf %s\\n '
|
'printf %s\\n '
|
||||||
. escapeshellarg($revision)
|
.escapeshellarg($revision)
|
||||||
. ' > {{release_path}}/REVISION'
|
.' > {{release_path}}/REVISION'
|
||||||
);
|
);
|
||||||
|
|
||||||
run(
|
run(
|
||||||
'date -u +%Y-%m-%dT%H:%M:%SZ'
|
'date -u +%Y-%m-%dT%H:%M:%SZ'
|
||||||
. ' > {{release_path}}/DEPLOYED_AT'
|
.' > {{release_path}}/DEPLOYED_AT'
|
||||||
);
|
);
|
||||||
|
|
||||||
writeln(
|
writeln(
|
||||||
'<info>Release revision: '
|
'<info>Release revision: '
|
||||||
. $revision
|
.$revision
|
||||||
. '</info>'
|
.'</info>'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Release validation
|
| Release validation
|
||||||
@@ -338,7 +330,6 @@ task('absdev:validate', function (): void {
|
|||||||
writeln('<info>Release files validated.</info>');
|
writeln('<info>Release files validated.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Database migrations
|
| Database migrations
|
||||||
@@ -356,12 +347,11 @@ desc('Run production database migrations');
|
|||||||
task('absdev:migrate', function (): void {
|
task('absdev:migrate', function (): void {
|
||||||
run(
|
run(
|
||||||
absdevCompose()
|
absdevCompose()
|
||||||
. ' exec -T -u www-data php'
|
.' exec -T -u www-data php'
|
||||||
. ' php artisan migrate --force'
|
.' php artisan migrate --force'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| PHP-FPM
|
| PHP-FPM
|
||||||
@@ -375,12 +365,11 @@ task('absdev:migrate', function (): void {
|
|||||||
desc('Restart Docker PHP-FPM to clear OPcache');
|
desc('Restart Docker PHP-FPM to clear OPcache');
|
||||||
|
|
||||||
task('absdev:php:restart', function (): void {
|
task('absdev:php:restart', function (): void {
|
||||||
run(absdevCompose() . ' restart php');
|
run(absdevCompose().' restart php');
|
||||||
|
|
||||||
writeln('<info>Docker PHP-FPM restarted.</info>');
|
writeln('<info>Docker PHP-FPM restarted.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Post-deployment
|
| Post-deployment
|
||||||
@@ -394,18 +383,17 @@ task('absdev:refresh', function (): void {
|
|||||||
|
|
||||||
run(
|
run(
|
||||||
$compose
|
$compose
|
||||||
. ' exec -T -u www-data php'
|
.' exec -T -u www-data php'
|
||||||
. ' php artisan view:clear'
|
.' php artisan view:clear'
|
||||||
);
|
);
|
||||||
|
|
||||||
run(
|
run(
|
||||||
$compose
|
$compose
|
||||||
. ' exec -T -u www-data php'
|
.' exec -T -u www-data php'
|
||||||
. ' php artisan queue:restart'
|
.' php artisan queue:restart'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Health check
|
| Health check
|
||||||
@@ -420,17 +408,16 @@ desc('Check production HTTP response');
|
|||||||
task('absdev:health', function (): void {
|
task('absdev:health', function (): void {
|
||||||
run(
|
run(
|
||||||
'curl --fail --silent --show-error'
|
'curl --fail --silent --show-error'
|
||||||
. ' --max-time 20'
|
.' --max-time 20'
|
||||||
. ' -H ' . escapeshellarg('Host: absdev.net')
|
.' -H '.escapeshellarg('Host: absdev.net')
|
||||||
. ' -H ' . escapeshellarg('Cache-Control: no-cache')
|
.' -H '.escapeshellarg('Cache-Control: no-cache')
|
||||||
. ' -o /dev/null'
|
.' -o /dev/null'
|
||||||
. ' http://127.0.0.1:8101/'
|
.' http://127.0.0.1:8101/'
|
||||||
);
|
);
|
||||||
|
|
||||||
writeln('<info>Production HTTP health check passed.</info>');
|
writeln('<info>Production HTTP health check passed.</info>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Deployment sequence
|
| Deployment sequence
|
||||||
@@ -471,7 +458,6 @@ after('deploy:failed', 'deploy:unlock');
|
|||||||
after('rollback', 'absdev:php:restart');
|
after('rollback', 'absdev:php:restart');
|
||||||
after('rollback', 'absdev:health');
|
after('rollback', 'absdev:health');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Repair Laravel cache ownership before release cleanup
|
| Repair Laravel cache ownership before release cleanup
|
||||||
@@ -505,8 +491,8 @@ SH;
|
|||||||
|
|
||||||
run(
|
run(
|
||||||
absdevCompose()
|
absdevCompose()
|
||||||
. ' exec -T -u root php sh -c '
|
.' exec -T -u root php sh -c '
|
||||||
. escapeshellarg($script)
|
.escapeshellarg($script)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user