0
votes

Recently without any code change except environmental variable in app.yaml, app engine deployments fails during cloud build process where it exceeds memory limit, and I can't understand where can I change it, or why it became a problem... I tried to set "gcp-build" to overwrite composer install command, but getting this error during cloud build:

Step #3 - "detector": ======== Output: google.php.composer-gcp-build@0.9.0 ========
Step #3 - "detector": unmarshalling composer.json: json: cannot unmarshal array into Go struct field     composerScriptsJSON.scripts.gcp-build of type string [id:070ec49f]
Step #3 - "detector": ======== Results ========

Here is my composer.json:

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
    "framework",
    "laravel"
],
"license": "MIT",
"require": {
    "php": "^7.2.5",
    "doctrine/dbal": "^2.10",
    "fideloper/proxy": "^4.2",
    "fruitcake/laravel-cors": "^2.0",
    "google/cloud": "^0.142.0",
    "google/cloud-core": "^1.39",
    "google/cloud-error-reporting": "^0.18.0",
    "google/cloud-firestore": "^1.14",
    "google/cloud-logging": "^1.21",
    "guzzlehttp/guzzle": "^7.0.1",
    "intervention/image": "^2.5",
    "kreait/firebase-php": "^5.0",
    "kreait/firebase-tokens": "^1.10",
    "kreait/laravel-firebase": "^2.2",
    "kyslik/column-sortable": "^6.3",
    "laravel/framework": "^8.0",
    "laravel/tinker": "^2.0",
    "laravel/ui": "^3.0",
    "owen-it/laravel-auditing": "^10.0",
    "predis/predis": "^1.1",
    "propaganistas/laravel-phone": "^4.2",
    "superbalist/laravel-google-cloud-storage": "^2.2",
    "tymon/jwt-auth": "^1.0"
},
"require-dev": {
    "fzaninotto/faker": "^1.9.1",
    "mockery/mockery": "^1.3.1",
    "phpunit/phpunit": "^9.0",
    "nunomaduro/collision": "^5.0"
},
"config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
},
"extra": {
    "laravel": {
        "dont-discover": []
    }
},
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    },
    "classmap": [
        "database/seeders",
        "database/factories"
    ]
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
    ],
    "post-root-package-install": [
        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate --ansi"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "composer dump-autoload",
        "php artisan optimize",
        "chmod -R 755 bootstrap\/cache",
        "php artisan migrate  --no-interaction --force"
    ],
    "gcp-build": [
        "COMPOSER_MEMORY_LIMIT=-1 composer install --no-dev"
    ]
}

}

Also, is there any chance to update composer to v2 as I getting this warning during cloud build:

Step #6 - "builder": Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is now available and you should upgrade. See https://getcomposer.org/2

And here is actual issue that fails the build:

Step #6 - "builder": Updating dependencies
Step #6 - "builder": 
Step #6 - "builder": Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Step #6 - "builder": 
Step #6 - "builder": Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.Done "composer install --no-dev --no-progress --no-suggest --no-in..." (56.105751566s)
Step #6 - "builder": Failure: (ID: 5888fcc4) Loading composer repositories with package information
Step #6 - "builder": Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2.0 is now available and you should upgrade. See https://getcomposer.org/2
Step #6 - "builder": Updating dependencies
Step #6 - "builder": 
Step #6 - "builder": Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52
Step #6 - "builder": 
Step #6 - "builder": Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.

Runtime used in app.yaml is php74, also tried to change it to php72, same issue

1
Try to run command composer install if there's no composer.lock file on your application folder and composer update if composer.lock exist. Then, deploy your application using the command gcloud app deploy --no-cache to make sure that the dependency will be updated.JM Gelilio
@john-michael-g Thanks! It actually helpedKikun
I assume that doing so resolved your issueJM Gelilio

1 Answers

0
votes

Since your deployed application already has a composer.lock file generated from App Engine deployment and by default, App Engine caches fetched dependencies to reduce build times. It will prevents you from automatically getting the latest versions of your dependencies and you will encounter the error:

You are using an outdated version of Composer

To resolve the issue, run command composer install locally to pin your dependencies to their current version and to have a composer.lock and composer update if composer.lock is existing. Then deploy using the command 'gcloud beta app deploy --no-cache' to install an uncached version of the dependency.