icanhazstring / duck-pony
秘密鸭马
0.7.0
2023-02-27 09:15 UTC
Requires
- php: ^8.1
- icanhazstring/systemctl-php: ^0.8
- icanhazstring/tempa-php: 2.2.0
- laminas/laminas-config: ^3.8
- league/container: ^4.0
- lesstif/php-jira-rest-client: ^5.0
- monolog/monolog: ^2.0
- symfony/console: ^5.0
- symfony/filesystem: ^6.0
- symfony/finder: ^6.0
Requires (Dev)
- ext-openssl: *
- ext-pdo: *
- phpspec/prophecy: 1.x-dev
- phpspec/prophecy-phpunit: 2.0.x-dev
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-openssl: Required for slack logging (see config/autoload/logger.config.php.dist)
- ext-pdo: Required for CleanMySQLDatabaseCommand
README
duck-pony
是一个用于管理集成服务器实例的小型维护工具。它与 Atlassian Jira 链接,以检索执行哪些操作的信息。
这些操作包括
- 清理分支
- 清理MySQL数据库
- 清除服务
- 删除孤立符号链接
安装
要使用此工具,只需将其克隆或下载到您的集成服务器上。
请注意,某些命令需要某种类型的
root
执行权限(例如,使用systemctl
关闭服务)
首先使用 composer 安装所有必需的包。(您可能想跳过开发包)
$ composer install --no-dev
要配置您的 config.yml
,请使用包含在此工具中的 icanhazstring/tempa-php。
$ vendor/bin/tempa file:substitute \ config/ \ tempa.json \ jira_host=JIRA_HOST \ jira_username=JIRA_USER \ jira_password=JIRA_PASSWORD \ pattern=BRANCH_PATTERN_REGEX \ db_host=DB_HOST \ db_username=DB_USER \ db_password=DB_PASSWORD \ instance_pattern=SYSTEMD_SERVICE_PATTERN \ slack_token=SLACK_TOKEN \ slack_channel=SLACK_CHANNEL
pattern
用于识别票证和文件夹。这意味着,您的文件夹 必须 与 Jira 板上的票证名称相同。
如果设置了 slack_token 和 slack_channel,则带有临界或更高级别的日志消息将发送到此 Slack 频道
命令
清理分支
$ bin/dp folder:clean --help Description: Scan folder an clean branches Usage: folder:clean [options] [--] <folder> Arguments: folder Folder branchname-filter Remove parts of the folder name to match jira ticket Options: -s, --status=STATUS Status -p, --pattern=PATTERN Branch pattern --keep-days[=KEEP-DAYS] The number of days a branch is allowed to remain. -i, --invert Invert status -y, --yes Confirm questions with yes -c, --config=CONFIG Config [default: "/home/vendor/duck-pony/config/config.yml"] -f, --force Force delete -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --branchname-filter Remove parts of the branchname for better jira ticket matching Help: Scan folder iterate over sub folders and removes them under certain conditions
示例:清理所有当前不是“进行中”、“已重新打开”、“待办”或“审查中”的分支。
$ bin/dp folder:clean /path/to/folder --status="reopened,open,in progress,in review" --invert --yes
清除服务
Description: Scan folder an purge services with same name Usage: service:purge [options] [--] <folder> Arguments: folder Deployment folder as reference Options: -u, --unit=UNIT Name of unit -p, --pattern=PATTERN Instance pattern -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: Disables and stops systemd services that have no reference folder in given folder argument
示例:清除所有不在扫描文件夹中存在的 awesome
服务的 systemd
/path/to/folder
|- ABC-123
systemd services:
- awesome@ABC-124
- awesome@ABC-125
执行此命令
$ bin/dp service:purge /path/to/folder --unit=awesome@'
将删除以下 systemd 服务
- awesome@ABC-124
- awesome@ABC-125
删除孤立符号链接
Description: Removes orphaned symlinks of a given folder Usage: symlinks:remove_orphaned <folder> Arguments: folder Folder Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: Removes only orphaned symlinks under a given folder without any recursion.
示例:删除 nginx 网站启用下的所有孤立符号链接
$ bin/dp symlinks:remove_orphaned /etc/nginx/sites-enabled
清理MySQL数据库
$ bin/dp db:clean --help Description: Scans Database and cleans orphaned Usage: db:clean [options] [--] <pattern> Arguments: branchname-filter Remove parts of the folder name to match jira ticket Options: -s, --status=STATUS Status -p, --pattern=PATTERN Branch pattern -i, --invert Invert status -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: Scans MySQL Databases and removes them under certain conditions
示例:清理所有当前不是“进行中”、“已重新打开”、“待办”或“审查中”的票证的数据库。
$ bin/dp db:clean --status="reopened,open,in progress,in review" --invert rsv_feature- rsv_bugfix-