php-docs-samples
php-docs-samples copied to clipboard
Error on build Laravel App On Gitlab runner
I have this error when deploy my app on Gitlab runner. I don't know what happening and how to fix this error.
$ echo $SERVICE_ACCOUNT > /tmp/$CI_PIPELINE_ID.json $ gcloud auth activate-service-account --key-file /tmp/$CI_PIPELINE_ID.json Activated service account credentials for: [[email protected]] $ gcloud --quiet --project $PROJECT_ID app deploy app-staging.yaml --version $CI_JOB_ID Services to deploy:
descriptor: [/builds/quilp/dashboard-bi/app-staging.yaml] source: [/builds/quilp/dashboard-bi] target project: [dw-ghn] target service: [dashboard-staging] target version: [39753] target url: [https://dashboard-staging-dot-dw-ghn.appspot.com]
Beginning deployment of service [dashboard-staging]...
#============================================================#
#= Uploading 1 file to Google Cloud Storage =#
#============================================================#
File upload done.
Updating service [dashboard-staging]...
...............................................................................................................................................................................................................................................................................failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build 8e6ed0b0-c44d-439b-b00e-c598c648d4a3 status: FAILURE.
Build error details: {"error":{"errorType":"BuildError","canonicalCode":"INVALID_ARGUMENT","errorId":"3FDF33BB","errorMessage":"INFO FTL version php-v0.17.0\nINFO Beginning FTL build for php\nINFO FTL arg passed: exposed_ports None\nINFO FTL arg passed: cache_repository asia.gcr.io/dw-ghn/app-engine-tmp/build-cache/ttl-7d\nINFO FTL arg passed: tar_base_image_path None\nINFO FTL arg passed: export_cache_stats False\nINFO FTL arg passed: builder_output_path ""\nINFO FTL arg passed: name asia.gcr.io/dw-ghn/app-engine-tmp/app/ttl-2h:5578b807-4c92-4502-8471-30621a91c96b\nINFO FTL arg passed: ttl 168\nINFO FTL arg passed: global_cache False\nINFO FTL arg passed: cache True\nINFO FTL arg passed: upload True\nINFO FTL arg passed: sh_c_prefix False\nINFO FTL arg passed: fail_on_error True\nINFO FTL arg passed: base asia.gcr.io/gae-runtimes/php72:php72_20191020_7_2_23_RC00\nINFO FTL arg passed: output_path None\nINFO FTL arg passed: cache_key_version v0.17.0\nINFO FTL arg passed: cache_salt \nINFO FTL arg passed: directory /workspace\nINFO FTL arg passed: entrypoint None\nINFO FTL arg passed: additional_directory /.googleconfig\nINFO FTL arg passed: destination_path /srv\nINFO FTL arg passed: verbosity NOTSET\nINFO starting: full build\nINFO starting: builder initialization\nINFO Loading Docker credentials for repository 'asia.gcr.io/gae-runtimes/php72:php72_20191020_7_2_23_RC00'\nINFO Loading Docker credentials for repository 'asia.gcr.io/dw-ghn/app-engine-tmp/app/ttl-2h:5578b807-4c92-4502-8471-30621a91c96b'\nINFO builder initialization took 0 seconds\nINFO starting: build process for FTL image\nINFO starting: rm_vendor_dir\nINFO rm_vendor_dir rm -rf /workspace/vendor\nINFO rm_vendor_dir
stdout:\n\nINFO rm_vendor_dir took 0 seconds\nINFO descriptor_contents:\n{\n "_readme": [\n "This file locks the dependencies of your project to a known state",\n "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",\n "This file is @generated automatically"\n ],\n "content-hash": "f079fd857eddf700675808511c67fb4d",\n "packages": [\n {\n "name": "dnoegel/php-xdg-base-dir",\n "version": "0.1",\n "source": {\n "type": "git",\n "url": "https://github.com/dnoegel/php-xdg-base-dir.git",\n "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a"\n },\n "dist": {\n "type": "zip",\n "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/265b8593498b997dc2d31e75b89f053b5cc9621a",\n "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a",\n "shasum": ""\n },\n "require": {\n "php": "\u003e=5.3.2"\n },\n "require-dev": {\n "phpunit/phpunit": "@stable"\n },\n "type": "project",\n "autoload": {\n "psr-4": {\n "XdgBaseDir\\": "src/"\n }\n },\n "notification-url": "https://packagist.org/downloads/",\n "license": [\n "MIT"\n ],\n "description": "implementation of xdg base directory specification for php",\n "time": "2014-10-24T07:27:01+00:00"\n },\n {\n "name": "doctrine/inflector",\n "version": "v1.3.0",\n "source": {\n "type": "git",\n "url": "https://github.com/doctrine/inflector.git",\n "reference": "5527a48b7313d15261292c149e55e26eae771b0a"\n },\n "dist": {\n "type": "zip",\n "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a",\n .
Check the build log for errors: https://console.cloud.google.com/gcr/builds/8e6ed0b0-c44d-439b-b00e-c598c648d4a3?project=1001942818469
Running after script...
$ rm /tmp/$CI_PIPELINE_ID.json
ERROR: Job failed: exit code 1
Hello @theboy412 ! Thank you for submitting this. Can you provide a little more context? Looking at the error message, nothing stands out as an obvious issue. Sharing your composer.json
and app-staging.yaml
would help, for starters.
composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2",
"ext-curl": "*",
"ext-json": "*",
"fideloper/proxy": "^4.0",
"google/cloud": "^0.120.0",
"google/cloud-bigquery": "^1.12",
"google/cloud-error-reporting": "^0.15.0",
"google/cloud-firestore": "^1.9",
"google/cloud-logging": "^1.18",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"phpoffice/phpspreadsheet": "^1.9"
},
"require-dev": {
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-install-cmd": [
"chmod -R 755 bootstrap\/cache",
"php artisan config:cache",
"php artisan route:cache"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
app-staging.yaml
runtime: php72
service: dashboard-staging
instance_class: f2
default_expiration: "1d 5h"
handlers:
- url: /favicon\.ico
static_files: public/images/favicon.ico
upload: public/images/favicon\.ico
- url: .*
script: auto
env_variables:
## Put production environment variables here.
APP_KEY: base64:ONEXx5NS8XBn/cI2+75KWHCYrAAAAAAAAAAAAA
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
LOG_CHANNEL: stackdriver
SESSION_DRIVER: cookie
SECRET_KEY: GGHEXPRESS
GOOGLE_PROJECT_ID: dw-ggh
DATASTORE: dashboard-staging
Error details on link https://console.cloud.google.com/gcr/builds/8e6ed0b0-c44d-439b-b00e-c598c648d4a3?project=1001942818469
Step #1 - "builder": error: composer_install returned code: 1
Step #1 - "builder": Traceback (most recent call last):
Step #1 - "builder": File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
Step #1 - "builder": "main", fname, loader, pkg_name)
Step #1 - "builder": File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
Step #1 - "builder": exec code in run_globals
Step #1 - "builder": File "/usr/local/bin/ftl.par/main.py", line 65, in
Your error is No such file or directory: '""/output'
For some reason or another, laravel is trying to write to a directory /output
, which doesn't exist. This needs to either be configured to be a different directory, or you can try creating that directory.
I am having a similar error, judging by the part of the build log. At least it also ends in No such file or directory: '""/output'
. Closer inspection of the Cloud Build log shows this:
INFO composer_install composer install --no-dev --no-progress --no-suggest --no-interaction
INFO `composer_install` stdout:
Google\Cloud\Core\Exception\BadRequestException : {
"error": {
"code": 400,
"message": "Invalid bucket name: '.appspot.com'",
"errors": [
{
"message": "Invalid bucket name: '.appspot.com'",
"domain": "global",
"reason": "invalid"
}
]
}
}
at /workspace/vendor/google/cloud-core/src/RequestWrapper.php:362
358| $exception = Exception\ServiceException::class;
359| break;
360| }
361|
> 362| return new $exception($this->getExceptionMessage($ex), $ex->getCode(), $ex);
363| }
364|
365| /**
366| * Gets the exception message.
Exception trace:
1 Google\Cloud\Core\RequestWrapper::convertToGoogleException(Object(GuzzleHttp\Exception\ClientException))
/workspace/vendor/google/cloud-core/src/RequestWrapper.php:206
2 Google\Cloud\Core\RequestWrapper::send(Object(GuzzleHttp\Psr7\Request), [])
/workspace/vendor/google/cloud-core/src/RestTrait.php:94
Please use the argument -v to see more details.
It seems that somehow the default project bucket is not found (Invalid bucket name: '.appspot.com'
). Maybe the project id is not set in the environment of the Cloud Builder, but this should be available always.
My app.yaml contains:
APP_STORAGE: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
VIEW_COMPILED_PATH: /tmp
My composer requirements are
"fideloper/proxy": "^4.2",
"google/cloud-error-reporting": "^0.14.5",
"google/cloud-logging": "^1.16",
"google/cloud-storage": "^1.10",
"google/cloud-tasks": "^1.3",
"google/cloud-vision": "^0.22.5",
"laravel/framework": "^6.3",
"superbalist/laravel-google-cloud-storage": "^2.2"
I'm running into this issue with CircleCI, so it has nothing to do with the CI/CD and is some issue with deployment.
Unlike, @gjvanahee, however, I'm not seeing that BadRequestException
in the build. I am, however, seeing:
Step #1 - "builder": In Compiler.php line 36:
Step #1 - "builder":
Step #1 - "builder": Please provide a valid cache path.
This makes me wonder if an error of some kind happening during the composer_install
process causes this error to occur. 🤔
For me the error seems to have something to do with php artisan package:discover
— if I remove this from the post-autoload-dump
then the build works (mind you, this breaks Laravel).
@JasonTheAdams dit you point all the paths to /tmp
in your app.yaml
?
APP_STORAGE: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
VIEW_COMPILED_PATH: /tmp
Deploying now is a multistage proces:
-
gcloud app deploy --no-promote
- if the build fails (in my case due to the invalid bucket name):
2.1. remove the line
"@php artisan package:discover --ansi"
in composer.json 2.2. deploy againgcloud app deploy --no-promote
2.3. undo the removal in composer.json 2.4.gcloud app deploy
- else promote the version (in the console)
Hardly optimal, but I have not found a better way. I have also not found why "@php artisan package:discover --ansi"
has any impact on the bucket name... I am also not sure which bucket this should be, have not tested yet whether setting the --bucket
flag will help. Perhaps @bshaffer knows this?