yeebase / readiness
Requires
- neos/flow: ~4.3 || ~5.0
Requires (Dev)
- t3n/coding-standard: dev-master
This package is auto-updated.
Last update: 2019-05-03 09:16:42 UTC
README
Yeebase.Readiness
用于检查流程应用程序就绪状态的包。
在 Kubernetes 就绪和活跃性探针 中很有用,以确定 Pod 是否可以服务流量并且是活跃的。
使用方法
就绪性
简单执行流程命令 ./flow app:isready
。
这将执行在 Settings.yaml 中的 Yeebase.Readiness.testChain
定义的 所有测试。如果所有测试都通过,将执行 readyChain
任务。
就绪链成功运行后,将设置一个内部锁以防止重复执行,因此只会再次执行 readyChain
。每次运行都会执行 testChain
。因此就绪链应将您的应用程序置于“就绪状态”。请确保初始化所有需要的内容。testChain 应对该应用程序所依赖的所有服务进行ping。
活跃性
执行 ./flow app:isalive
检查您的 Pod 是否仍然活跃。
这将执行 Yeebase.Readiness.livenessChain
。
默认情况下,活跃链为空,有一个可能的测试:statusCode
。
配置
将所有测试按照以下格式添加到您的应用程序 Settings.yaml 中
Yeebase: Readiness: testChain: yourUniqueTestKey: name: 'Optional name' test: 'database' // shorthand for a predefined task in Yeebase\Readiness\Test\*.Test or a full qualified class name options: key: 'value' // optional options for your test position: 'after otherTestKey' // optional position
之后,检查将执行就绪链
Yeebase: Readiness: readyChain: yourUniqueTaskKey: name: 'Optional name' task: 'command' // shorthand for a predefined task in Yeebase\Readiness\Task\*.Task or a full qualified class name options: key: 'value' // optional options for your task position: 'after otherTaskKey' / optional position lockName: 'mylock' // optional lock override. This will create a lock for this task only and ignore the global lock
就绪链成功调用后,您可以调用 ./flow app:isalive
来执行活跃链
Yeebase: Readiness: livenessChain: yourUniqueTestKey: name: 'Optional name' task: 'statusCode' // shorthand for a predefined task in Yeebase\Readiness\LivenessTest\*.Test or a full qualified class name options: key: 'value' // optional options for your task position: 'after otherTaskKey' / optional position
高级配置
在尝试执行每个就绪任务之前,检查将测试 Yeebase.Readiness.defaultReadyTaskCondition
以查看是否应执行任务。在默认配置中,这只是一个检查就绪锁是否尚未设置的检查。
您可以根据任务逐个覆盖此行为
Yeebase: Readiness: readyChain: yourUniqueTaskKey: condition: '${Lock.isSet("mylock")}' // this can be any eel expression afterInvocation: '${Lock.set("mylock")}' // this will be executed after a successfull invocation
(lockName
设置只是上述示例的简写)
要扩展 eel 上下文,您可以在 Yeebase.Readiness.defaultContext
中提供额外的助手。
示例配置
此示例可用于您的 Flow 包,以确保您的应用程序 Pod 处于就绪状态以供流量使用。因此,它将始终检查 doctrine、redis 和 beanstalk 的 ping 状态。在第一次运行时,将执行所有缺失的数据库迁移,清除 redis 缓存并发布静态资源。成功运行后,将再次执行 testChain。
Yeebase: Readiness: testChain: database: test: doctrine position: start redis: test: redis options: hostmane: your-redis-host beanstalk: test: beanstalk options: hostname: your-beanstalk-host readyChain: migrations: task: command options: command: 'neos.flow:doctrine:migrate' flushRedis: name: 'Flush redis' position: 'start 100' task: redis options: hostname: your-redis-host command: FLUSHDB database: 0 staticResources: name: 'Publish static resources' task: command position: 'end 20' lockname: staticresources cacheName: Yeebase_Readiness_LocalLock options: command: 'neos.flow:resource:publish' arguments: collection: static livenessChain: home: task: statusCode name: 'Homepage responds' options: url: '/' method: 'GET' statusCode: 200
注意 lockname
配置。此配置允许您在每个部署中只运行一次任务或始终运行。默认情况下,使用 Yeebase_Readiness_Lock
缓存来读取和写入锁。将其添加到您的 Caches.yaml,并且所有应用程序 Pod 都将依赖于相同的锁文件,因为它们不使用本地文件存储,而是使用 redis。这将导致每个部署只执行一次。
Yeebase_Readiness_Lock: backend: Neos\Cache\Backend\RedisBackend backendOptions: hostname: 'your-redis-server' database: 2
《staticResources》任务配置了自定义的cacheName。为确保此任务在每个应用Pod中执行,请将其设置为本地文件存储
Yeebase_Readiness_LocalLock: frontend: Neos\Cache\Frontend\StringFrontend backend: Neos\Cache\Backend\FileBackend