部署者:从没有存储库的本地机器部署

Deployer: Deploy from local machine without repository

所以我正在尝试使用 deployer 将我的本地文件部署到服务器。

但是我不确定部署器究竟是如何工作的,因为它似乎需要一个 GIT 存储库——我不想使用它。在文档中,我真的找不到太多关于我的问题的信息。

我的问题: 如何在没有 git-repository 的情况下使用部署程序。只需将我的本地文件推送到服务器/多个服务器即可。

我使用安装了部署程序的 Symfony4,一切正常,直到出现以下错误:

fatal: repository '/var/www/project/releases/1' does not exist

谢谢


deployer.php

<?php
namespace Deployer;

require 'recipe/symfony.php';

// Project name
set('application', 'project');

// Project repository
//set('repository', '');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);

// Shared files/dirs between deploys 
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server 
add('writable_dirs', []);
set('allow_anonymous_stats', false);

// Hosts

host('x.x.x.x') //IP of host
    ->user('www-data')
    ->set('deploy_path', '/var/www/project');

// Tasks

task('build', function () {
    run('cd {{release_path}} && build');
});

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.

before('deploy:symlink', 'database:migrate');

如果您不想从头开始编写部署任务,deployer/recipes 包提供了 rsync recipe 可以将您的项目传输到您的主机而无需 git.

如上文所述,您可以使用 rsync 配方或简单地用类似这样的东西覆盖 deploy:update_code

task('deploy:update_code', function () {
    writeln("<info>Uploading files to server</info>");
    upload('./< some path >', '{{release_path}}');
});

有时我只需要将一些文件推送到远程,为此我创建了一个任务:

use Symfony\Component\Console\Input\InputOption;

option('source', null, InputOption::VALUE_OPTIONAL, 'Source alias of the current task.');
option('target', null, InputOption::VALUE_OPTIONAL, 'Target alias of the current task.');

task('upload:file', function() {
    /*
    * Usage: dep upload:file --source="some_destination/file.txt" --target="some_destination/" host
    */

    $source = null;
    $target = null;

    if (input()->hasOption('source')) {
        $source = input()->getOption('source');
    }

    if (input()->hasOption('target')) {
        $target = input()->getOption('target');
    }
    if (askConfirmation('Upload file ' . $source . ' to release/' . $target . ' ?')) {
        upload('/< some place >' . $source, '{{release_path}}/' . $target);
    }
});