我正在尝试将新应用程序部署到App Engine(标准环境)。这是我使用 GitHub 操作部署的 Laravel 11、PHP 8.3 应用程序。
问题是,它已成功上传到 Google Cloud,但 Cloud Build 未检测到它应该运行
composer install
。我检查了构建日志并看到了这一点:
在 build 步骤中,我以前的应用程序(Laravel 9,PHP 8.2)始终运行检测器,它发现它需要运行 Composer:
===> DETECTING
Timer: Detector started at 2024-05-27T00:01:25Z
5 of 6 buildpacks participating
google.php.runtime 0.0.2
google.php.composer-install 0.0.1
google.php.composer 0.9.1
google.php.appengine 0.9.0
google.utils.label-image 0.0.2
Timer: Detector ran for 179.182403ms and ended at 2024-05-27T00:01:25Z
现在我的 Laravel 11,PHP 8.3 在 build 步骤中只有这个:
===> DETECTING
Timer: Detector started at 2024-05-26T21:41:32Z
3 of 6 buildpacks participating
google.php.runtime 0.0.2
google.php.appengine 0.9.0
google.utils.label-image 0.0.2
Timer: Detector ran for 175.726391ms and ended at 2024-05-26T21:41:32Z
现在,根据 Cloud Docs,如果您需要
autoload.php
,Composer 会自动运行(对于 public/index.php
中的 Laravel 应用程序来说也是如此)。
对于上下文,这是我的
.github/workflows/v2.yml
:
name: V2 Deployment
on:
push:
branches:
- v2
jobs:
build:
name: 📦 Build the App
runs-on: ubuntu-latest
steps:
- name: 💾 Get the latest code
uses: actions/checkout@v4
- name: 🧩 Build the frontend
run: |
npm install
npm run build
- name: 📤 Upload frontend
uses: actions/upload-artifact@v4
with:
name: frontend
path: public/build
deploy_staging:
name: 🦺 Deploy to staging (v2)
runs-on: ubuntu-latest
environment: staging
needs: build
permissions:
id-token: write
contents: read
steps:
- name: 💾 Get the latest code
uses: actions/checkout@v4
- name: 📥 Download frontend
uses: actions/download-artifact@v4
with:
name: frontend
path: public/build
- name: 🔑 Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.GCLOUD_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.GCLOUD_SERVICE_ACCOUNT }}
- name: 🚀 Deploy to App Engine
uses: google-github-actions/deploy-appengine@v2
with:
project_id: ${{ vars.GCLOUD_PROJECT }}
version: v2
deliverables: .github/workflows/appengine/staging.yaml
gcloud_component: beta
flags: --no-cache
这是我的
.github/workflows/appengine/staging.yaml
:
runtime: php83
env: standard
service: staging
handlers:
- url: /(.*\.(bmp|gif|png|jpg|jpeg|png|ico))$
static_files: public/\1
upload: public/.*\.(bmp|gif|png|jpg|jpeg|png|ico)$
- url: /(.*\.ico)$
static_files: public/\1
upload: public/.*\.icon$
- url: /(.*\.mp4)$
mime_type: video/mp4
static_files: public/\1
upload: public/.*\.mp4$
- url: /(.*\.css)$
mime_type: text/css
static_files: public/\1
upload: public/.*\.css$
- url: /(.*\.js)$
mime_type: application/javascript
static_files: public/\1
upload: public/.*\.js$
- url: /(.*\.json)$
mime_type: application/json
static_files: public/\1
upload: public/.*\.json$
- url: /(.*\.(svg|svgz))$
mime_type: image/svg+xml
static_files: public/\1
upload: public/.*\.(svg|svgz)$
- url: /(.*\.txt)$
mime_type: text/plain
static_files: public/\1
upload: public/.*\.txt$
- url: /(.*\.ttf)$
mime_type: font/ttf
static_files: public/\1
upload: public/.*\.ttf$
- url: /(.*\.woff2)$
mime_type: font/woff2
static_files: public/\1
upload: public/.*\.woff2$
- url: /(.*\.map)$
mime_type: application/json
static_files: public/\1
upload: public/.*\.map$
env_variables:
VIEW_COMPILED_PATH: /tmp
CACHE_STORAGE_PATH: /tmp/framework/cache/data
(注意:
service: staging
中的staging.yaml
是有效的,因为我已经部署了具有有效dispatch.yaml
的V1)。
嗯,奥卡姆剃刀永远不会停止给我留下深刻的印象。问题是我的
v2.yml
不在应用程序的根目录中。我认为这不会成为问题,因为我尝试设置working_directory: ./
(请参阅操作的输入)。但它是...
因此,对于那些痴迷于整理代码库的开发人员来说,这是我在
🚀 Deploy to App Engine
之前添加的缺失步骤:
- name: 📑 Move the GAE deliverables
run: |
mv .github/workflows/appengine/staging.yaml app.yaml
mv .github/workflows/appengine/dispatch.yaml dispatch.yaml
然后调整可交付成果的路径:
- name: 🚀 Deploy to App Engine
uses: google-github-actions/deploy-appengine@v2
with:
project_id: ${{ vars.GCLOUD_PROJECT }}
version: v2
deliverables: app.yaml dispatch.yaml
PS:它给 Cloud Composer 带来了另一个问题:
Problem 1
Step #2 - "build": - laravel/framework is locked to version v11.0.5 and an update of this package was not requested.
Step #2 - "build": - laravel/framework v11.0.5 requires composer-runtime-api ^2.2 -> found composer-runtime-api[2.1.0] but it does not match the constraint.
...所以我还必须将其添加到部署步骤中:
build_env_vars:
GOOGLE_COMPOSER_VERSION=2.2.1