bomoko/algm_drutiny_profile
核心ALGM插件库,包含我们运行Drutiny审计所使用的策略和配置文件
Requires
- drutiny/plugin-drupal-7: ^2.3
- drutiny/plugin-drupal-8: ^2.3
- mlocati/ip-lib: ^1.14
- spatie/ssl-certificate: ^1.20
Requires (Dev)
- dantleech/fink: ^0.10.1
- drutiny/drutiny: ^2.4
- phpunit/phpunit: ^9.2
- squizlabs/php_codesniffer: ^3.5
- dev-master
- v1.2.1
- v1.2.0
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.1
- v1.0.0
- v0.0.2
- v0.0.1
- dev-feature/SRE-94-check-mails-not-sent-on-non-prod
- dev-package-only
- dev-storage_space
- dev-drutiny-3.x
This package is auto-updated.
Last update: 2024-08-27 14:50:14 UTC
README
此插件提供了一组标准策略集合,这些集合可以被Drutiny使用。
设置
-
git clone git@github.com:AmazeeLabs/algm_drutiny.git
-
composer install -o
-
需要Drush - https://docs.drush.org/en/9.x/install/
We also need Drush locally (preferably Drush 9+). There are also a couple of things you need to ensure your drush alias files have in order to get this working with Drutiny which we will cover below.
If you have drush but need to update to Drush 9 way of things, then this is your friend:
https://stackoverflow.com/questions/55587919/where-drush-9-aliases-file-should-be-located-in-drupal-8
To install globally in terminal (But aware that this will affect previous Drush setup)
In your user folder.
$ `composer global require drush/drush:^9`
- 在 ~/.drush/ 中设置Drush文件夹结构
~/.drush/
- cache/ (might not be there)
- commands/ (might not be there)
- sites/ ( Add this Drush Alias folder. This is where you add your sitename.site.yml for each sites you'll connect to.)
- drush.yml
- drush.yml should have:
drush:
paths:
alias-path:
- '${env.home}/.drush/sites'
- 测试Drutiny是否运行 -
./vendor/bin/drutiny
这是什么?
此存储库是Drutiny的插件,意味着它作为扩展添加到核心Drutiny中,然后我们将其构建、发布并作为单个phar文件运行。因此,此插件为我们提供了一种添加我们自己的策略、配置文件、格式化程序以及其他任何我们喜欢的内容的方法,以便扩展现有的Drutiny功能。
文档对此解释得很好 - https://drutiny.readthedocs.io/en/2.x/README/
- 策略 - https://drutiny.readthedocs.io/en/2.x/policy/
- 配置文件 - https://drutiny.readthedocs.io/en/2.x/profiles/
工作流程
要添加策略/配置文件或以任何方式扩展我们的Drutiny插件,我们需要做几件事
- 确保我们本地有最新版本(获取并拉取以确保)
- 添加我们需要的内容,提交并推送到PR或master(取决于是否需要测试)
- 可以通过此存储库中的
drupal-web
docker实例进行测试,或者通过使用远程drush别名并直接运行它们来测试。当然,如果您不确定预期结果,请谨慎在生产站点上运行操作。 - 一旦推送到master,并且您对测试/工作正常感到满意,那么我们需要创建一个新的标签。
- 从远程获取所有标签,并检查列表,使用
git tag v1.0.x
等命令添加新标签,如果您喜欢,还可以使用-a
标志添加注释。然后使用git push origin --tags
推送到我们的origin。 - 这将触发我们拥有的phar构建github动作。您可以在这里看到此构建 - https://github.com/AmazeeLabs/algm_drutiny/actions
- 将构建新版本 - 检查构建输出以查看您的策略是否在其中。您还可以在本地上传phar并在本地站点上运行它以检查其是否按预期工作。
- 然后我们将在我们的ansible/awx playbooks中使用最新的版本!
使用Drutiny
在Drutiny中有两个核心命令:policy:audit和profile:run。
policy:audit
此命令将在目标(通常是drush目标)上运行策略,将执行我们想要运行的检查。
基本来说,我们需要提供一个策略(例如 algm:ModuleUpdates
)和一个目标(例如 drush别名 @site-prod.site-name
)。我们还可以传递选项,例如 --format
,它定义了输出格式。参数/默认值也可以通过 -p
标志传递给策略,例如 -p module=8.6.8
。
policy:audit [options] [--] <policy> <target>
最终命令可能如下所示: ./vendor/bin/drutiny policy:audit algm:ModuleUpdates @site-prod.site-name --format=markdown
profile:run
此命令将在目标上运行配置文件,将遍历并检查整个策略套件。
对于配置文件,我们需要提供一个配置文件名(例如 algm_sla_site
)和一个目标(例如 drush 别名 @site-prod.site-name
)。我们还可以传递一些选项,例如 '--format',它定义了输出格式。
profile:run [选项] [--] <配置文件> <目标>
最终的命令可能看起来像这样:./vendor/bin/drutiny profile:run algm_sla_site @site-prod.site-name --format==markdown
添加新策略
要添加新策略,我们需要两个文件:一个新策略 yaml 文件添加在这里(https://github.com/AmazeeLabs/algm_drutiny/tree/master/Policies)以及一个新的 Audit 类添加在这里(https://github.com/AmazeeLabs/algm_drutiny/tree/master/src/Audit)
策略详情
最重要的是,我们有 $sandbox
对象,它是执行我们策略的运行时对象。
exec
exec
是一个方法,它将访问远程 shell 并执行给定的命令 - 例如 $output = $sandbox->exec('ls -la');
drush
Drush 可以通过 drush
方法运行。Drutiny 支持这里使用驼峰命名 - 例如 $list = $sandbox->drush(['format' => 'json'])->pmList();
如果提供 json 格式,Drutiny 将解析响应并以 PHP 格式返回输出。
Drush 别名
一个 Drush 9 别名文件示例
prod:
host: ssh.lagoon.amazeeio.cloud
root: /app/web
user: site-prod
remote-host: ssh.lagoon.amazeeio.cloud
remote-user: site-prod
ssh-options: '-o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 32222'
请注意,这只是一个示例,您应该只使用这些值来更新 drush 别名以便与 Drutiny 一起使用,而不是完全替换它。
在此存储库中还有一个 example.drush.alias.yml
。
不要忘记在更改或添加新站点别名时清除 drush 缓存 - drush cc
有关更多配置选项 - 这很有用 https://github.com/drush-ops/drush/blob/master/examples/example.site.yml
有用事物
检查我们可用的策略列表:./vendor/bin/drutiny policy:list
检查配置文件列表:./vendor/bin/drutiny profile:list
您可能需要清除 Drutiny 缓存:./vendor/bin/drutiny cache:clear
开发和测试
在包内有一个 Drupal 安装,您可以在这里测试您的策略。请遵循 drupal-web/README.md 文件