digipolisgent / robo-digipolis-deploy
Robo Task Runner 的部署任务
Requires
- consolidation/robo: ^3.0 || ^4.0
- digipolisgent/command-builder: ^1.2
- digipolisgent/robo-digipolis-general: ^2.0.0
- district09/backup-manager: ^4.0
- gordalina/cachetool: ^8.0 || ^9.0
- phpseclib/phpseclib: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5.20
- dev-develop
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.1.0-rc10
- 0.1.0-rc9
- 0.1.0-rc8
- 0.1.0-rc7
- 0.1.0-rc6
- 0.1.0-rc5
- 0.1.0-rc4
- 0.1.0-rc3
- 0.1.0-rc2
- 0.1.0-rc1
- 0.1.0-beta1
- 0.1.0-alpha2
- 0.1.0-alpha1
- dev-master
- dev-1.x-dev
This package is auto-updated.
Last update: 2024-09-23 09:21:45 UTC
README
Robo Task Runner 的部署任务
本包中的任务
PushPackage
$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa'); $result = $this->taskPushPackage('192.168.1.1', $auth) ->port(8022) ->timeout(15) ->destinationFolder('/folder/on/server') ->package('/path/to/local/package.tar.gz') ->run();
SFTP
$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa'); $result = $this->taskSFTP('192.168.1.1', $auth) ->port(8022) ->timeout(15) // Download file from server. ->get('/path/to/remote/file.txt', '/path/to/local/file.txt') // Upload file to server. ->put('/path/to/remote/file.txt', '/path/to/local/file.txt') ->run();
Ssh
$auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa'); $result = $this->taskSsh('192.168.1.1', $auth) ->port(8022) ->timeout(15) // Set the remote directory to execute the commands in. ->remoteDirectory('/path/to/remote/dir') ->exec('composer install') ->run();
SymlinkFolderFileContents
$result = $this ->taskSymlinkFolderFileContents('/path/to/source', '/path/to/destination') ->run();
由于此命令很可能会在部署期间用于在服务器上创建符号链接配置文件,因此应在服务器上运行的命令中使用此任务。例如
服务器上的 RoboFile.php(假设为 192.168.1.1,位于 /path/to/remote/dir 文件夹中)
<?php class RoboFile extends \Robo\Tasks { use \DigipolisGent\Robo\Task\Deploy\loadTasks; /** * Creates the symlinks. */ public function symlinks($source, $dest) { $this ->taskSymlinkFolderFileContents($source, $dest) ->run(); } }
构建服务器上的 RoboFile.php 或您的本地计算机
<?php class RoboFile extends \Robo\Tasks { use \DigipolisGent\Robo\Task\Deploy\loadTasks; /** * Creates the symlinks. */ public function symlinks($source, $dest) { $auth = new \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\KeyFile('user', '/home/myuser/.ssh/id_dsa'); $this->taskSsh('192.168.1.1', $auth) ->port(8022) ->timeout(15) ->remoteDirectory('/path/to/remote/dir') ->exec('vendor/bin/robo symlink ' . $source . ' ' . $dest) ->run(); } }
数据库备份
$filesystemConfig = [ 'local' => [ 'type' => 'Local', 'root' => '/home/myuser/backups', ], ]; $dbConfig = [ 'development' => [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', 'singleTransaction' => true, 'ignoreTables' => [], ], 'production' => [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', 'ignoreTables' => [], 'structureTables' => [], 'tables' => [], 'dataOnly' => false, 'orderedDump' => false, 'singleTransaction' => true, 'extra' => '--opt', ], ]; // Store a backup of the development database in /home/myuser/backups/dev.sql.tar.gz. $result = $this->taskDatabaseBackup($filesystemConfig, $dbConfig) ->database('development') ->destination('dev.sql') ->compression('tar') ->run();
数据库恢复
$filesystemConfig = [ 'local' => [ 'type' => 'Local', 'root' => '/home/myuser/backups', ], ]; $dbConfig = [ 'development' => [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', 'singleTransaction' => true, 'ignoreTables' => [], ], 'production' => [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', 'ignoreTables' => [], 'structureTables' => [], 'tables' => [], 'dataOnly' => false, 'orderedDump' => false, 'singleTransaction' => true, 'extra' => '--opt', ], ]; // Restore a backup of the development database located at /home/myuser/backups/dev.sql.tar.gz. $result = $this->taskDatabaseRestore($filesystemConfig, $dbConfig) ->database('development') ->source('dev.sql.tar.gz') ->compression('tar') ->run();
文件系统配置选项
有关文件系统配置选项的更多信息,请参阅 https://github.com/backup-manager/backup-manager。
数据库配置选项
有关数据库配置选项的更多信息,请参阅 https://github.com/backup-manager/backup-manager。然而,我们提供了自己的 MySql 数据库处理器。以下是对配置选项的说明
$dbConfig = [ 'production' => [ // Specify it's a mysql database. 'type' => 'mysql', // Specify the database credentials. 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => 'password', 'database' => 'test', // Tables to exclude from the export. This option will be ignored if the // 'tables' configuration option is set, because all tables will be // excluded except the ones specified in the 'tables' option. Therefore, // adding a table to the 'ignoreTables' would be the same as omitting it // from tbe 'tables' option if that option has a non-empty) value. 'ignoreTables' => [], // Tables to only export the table structure for. A good example would // be a cache table, since most of the time you wouldn't want this // table's data in a backup. The structure of the tables specified here // will be exported even if the 'tables' configuration options has a // (non-empty) value and these tables are not in it. 'structureTables' => [], // Tables to export. Leave empty to export all tables (except those // specified in the 'ignoreTables' configuration option). 'tables' => [], // Export only data, not table structure. 'dataOnly' => false, // Order by primary key and add line breaks for efficient diff in // revision control. Slows down the dump. 'orderedDump' => false, // If singleTransaction is set to true, the --single-transcation flag // will be set. This is useful on transactional databases like InnoDB. // https://dev.mysqlserver.cn/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction 'singleTransaction' => true, // Extra options to pass to mysqldump (e.g. '--opt --quick'). 'extra' => '--opt', ], ];
本包中的命令
此包提供默认命令,您可以在您的 RoboFile.php
中使用,如下所示
class RoboFile extends \Robo\Tasks { use \DigipolisGent\Robo\Task\Deploy\Commands\loadCommands; }
digipolis:database-backup
vendor/bin/robo digipolis:database-backup [DATABASE] [OPTIONS]
使用事件进行默认配置
为 digipolis-db-config 事件实现一个 on-event hook,以返回该命令使用的数据库配置 如上所述。例如
/** * @hook on-event digipolis-db-config */ public function defaultDbConfig() { $dbConfig = []; $dbConfig['default'] = [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => '$up3r$3cr3tP@$$w0rD', 'database' => 'my_database', 'structureTables' => [], 'extra' => '--skip-add-locks --no-tablespaces', ]; return $dbConfig; }
参数
DATABASE
数据库配置键。有关更多详细信息,请参阅上面。在给定的示例中,此参数必须是 'production'。默认为 'default'。
选项
--file-system-config, -fsconf
包含文件系统配置的 PHP 文件的路径,如 https://github.com/backup-manager/backup-manager 中所述。默认为本地文件系统的根目录。
--database-config, -dbconf
包含数据库配置的 PHP 文件的路径,如 https://github.com/backup-manager/backup-manager 中所述。默认为当前工作目录名称的数据库名称,在 localhost
端口 3306
上,用户 root
和空密码。
--compression, -c
用于此备份的压缩方式。默认为 tar
。
--destination, -d
此备份的目标文件。默认为当前工作目录中的 project.tar.gz
。
--destination-type, -dtype
目标类型(例如 local
、dropbox
、ftp
)。默认为 local
。
digipolis:database-restore
vendor/bin/robo digipolis:database-restore [DATABASE] [OPTIONS]
使用事件进行默认配置
为 digipolis-db-config 事件实现一个 on-event hook,以返回该命令使用的数据库配置 如上所述。例如
/** * @hook on-event digipolis-db-config */ public function defaultDbConfig() { $dbConfig = []; $dbConfig['default'] = [ 'type' => 'mysql', 'host' => 'localhost', 'port' => '3306', 'user' => 'root', 'pass' => '$up3r$3cr3tP@$$w0rD', 'database' => 'my_database', 'structureTables' => [], 'extra' => '--skip-add-locks --no-tablespaces', ]; return $dbConfig; }
参数
DATABASE
数据库配置键。有关更多详细信息,请参阅上面。在给定的示例中,此参数必须是 'production'。默认为 'default'。
选项
--file-system-config, -fsconf
包含文件系统配置的 PHP 文件的路径,如 https://github.com/backup-manager/backup-manager 中所述。默认为本地文件系统的根目录。
--database-config, -dbconf
包含数据库配置的 PHP 文件的路径,如 https://github.com/backup-manager/backup-manager 中所述。默认为当前工作目录名称的数据库名称,在 localhost
端口 3306
上,用户 root
和空密码。
--compression, -c
给定备份的压缩方式。默认为 tar
。
--source, -s
要恢复的源文件。默认为当前工作目录中的 project.tar.gz
。
--source-type, -stype
源类型(例如 local
、dropbox
、ftp
)。默认为 local
。
digipolis:push-package
vendor/bin/robo digipolis:push-package 用户 主机 包 [目标] [选项]
参数
用户
连接到主机的用户。
主机
要连接的主机。
包
要推送的包(tar文件)。
目标
服务器上的目标文件夹。默认为用户的家目录。
选项
--password
连接到主机的密码。
--key-file
连接到主机时使用的私钥文件。
--port
连接的端口号。默认为22
。
--timeout
连接的超时时间(秒)。默认为10
。