我让部署程序作为 GitHub Action 管道的一部分运行。我想让管道为我运行 NPM 构建并将其复制为部署的一部分,而不是让部署程序在服务器上使用 npm dev 依赖项。对于我想在获取生产版本时使用调试版本core
的网站。stage
prod
完整的 deploy.php 如下:
<?php
namespace Deployer;
require 'recipe/laravel.php';
require 'recipe/rsync.php';
require 'recipe/discord.php';
// Project name
set('application', 'xxxxxxxxxx');
// Project repository
set('repository', 'git@github.com:xxxxxxxxxx');
// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);
set('allow_anonymous_stats', false);
set('dev_db', false);
set('dev_js_mode', 'prod');
set('rsync_src', __DIR__ . '/public/');
set('rsync_dest', '{{release_path}}/public/');
set('discord_channel', 'xxxxxxxxxx');
set('discord_token', 'xxxxxxxxxx');
// Hosts
host('core')
->hostname('xxxxxxxxxx.com')
->user('xxxxxxxxxx')
->set('deploy_path', '/home/xxxxxxxxxx.com')
->set('branch', 'master')
->set('dev_db', true)
->set('dev_js_mode', 'dev');
host('stage')
->hostname('xxxxxxxxxx')
->user('xxxxxxxxxx')
->set('deploy_path', '/home/xxxxxxxxxx.com')
->set('branch', 'stage')
->set('dev_js_mode', 'dev');
host('prod')
->hostname('xxxxxxxxxx.com')
->user('xxxxxxxxxx')
->set('deploy_path', '/home/xxxxxxxxxx.com')
->set('branch', 'prod');
// Custom Tasks
task('reload', function () {
run('sudo systemctl restart php7.2-fpm');
run('sudo systemctl restart nginx');
});
task('database', function() {
$freshDb = get('dev_db');
if ($freshDb === true) {
run('composer run refresh-db --working-dir={{release_path}}/');
} else {
invoke('artisan:migrate');
}
});
task('local:javascript:package', function() {
run('npm ci');
run('npm run {{dev_js_mode}}');
})->local();
task('local:javascript:deploy', [
'rsync',
]);
task('local:javascript', [
'local:javascript:package',
'local:javascript:deploy',
]);
// modifications
before('deploy:symlink', 'local:javascript');
before('deploy:symlink', 'database');
after('deploy', 'reload');
after('rollback', 'reload');
after('deploy:failed', 'deploy:unlock');
before('deploy', 'discord:notify');
after('success', 'discord:notify:success');
after('deploy:failed', 'discord:notify:failure');
我将dev_js_mode
变量默认设置为“prod”,以确保调试版本不会出现在我不想要的地方。
如果我运行,dep -vvv deploy core
我可以看到该local:javascript:package
步骤已dev_js_mode
设置为“prod”,这是因为该命令未在主机上运行,但我无法找到使其工作的方法。