Api platform demo project installation problem - api-platform.com

I want to try the api-platform demo (link) but when running docker-compose up -d I get this:
Step 25/34 : RUN set -eux; mkdir -p var/cache var/log; composer dump-autoload --classmap-authoritative --no-dev; composer dump-env prod; composer run-script --no-dev post-install-cmd; chmod +x bin/console; sync
---> Running in ce481c894af3
+ mkdir -p var/cache var/log
+ composer dump-autoload --classmap-authoritative --no-dev
Generating optimized autoload files (authoritative)
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
Generated optimized autoload files (authoritative) containing 4186 classes
+ composer dump-env prod
[RuntimeException]
Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.
symfony:dump-env [--empty] [--] [<env>]
The command '/bin/sh -c set -eux; mkdir -p var/cache var/log; composer dump-autoload --classmap-authoritative --no-dev; composer dump-env prod; composer run-script --no-dev post-install-cmd; chmod +x bin/console; sync' returned a non-zero code: 1
ERROR: Service 'php' failed to build
OS: Ubuntu 18.04
Docker: version 20.10.3, build 48d30b5
Docker-compose: version 1.28.4, build cabd5cfb
What am I doing wrong?

there is a pull request to fix it. just update the composer.lock file https://github.com/api-platform/api-platform/pull/1826

Related

Error on Composer before deploying on Bitbucket Pipeline

