Run demo locally fails: Service 'consumer' failed to build - api-platform.com

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

Related

Bash Script not executing git pull

I'm executing a bash script from laravel controller using symphony/process. The bash script is executing but only few of the lines only. Other lines are throwing no output at all.
This is what I'm using to execute bash script from laravel controller.
$process = new Process(['/home/ubuntu/deploy.sh']);
process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
This is triggering the deploy.sh file. and the code of deploy.sh is :
#!/bin/sh
cd /var/www/foodie #working
# activate maintenance mode
php artisan down #working
# update source code
git pull --progress #not working
# update PHP dependencies
composer install --no-interaction --no-dev --prefer-dist #not working
# --no-interaction Do not ask any interactive question
# --no-dev Disables installation of require-dev packages.
# --prefer-dist Forces installation from package dist even for dev versions.
# update database
php artisan migrate --force #working
# --force Required to run when in production.
# stop maintenance mode
php artisan up #working
In all the code php based commands and cd command only working. All other not getting exeuted.
When I execute same file like /home/ubuntu/deploy.sh all commands are working.
I have tried executing the same code manually with home/deploy/deploy.sh and all working fine.
I'm expecting the same should work when executed through symphony/process from laravel controller.

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.

Api platform demo project installation problem

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

Composer hangs on exit

The execution of composer (install, update, create-project...) hangs after composer has finished with an blinking cursor and idle cpu - but the batch script won't exit. It is possible to end the process with ctrl+c.
The problem occurs for most of my Laravel and Symfony Projects and seems not to depended on a certain composer.json / .lock
Window 10
XAMPP PHP 7.0.18
Un/reinstalled composer several times.
Examples:
composer create-project --prefer-dist laravel/laravel testapp
cd testapp
composer install
both won't exit
using --profile shows the following result:
C:\dev\killme>composer install --profile
[7.2MB/0.01s] Loading composer repositories with package information
[7.5MB/0.01s] Installing dependencies (including require-dev) from lock file
[8.5MB/0.04s] Nothing to install or update
[7.7MB/0.05s] Generating optimized autoload files
[9.6MB/7.26s] > Illuminate\Foundation\ComposerScripts::postAutoloadDump
[11.0MB/7.28s] > #php artisan package:discover
[11.1MB/7.69s] Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Package manifest generated successfully.
[10.0MB/7.71s] Memory usage: 9.99MB (peak: 11.53MB), time: 7.71s
- (blinking cursor - batch won't end)
^C cancel batch process (Y/N)? ^C
The following change worked for me:
Updating from PHP 7.0.18 to 7.1.11 (XAMPP)

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.

Resources