This commit is contained in:
parent
eb25d2c34e
commit
2a8b6bc397
@@ -34,11 +34,11 @@ framework:
|
|||||||
assets:
|
assets:
|
||||||
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
|
||||||
|
|
||||||
#when@prod:
|
when@prod:
|
||||||
# webpack_encore:
|
webpack_encore:
|
||||||
# # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
|
||||||
# # Available in version 1.2
|
# Available in version 1.2
|
||||||
# cache: true
|
cache: true
|
||||||
|
|
||||||
#when@test:
|
#when@test:
|
||||||
# webpack_encore:
|
# webpack_encore:
|
||||||
|
|||||||
83
deploy.php
83
deploy.php
@@ -9,9 +9,9 @@ set('repository', "https://{$giteaToken}@git.homelab.nestor-server.fr/colgora/Ma
|
|||||||
set('keep_releases', 3);
|
set('keep_releases', 3);
|
||||||
set('composer_options', '--no-dev --optimize-autoloader --no-interaction --prefer-dist --ignore-platform-reqs --no-scripts');
|
set('composer_options', '--no-dev --optimize-autoloader --no-interaction --prefer-dist --ignore-platform-reqs --no-scripts');
|
||||||
|
|
||||||
// Copier vendor/ et node_modules/ depuis la release précédente (hard links, quasi instantané)
|
// Copier vendor/ depuis la release précédente (hard links, quasi instantané)
|
||||||
// Composer et npm ne mettent à jour que ce qui a changé → déploiements beaucoup plus rapides
|
// node_modules est géré par le shared mount /srv/mangarr/shared/node_modules
|
||||||
set('copy_dirs', ['vendor', 'node_modules']);
|
set('copy_dirs', ['vendor']);
|
||||||
|
|
||||||
// Pas de shared_files ni shared_dirs : tout est géré par les volumes Docker
|
// Pas de shared_files ni shared_dirs : tout est géré par les volumes Docker
|
||||||
set('shared_files', []);
|
set('shared_files', []);
|
||||||
@@ -31,17 +31,86 @@ task('deploy:prepare_dirs', function () {
|
|||||||
|
|
||||||
// composer install via container éphémère (pas de PHP sur l'hôte requis)
|
// 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
|
// --user assure que vendor/ appartient au user deploy et non root
|
||||||
|
// Skip si composer.lock inchangé et vendor/ déjà populé (hard-linké depuis la release précédente)
|
||||||
task('deploy:vendors', function () {
|
task('deploy:vendors', function () {
|
||||||
|
$releaseDir = get('release_path');
|
||||||
|
$previousDir = get('previous_release');
|
||||||
|
|
||||||
|
if ($previousDir !== null) {
|
||||||
|
$lockUnchanged = test("diff -q $previousDir/composer.lock $releaseDir/composer.lock > /dev/null 2>&1");
|
||||||
|
$vendorPopulated = test("[ -d $releaseDir/vendor/composer ]");
|
||||||
|
|
||||||
|
if ($lockUnchanged && $vendorPopulated) {
|
||||||
|
writeln('<info>deploy:vendors skipped — composer.lock unchanged</info>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
run('docker run --rm --user $(id -u):$(id -g) -v {{release_path}}:/app -w /app composer:2 install {{composer_options}}');
|
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
|
// Build assets via container node éphémère
|
||||||
// Le cache webpack (node_modules/.cache) est persisté dans shared/webpack_cache entre les releases
|
// 3 couches d'optimisation :
|
||||||
// → 1er build lent, suivants compilent uniquement les modules modifiés
|
// 1. Skip total si aucun fichier front-end n'a changé (hard-link public/build/)
|
||||||
|
// 2. Skip npm install si package-lock.json inchangé (node_modules partagé persistant)
|
||||||
|
// 3. Cache npm et webpack persistants entre les releases
|
||||||
desc('Build Webpack Encore assets');
|
desc('Build Webpack Encore assets');
|
||||||
task('webpack_encore:build', function () {
|
task('webpack_encore:build', function () {
|
||||||
run('mkdir -p /srv/mangarr/shared/webpack_cache');
|
$sharedDir = '/srv/mangarr/shared';
|
||||||
run('docker run --rm --user $(id -u):$(id -g) -e npm_config_cache=/tmp/npm-cache -e PUPPETEER_SKIP_DOWNLOAD=1 -v {{release_path}}:/app -v /srv/mangarr/shared/webpack_cache:/app/node_modules/.cache -w /app node:22-alpine sh -c "npm install && npm run build"');
|
$sharedWebpackCache = "$sharedDir/webpack_cache";
|
||||||
|
$sharedNodeModules = "$sharedDir/node_modules";
|
||||||
|
$sharedNpmCache = "$sharedDir/npm_cache";
|
||||||
|
|
||||||
|
run("mkdir -p $sharedWebpackCache $sharedNodeModules $sharedNpmCache");
|
||||||
|
|
||||||
|
$releaseDir = get('release_path');
|
||||||
|
$previousDir = get('previous_release'); // null au 1er déploiement
|
||||||
|
|
||||||
|
// --- COUCHE 1 : skip total si aucun fichier front-end n'a changé ---
|
||||||
|
if ($previousDir !== null) {
|
||||||
|
$watchList = ['assets', 'templates', 'package.json', 'package-lock.json',
|
||||||
|
'webpack.config.js', 'postcss.config.js', 'tailwind.config.js'];
|
||||||
|
|
||||||
|
$diffChecks = implode(' && ', array_map(
|
||||||
|
fn($p) => "diff -rq --no-dereference $previousDir/$p $releaseDir/$p > /dev/null 2>&1",
|
||||||
|
$watchList
|
||||||
|
));
|
||||||
|
|
||||||
|
$hasPreviousBuild = test("[ -d $previousDir/public/build ] && [ -f $previousDir/public/build/manifest.json ]");
|
||||||
|
|
||||||
|
if ($hasPreviousBuild && test("($diffChecks)")) {
|
||||||
|
run("cp -al $previousDir/public/build $releaseDir/public/build");
|
||||||
|
writeln('<info>webpack_encore:build skipped — no front-end files changed</info>');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- COUCHE 2 : skip npm install si package-lock.json inchangé ---
|
||||||
|
$needsNpmInstall = true;
|
||||||
|
if ($previousDir !== null) {
|
||||||
|
$lockUnchanged = test("diff -q $previousDir/package-lock.json $releaseDir/package-lock.json > /dev/null 2>&1");
|
||||||
|
$nmPopulated = test("[ -d $sharedNodeModules/.bin ]");
|
||||||
|
if ($lockUnchanged && $nmPopulated) {
|
||||||
|
$needsNpmInstall = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- COUCHE 3 : build docker avec caches persistants ---
|
||||||
|
$installCmd = $needsNpmInstall
|
||||||
|
? 'npm install --prefer-offline && npm run build'
|
||||||
|
: 'npm run build';
|
||||||
|
|
||||||
|
run("docker run --rm \
|
||||||
|
--user \$(id -u):\$(id -g) \
|
||||||
|
-v $releaseDir:/app \
|
||||||
|
-v $sharedNodeModules:/app/node_modules \
|
||||||
|
-v $sharedWebpackCache:/app/node_modules/.cache \
|
||||||
|
-v $sharedNpmCache:/npm_cache \
|
||||||
|
-e npm_config_cache=/npm_cache \
|
||||||
|
-e PUPPETEER_SKIP_DOWNLOAD=1 \
|
||||||
|
-w /app \
|
||||||
|
node:22-alpine \
|
||||||
|
sh -c '$installCmd'");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Restart Docker containers (entrypoint gère les migrations automatiquement)
|
// Restart Docker containers (entrypoint gère les migrations automatiquement)
|
||||||
|
|||||||
Reference in New Issue
Block a user