We have a CI&CD process that have a dockerfile within for deploying to laravel vapor environments via bitbucket pipeline which consists of 4 basic steps:
Install
Build
Test
Deploy
The interesting point is that, we're passing 3 steps without any problems.
We can run the same command on the 4th step on our local environment and deploy to any environments without any problems.
But when we're trying to deploy it via Bitbucket Pipeline (which was already working 10 days ago but broken now) we're failing with an error message of
In ClassLoader.php line 571:
include(/opt/atlassian/pipelines/agent/build/.vapor/build/app/vendor/compos
er/../composer/composer/src/Composer/Console/GithubActionError.php): Failed
to open stream: No such file or directory
on composer install command.
Our current pipeline configuration:
image: lorisleiva/laravel-docker:8.0
definitions:
steps:
- step: &Install
name: Install
script:
- npm ci
- composer install
- composer dump-autoload
artifacts:
- node_modules/**
- vendor/**
- step: &Build
name: Build
script:
- npm run prod
artifacts:
- public/**
- vendor/**
- step: &Test
name: Test & Lint
script:
- php -d memory_limit=4G vendor/bin/phpstan
- vendor/bin/phplint ./ --exclude=vendor
- vendor/bin/phpunit --coverage-text --colors=never
caches:
node: node_modules
composer: vendor
public: public
pipelines:
branches:
release/test:
- step: *Install
- step: *Build
- step: *Test
- step:
name: Release to Vapor [test]
services:
- docker
script:
- COMMIT_MESSAGE=`git log --format=%B -n 1 $BITBUCKET_COMMIT`
- vendor/bin/vapor deploy test --commit="$BITBUCKET_COMMIT" --message="$COMMIT_MESSAGE"
our test dockerfile for vapor
FROM laravelphp/vapor:php80
COPY . /var/task
and our vapor configuration:
build:
- "COMPOSER_MIRROR_PATH_REPOS=1 composer install --no-dev"
- "php artisan event:cache"
- "npm ci && npm run prod && rm -rf node_modules"
deploy:
- "php artisan migrate"
- "php artisan lighthouse:clear-cache"
Tried to remove composer cache on bitbucket pipeline config.
Read composer cache not working on bitbucket pipeline build and https://github.com/lorisleiva/laravel-docker/issues/67 but still have no idea why it is happening so any help or suggestions are more than welcome.
TLDR: Run rm -rf ./vendor before your composer install before deploying.
Now to our analysis 👇🏼
We run all our tests and deploys in GitLab CI (thanks to #lorisleiva 🤗 ). And we have 3 jobs in 3 stages:
preparation stage runs the "composer" job, which runs composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
testing stage runs the "phpunit" job
deploy stage runs our Vapor deploy script, which runs COMPOSER_MIRROR_PATH_REPOS=1 composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader --no-dev
So, in the composer job we install our dev dependencies because we need them to test the app. The resulting ./vendor directory gets cached by GitLab's CI system and it's automatically made available for the subsequent stages.
That's great, cause it means we install dependencies once and then we can re use that in the testing and deploying stages. So we "deploy the same thing that we tested"...
But that's actually false, cause for production we don't want to install the development dependencies. That's why we use the --no-dev flag in composer in the deploy stage. Keep in mind, we do need those development dependencies to run phpunit.
And when we run it we see a message like:
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 0 updates, 73 removals
That makes sense, we already have access to the cached ./vendor directory from the composer job and now we only need to remove the development dependencies.
That's when things fall apart. I've no idea if this is a bug in composer itself, in a dependency, in our codebase, etc... but composer errors out with the ...GithubActionError.php error when trying to remove the development dependencies. If we remove the --no-dev it works perfectly, but That's A NoNo.
Long story short, our solution is to embrace the fact that composer.lock exists and that this job runs in CI (where the download speed is insanely fast). So we nuke the ./vendor directory running rm -rf ./vendor right before the deployable composer install ... --no-dev.
In the end, I think this is perfectly acceptable.
I'm sure there's a way to tell GitLab to avoid downloading the cached ./vendor directory, or an overall better way to do this. But we've spent way to much time today trying to understand and fix this... so, it's going to stay like this. And, no, it doesn't seen to be related to lorisleiva/laravel-docker:x.x docker images.
I hope this is helpful or at least interesting :)
Please do let me know if anyone finds a better approach.
Source here https://github.com/lorisleiva/laravel-docker/issues/67#issuecomment-1009419913
I'm having the same issue.
Is working fine if I remove on vapor.yaml file " --no-dev" in this line.
- 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'
Of course is not a solution, but maybe it helps to identify the issue.
I was having same issue but finally fixed.
include(/builds/myapp/myapp-api/vendor/composer/../composer/composer/sr
c/Composer/Console/GithubActionError.php): Failed to open stream: No such f
ile or directory
I am using gitlab pipeline with same lorisleiva/laravel-docker:8.0 image. Further investigation i found composer self-update gives Command "self-update" is not defined. so i thought it is about composer.
So i change .gitlab.ci.yml file like this;
- curl -sS https://getcomposer.org/installer | php
- ./composer.phar -V
- ./composer.phar install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --ignore-platform-reqs
So i download new composer.phar file and used that instead of default composer command and it is worked.

Run demo locally fails: Service 'consumer' failed to build

When Tring to build the API-Platform demo has described on the GitHub repository the building appears to fail on PHP step:
Step 28/36 : RUN set -eux; mkdir -p var/cache var/log; composer dump-autoload --classmap-authoritative --no-dev; composer run-script --no-dev post-install-cmd; chmod +x bin/console; sync
---> Running in 7c9b0eb0fd97
+ mkdir -p var/cache var/log
+ composer dump-autoload --classmap-authoritative --no-dev
Generating optimized autoload files (authoritative)
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
Generated optimized autoload files (authoritative) containing 4776 classes
+ composer run-script --no-dev post-install-cmd
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [OK]
Executing script assets:install public [OK]
Executing script security-checker security:check [KO]
[KO]
Script security-checker security:check returned with error code 1
!!
!! The web service failed for an unknown reason (HTTP 403).
!!
!!
Script #auto-scripts was called via post-install-cmd
ERROR: Service 'consumer' failed to build: The command '/bin/sh -c set -eux; mkdir -p var/cache var/log; composer dump-autoload --classmap-authoritative --no-dev; composer run-script --no-dev post-install-cmd; chmod +x bin/console; sync' returned a non-zero code: 1
I try the following commands:
docker-compose build
I opened an issue too https://github.com/api-platform/demo/issues/192
i think the service stopped ..
https://packagist.org/packages/sensiolabs/security-checker
use this instead
https://github.com/fabpot/local-php-security-checker

Laravel package installation on live server

How to install package in laravel on live server, whenever I run "command composer require monolog/monolog". It gives error Could not open input file: /home/root/composer.phar
First of all, you should not run composer require on live server. You should only run composer install so you should require it locally, test if everything is working fine and then on live server just install library that is tested in your application.
About error:
Could not open input file: /home/root/composer.phar
make sure this file really exists (if not you can download it from Composer site) and make sure it has correct permissions (it should have execute permission) - use chmod +x composer.phar to make it executable
Please try like this.
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ php composer.phar update monolog/monolog
You can install package without any problem.

command line composer command not defined

I am following the composer developer Tutorial: https://hyperledger.github.io/composer/tutorials/developer-guide.html
Everything worked till the point when I am running from the command line:
$ composer archive create -a dist/my-network.bna --sourceType dir --sourceName .
-bash: fds: command not found
The composer command was not found. When built by npm install the script can execute the composer command within the package.json
Next I installed php composer from: https://getcomposer.org - Which might be the wrong package?
$ composer network deploy
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "network" is not defined.
My 2 questions: is this the right package, if not how can I remove it safely?
Furthermore, how can I execute the composer command.
You need to npm install -g composer-cli -- please refer to the documentation.

How to properly duplicate a working Laravel 4 project

I have the latest Laravel 4 beta 5 build from Laravel's github repo.
I have built a simple web API and it is working fine. I wanted to duplicate the project to another folder and continue working on it from the copy. However, when I try that, I get the following error message:
InvalidArgumentException
Driver [native] not supported.
/Users/tolga/Sites/l4api-copy/bootstrap/compiled.php
Line 10908: throw new \InvalidArgumentException("Driver [{$driver}] not supported.");
Here is what I did in order to copy the project:
[/Users/tolga/Sites] $ cp -R l4api l4api-copy
[/Users/tolga/Sites] $ chmod -R 755 l4api-copy
It didn't work, so I've tried:
[/Users/tolga/Sites] $ chmod -R 777 l4api-copy/app/storage
Still no good, tried to run composer dump-autoload:
[/Users/tolga/Sites] $ cd l4api-copy
[/Users/tolga/Sites/l4api-copy] $ composer.phar dump-autoload
Generating autoload files
[/Users/tolga/Sites/l4api-copy] $
Same error. I have also tried to remove the app/storage folder and re-create it.
[/Users/tolga/Sites/l4api-copy] $ rm -Rf app/storage
[/Users/tolga/Sites/l4api-copy] $ mkdir app/storage
[/Users/tolga/Sites/l4api-copy] $ chmod -R 777 app/storage/
Here is a brand-new error:
ErrorException
Warning: file_put_contents(/Users/tolga/Sites/l4api-copy/bootstrap/../app/storage/meta/services.json):
failed to open stream: No such file or directory in
/Users/tolga/Sites/l4api-copy/bootstrap/compiled.php line 5507
Line 5507: return file_put_contents($path, $contents);
I have also run composer.phar dump-autoload command again, after emptying the app/storage folder.
And finally, I have also tried composer.phar install:
[/Users/tolga/Sites/l4api-copy] $ composer.phar install
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
[/Users/tolga/Sites/l4api-copy] $
None of the above helped. What am I doing wrong? What is the proper way to duplicate a working project?
After a recent commit to the laravel/laravel repository a new session driver, native, has been introduced. From the looks of your errors you should update your application skeleton (the cloned develop branch of laravel/laravel), delete your bootstrap/compiled.php file and re-run composer update to pull in the latest framework changes.
In terms of copying the project you should copy over everything except the vendor directory then run composer install in the new location. You could copy the vendor directory but it's better to run a clean install and let composer dump a new autoload.
I've also seen Taylor mention a cleanup of your app/storage/sessions directory. Delete all the files in there.

Resources