codegreencreative / laravel-heroku-deploy
为您的 Heroku 审查应用设置 post deploy 和 pr pre destroy 脚本。
Requires
- php: ^7.3
- guzzlehttp/guzzle: ^7.4.4
- illuminate/routing: ^7|^8
- illuminate/support: ^7|^8
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^8.5|^9.0
This package is auto-updated.
Last update: 2024-09-10 18:00:10 UTC
README
Laravel Heroku Deploy
此 Laravel 7+ 包允许您配置 Heroku Review Apps 实例以用于 Laravel 应用程序。您可以使用 Cloudflare 管理自定义域名,通过 Let's Encrypt 应用自动化证书管理 (ACM),并使用 Heroku 的 postdeploy 和 pr-predestroy 脚本事件更新 Config Vars。
安装
使用 composer 安装此包
composer require codegreencreative/laravel-heroku-deploy
配置
以下命令将在您的 config 文件夹中添加一个新的 heroku-deploy.php 配置文件。
php artisan vendor:publish --tag="heroky_deploy_config"
heroku-deploy.php
示例 heroku-deploy 配置文件。
// config/heroku-deploy.php return [ // Heroku Platform API token, learn more here: // https://devcenter.heroku.com/articles/authentication 'heroku_token' => env('HEROKU_DEPLOY_HEROKU_TOKEN', null), // Cloudflare token, get yours here: // https://dash.cloudflare.com/profile/api-tokens 'cloudflare_token' => env('HEROKU_DEPLOY_CLOUDFLARE_TOKEN', null), // Created by Heroku, just capture the information 'app_name' => env('HEROKU_APP_NAME', null), 'pr_number' => env('HEROKU_PR_NUMBER', null), // JSON array containing information on your zones you want to use for this project // { // "mydomain.com": ["id", "account", "support", "policies"] // } 'cloudflare_zones' => json_decode(env('HEROKU_DEPLOY_ZONES', '[]'), true), // You can attach addons from other applications // { // "addon_id": "confirming_app (id or name)" // } 'heroku_addon_attachments' => json_decode(env('HEROKU_DEPLOY_ADDON_ATTACHMENTS', '[]'), true), // Enable automated certificate management in Heroku for each subdomain 'enable_acm' => env('HEROKU_DEPLOY_ENABLE_ACM', true) ];
.env
示例 .env 条目。
HEROKU_DEPLOY_HEROKU_TOKEN=addyourtokenehere
HEROKU_DEPLOY_CLOUDFLARE_TOKEN=addyourtokenehere
HEROKU_DEPLOY_ZONES="{\"mydomain.com\": [\"id\", \"account\", \"support\"]}"
# Optional
# This connects Heroku Postgres database or Heroku Redis, for example
HEROKU_DEPLOY_ADDON_ATTACHMENTS="{\"xxxx-xxxx-xxxx-xxxx-xxxx\": \"xxxxxxxxx\"}"
HEROKU_DEPLOY_ENABLE_ACM=false
app.json
将 postdeploy 和 pr-predestroy 命令添加到您的 app.json 文件中。
{
"environments": {
"review": {
"scripts": {
"postdeploy": "php artisan heroku:postdeploy",
"pr-predestroy": "php artisan heroku:pr-predestroy"
}
}
}
}
配置变量
根据您的配置,将添加/更新两个额外的配置变量 APP_BASE_DOMAIN 和 APP_URL。在 HEROKU_DEPLOY_ZONES 中定义的第一个域名将被视为您的 基本/主域名,因为您只能有一个。第一个域名的第一个子域名被视为您的 APP_URL。我们还使用拉取请求编号来保持审查应用的唯一性。拉取请求编号由 Heroku 作为环境变量提供。
例如,以下内容将自动添加到您的环境变量中
APP_BASE_DOMAIN=pr-125.mydomain.com
APP_URL=https://id.pr-125.mydomain.com
如果您未启用 ACM,会话 cookie 将设置为不安全。
SESSION_SECURE_COOKIE=false
会话 cookie 将使用一个唯一的名称创建。
SESSION_COOKIE=PR125_SID
需要添加的其他任何配置变量都可以在您的 Heroku 管道中进行操作。
错误报告
如果已安装 Bugsnag,异常将报告到 Bugsnag。
待办事项
- 检查日志配置以进行错误日志 | bugsnag
- 将默认 herokuapp.com 子域名重定向到根域名