ueberdosis/laravel-docker-health-check
最新稳定版本:0.4.0
Composer 安装命令:
composer require ueberdosis/laravel-docker-health-check
包简介
README 文档
README
A simple package that makes it easier to work with Laravel and Docker in production.
Installation
Install it with composer:
composer require ueberdosis/laravel-docker-health-check
Add the Middleware to your app/Http/Kernel.php:
class Kernel extends HttpKernel { /** * The application's global HTTP middleware stack. * * These middleware are run during every request to your application. * * @var array */ protected $middleware = [ // ... \Ueberdosis\DockerHealthCheck\Middleware\ClearCacheOnInitialRequest::class, ]; // ... }
Update your health check script to curl the newly registered route /docker-health-check. The following is an example health check script, please update your own implementation:
#!/usr/bin/env bash set -e if [ $(curl -o /dev/null -L -s -w "%{http_code}\n" http://localhost/docker-health-check) = "200" ]; then exit 0 else exit 1 fi
What problem is this package solving?
When using Laravel with Docker in production you would normally write a huge entrypoint script that runs migrations, clears caches and so on. But clearing caches in this entrypoint script doesn't work well. Why?
Well, the orchestrator waits for the Laravel container to become healthy before directing actual traffic to it. So when you update your stack, the old container will handle all the traffic at the moment when you call php artisan view:clear in your entrypoint up to the moment when the new container is healthy. When traffic hits the site in that moment, the cache will be rebuilt in the old container.
This is a huge pain on big dockerized Laravel apps. This package will clear caches on the first request to a new container by using a temporary file in the app root.
And it conveniently registers a nice /docker-health-check route for you that returns a response with status code 200 for your health check script.
License
MIT
统计信息
- 总下载量: 3.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-04