affordablemobiles / g-serverless-support-laravel
Google Serverless runtime support for Laravel apps
Installs: 748
Dependents: 0
Suggesters: 0
Security: 0
Stars: 26
Watchers: 5
Forks: 17
Open Issues: 0
Requires
- php: ^8.3
- affordablemobiles/eloquent-datastore: ~11
- affordablemobiles/eloquent-sqlcommenter: ~11
- affordablemobiles/open-telemetry-operations-php: ~1
- google/cloud: >=0.239.0 <1.0.0
- guzzlehttp/guzzle: ^7.8.1
- kelvinmo/simplejwt: ^0.8.2
- laravel/framework: ~11
- open-telemetry/sdk: ~1
Requires (Dev)
Suggests
- a1comms/php-gds: Provides legacy Datastore support
- barryvdh/laravel-debugbar: Laravel Debugbar
- lcobucci/jwt: JWT library can be used with IAMSigner
Conflicts
Replaces
- a1comms/gae-support-laravel: v11.0.16
- dev-php8.3-laravel11.x
- v11.0.16
- v11.0.15
- v11.0.14
- v11.0.13
- v11.0.12
- v11.0.11
- v11.0.10
- v11.0.9
- v11.0.8
- v11.0.7
- v11.0.6
- v11.0.5
- v11.0.4
- v11.0.3
- v11.0.2
- v11.0.1
- v11.0.0
- v9.0.48
- v9.0.47
- v9.0.46
- v9.0.45
- v9.0.44
- v9.0.43
- v9.0.42
- v9.0.41
- v9.0.40
- v9.0.39
- v9.0.38
- v9.0.37
- v9.0.36
- v9.0.35
- v9.0.34
- v9.0.33
- v9.0.32
- v9.0.31
- v9.0.30
- v9.0.29
- v9.0.28
- v9.0.27
- v9.0.26
- v9.0.25
- v9.0.24
- v9.0.23
- v9.0.22
- v9.0.21
- v9.0.20
- v9.0.19
- v9.0.18
- v9.0.17
- v9.0.16
- v9.0.15
- v9.0.14
- v9.0.13
- v9.0.12
- v9.0.11
- v9.0.10
- v9.0.9
- v9.0.8
- v9.0.7
- v9.0.6
- v9.0.5
- v9.0.4
- v9.0.3
- v9.0.2
- v9.0.1
- v6.0.41
- v6.0.39
- v6.0.38
- v6.0.37
- v6.0.36
- v6.0.35
- v6.0.34
- v6.0.33
- v6.0.32
- v6.0.31
- v6.0.30
- v6.0.29
- v6.0.28
- v6.0.27
- v6.0.26
- v6.0.25
- v6.0.24
- v6.0.23
- v6.0.22
- v6.0.21
- v6.0.20
- v6.0.19
- v6.0.18
- v6.0.17
- v6.0.16
- v6.0.15
- v6.0.14
- v6.0.13
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v5.5.49
- v5.5.48
- v5.5.47
- v5.5.46
- v5.5.45
- v5.5.44
- 5.5.43
- v5.5.42
- v5.5.41
- v5.5.40
- v5.5.39
- v5.5.38
- v5.5.37
- v5.5.36
- v5.5.35
- v5.5.34
- v5.5.33
- v5.5.32
- v5.5.31
- v5.5.30
- v5.5.29
- v5.5.28
- v5.5.27
- v5.5.26
- v5.5.25
- v5.5.24
- v5.5.23
- v5.5.22
- v5.5.21
- v5.5.20
- v5.5.19
- v5.5.18
- v5.5.17
- v5.5.16
- v5.5.15
- v5.5.14
- v5.5.13
- v5.5.12
- v5.5.11
- v5.5.10
- v5.5.9
- v5.5.8
- v5.5.7
- v5.5.6
- v5.5.5
- v5.5.4
- v5.5.3
- v5.5.2
- v5.5.1
- 5.1.27
- 5.1.26
- 5.1.25
- 5.1.24
- 5.1.23
- 5.1.22
- 5.1.21
- 5.1.20
- 5.1.19
- 5.1.18
- 5.1.17
- 5.1.16
- 5.1.15
- 5.1.14
- 5.1.13
- 5.1.12
- 5.1.11
- 5.1.10
- 5.1.9
- 5.1.8
- 5.1.7
- 5.1.6
- v5.1.5
- 5.1.4
- 5.1.3
- v5.1.2
- 5.1.1
- 5.1.0
- dev-iamacarpet/exception-handler-outside-gcp
- dev-php8.1-laravel9.x
- dev-bug/ApplicationBuilderNamespace
- dev-error-reporting-exception-handling
- dev-php7.4-laravel6.0
- dev-php72-laravel55
- dev-php55-laravel51-compat
This package is auto-updated.
Last update: 2024-11-08 13:18:54 UTC
README
Google Serverless runtime support package for Laravel 11.x.
Supporting Cloud Run & App Engine (Standard Environment) with the php83
runtime.
Based on original work for App Engine (GaeSupportL5 using the php55
runtime) by @shpasser.
Functionality
- Google Cloud Operations Suite integration
- Cloud Logging destination with structured logs (see docs/logging.md).
- Error Reporting integration for aggregation of reported exceptions (see docs/logging.md).
- Cloud Trace (via opentelemetry) (see docs/trace.md)
- Distributed trace propagation via Guzzle.
- Integration with laravel-debugbar (optional, see docs/debugbar.md).
- Identity Aware Proxy (IAP) integration
- Inbound authentication via Laravel's Guards (optional, see docs/iap-auth-verify.md).
- Outbound authentication via Guzzle middleware (optional, see docs/guzzle.md).
- Cloud SQL integration
- IAM Authentication (optional, see docs/cloud-sql.md).
- Automatic failover between read replicas (optional, see docs/cloud-sql.md).
- Query Insights integration via eloquent-sqlcommenter (optional, see docs/cloud-sql.md).
- Cloud Firestore in Datastore mode integration
- Session handler (optional, see docs/sessions.md).
- Eloquent driver via eloquent-datastore.
- Optimizations for containerized deployment
bootstrap/cache
generation before deployment (see g-serverless:prepare).- Blade View Pre-Compiler (optional, see docs/blade-pre-compile.md)
- Automatic retries for outbound connections on network layer failure with Guzzle (optional, see docs/guzzle.md)
- Domain Wide Delegation (DWD) support via IAM Credentials API (no key file required).
- IAMSigner for lcobucci/jwt using IAM Credentials API.
- Examples for push-to-deploy from Git via Cloud Build with Secret Manager (see docs/cloudbuild.md)
Installation
1. Pull in the package via Composer:
"require": { "affordablemobiles/g-serverless-support-laravel": "~11" }
2. Add the following to composer.json
:
"scripts": { "post-autoload-dump": [ "php artisan g-serverless:prepare" ] },
This is to automatically run the artisan command that prepares our app for deployment after composer finishes running: this creates any necessary cache files and if enabled, pre-compiles all of the blade views.
If you are deploying with Cloud Build, composer install
is likely to run just before packaging/deployment to your chosen serverless product, so this will ensure everything else required runs as part of that step.
3. Update the use
statement at the top of bootstrap/app.php
from:
use Illuminate\Foundation\Application;
to:
use AffordableMobiles\GServerlessSupportLaravel\Foundation\Application;
This will enable automatic exception reporting to Cloud Logging & Error Reporting, alongside adjusting the emergency logger to work correctly inside the containerized environment by writing to stderr
.
Important: the Logging API & the Trace API need to be enabled within your project, and the service account being used by your serverless app needs to have IAM permissions to use them:
- Enable the Logs API - append
?project=<project-name>
to the URL if necessary. - Assign the IAM permission "Logs Writer" to your service account.
- Enable the Trace API - append
?project=<project-name>
to the URL if necessary. - Assign the IAM permission "Cloud Trace Agent" to your service account.
4. Configure the service providers within config/app.php
by adding:
/* |-------------------------------------------------------------------------- | Autoloaded Service Providers |-------------------------------------------------------------------------- | | The service providers listed here will be automatically loaded on any | requests to your application. You may add your own services to the | arrays below to provide additional features to this application. | */ 'providers' => \Illuminate\Support\ServiceProvider::defaultProviders()->merge([ // Package Service Providers... \AffordableMobiles\GServerlessSupportLaravel\GServerlessSupportServiceProvider::class, \AffordableMobiles\GServerlessSupportLaravel\Auth\AuthServiceProvider::class, \AffordableMobiles\GServerlessSupportLaravel\Database\DatabaseServiceProvider::class, ])->replace([ \Illuminate\View\ViewServiceProvider::class => \AffordableMobiles\GServerlessSupportLaravel\View\ViewServiceProvider::class, ])->toArray(),
5. Add the following environment variables:
This can be done either in .env
, inside app.yaml
, or as part of the Cloud Run service configuration - we recommend the latter two options where possible.
LOG_CHANNEL=stderr
LOG_STDERR_FORMATTER=AffordableMobiles\GServerlessSupportLaravel\Log\Formatter\JsonFormatter
CACHE_STORE=array
SESSION_DRIVER=datastore
When using Cloud Tasks, you'll also want to configure:
CLOUD_TASKS_REGION=europe-west1 (or similar, required)
TASK_QUEUE_SERVICE_ACCOUNT=<project-name>@appspot.gserviceaccount.com (default, required for Cloud Run)
OIDC_AUDIENCE=<OAuth2 Client ID used by IAP, if enabled for inbound calls to your app> (required for Cloud Run)
If you are using an external CDN such as Cloudflare, also configure the following environment variable with the name of the HTTP header used for passing the client's IP address:
SOURCE_IP_HEADER=CF-Connecting-IP
And if you need to disable OpenTelemetry tracing (we highly recommend you leave it enabled), define the following environment variable:
G_SERVERLESS_TRACE_STOP=true
Also, if running in a development environment, please also set the following:
G_SERVERLESS_DEVELOPMENT=true
This does several things, such as:
- Alters the local storage location to include
HTTP_HOST
. - Turns OpenTelemetry tracing on for every request.
- Turns off sticky database connections per instance.
Upgrading (from Laravel 9.x LTS)
1. Update the package version in composer.json
:
"require": { "affordablemobiles/g-serverless-support-laravel": "~11" }
2. Follow the Laravel upgrade steps for all versions 9.x ... 11.x
3. Update any references in your code to our namespace:
A1comms\GaeSupportLaravel
has changed to:
AffordableMobiles\GServerlessSupportLaravel
4. Ensure bootstrap/app.php
is extending our Application
class:
Please see step 3 in the main installation guide as an example.
5. Change to the new provider configuration format in config/app.php
:
Please see step 4 in the main installation guide as an example.
6. Update explicit/silent exception reporting:
Anywhere referencing the Error Reporting integration class directly:
AffordableMobiles\GServerlessSupportLaravel\Integration\ErrorReporting::exceptionHandler($e);
should be updated to report using Laravel's new method:
report($e);
7. Revert config/logging.php
to the Laravel default.
8. Update environment variables:
Please see step 5 in the main installation guide & update your environment variables accordingly.
9. If you are using php-gds
for Datastore, consider switching to eloquent-datastore.
Otherwise, you'll need to require it via composer yourself, as it is no longer required by this repository.
10. If using the lcobucci/jwt
compatible DWDTokenSource, it has now been removed.
Migrate to the google/auth
compatible GCEDWDCredentials.
11. Update your app.yaml
file(s) to specify runtime: php83
.