59 lines
2.6 KiB
PHP
59 lines
2.6 KiB
PHP
<?php
|
|
namespace Deployer;
|
|
|
|
require 'recipe/symfony.php';
|
|
|
|
// GITEA_TOKEN injecté depuis le secret Gitea (scope: read:repository)
|
|
$giteaToken = getenv('GITEA_TOKEN') ?: throw new \RuntimeException('GITEA_TOKEN secret is required');
|
|
set('repository', "https://{$giteaToken}@git.homelab.nestor-server.fr/colgora/Mangarr.git");
|
|
set('keep_releases', 3);
|
|
set('composer_options', '--no-dev --optimize-autoloader --no-interaction --prefer-dist --ignore-platform-reqs --no-scripts');
|
|
|
|
// Pas de shared_files ni shared_dirs : tout est géré par les volumes Docker
|
|
set('shared_files', []);
|
|
set('shared_dirs', []);
|
|
set('writable_dirs', []);
|
|
|
|
host('production')
|
|
->set('hostname', getenv('DEPLOY_HOST')) // Injecté depuis le secret Gitea
|
|
->set('remote_user', 'deploy') // User avec accès docker group
|
|
->set('deploy_path', '/srv/mangarr')
|
|
->set('branch', 'main');
|
|
|
|
// Créer les dossiers que Docker doit monter comme volumes (gitignorés, absents de la release)
|
|
task('deploy:prepare_dirs', function () {
|
|
run('mkdir -p {{release_path}}/var {{release_path}}/public/images {{release_path}}/public/cbz {{release_path}}/public/tmp');
|
|
});
|
|
|
|
// composer install via container éphémère (pas de PHP sur l'hôte requis)
|
|
// --user assure que vendor/ appartient au user deploy et non root
|
|
task('deploy:vendors', function () {
|
|
run('docker run --rm --user $(id -u):$(id -g) -v {{release_path}}:/app -w /app composer:2 install {{composer_options}}');
|
|
});
|
|
|
|
// Build assets via container node éphémère
|
|
// --user assure que public/build/ appartient au user deploy et non root
|
|
// mangarr_node_modules volume = cache npm entre les déploiements
|
|
desc('Build Webpack Encore assets');
|
|
task('webpack_encore:build', function () {
|
|
run('docker run --rm --user $(id -u):$(id -g) -v {{release_path}}:/app -v mangarr_node_modules:/app/node_modules -w /app node:22-alpine sh -c "npm install && npm run build"');
|
|
});
|
|
|
|
// Restart Docker containers (entrypoint gère les migrations automatiquement)
|
|
desc('Restart Docker containers');
|
|
task('docker:restart', function () {
|
|
run('docker restart mangarr-worker-commands mangarr-worker-events mangarr-worker-scheduler');
|
|
run('docker restart mangarr');
|
|
});
|
|
|
|
// Pas de PHP sur l'hôte : désactiver les tâches Symfony qui en ont besoin
|
|
// Le cache et les migrations sont gérés par l'entrypoint.sh au démarrage du container
|
|
task('deploy:cache:clear', function () {});
|
|
task('deploy:cache:warmup', function () {});
|
|
|
|
// Hooks
|
|
after('deploy:update_code', 'deploy:prepare_dirs');
|
|
after('deploy:vendors', 'webpack_encore:build');
|
|
after('deploy:symlink', 'docker:restart');
|
|
after('deploy:failed', 'deploy:unlock');
|