How to unlimit PHP Deployer composer memory? - composer-php

I am running PHP deployer for a magento application from a docker-compose.
The apache is inside a container and there is a memory limit for php. I have control on the Dockerfile, if needed.
Currently my issue is that when I run dep deploy it crashes:
$ dep deploy
✈︎ Deploying master on main
✔ Executing task deploy:prepare
✔ Executing task deploy:lock
✔ Executing task deploy:release
✔ Executing task deploy:update_code
✔ Executing task deploy:shared
➤ Executing task deploy:vendors
✔ Executing task deploy:failed
✔ Executing task deploy:unlock
In Client.php line 103:
The command "cd /home/public_html/releases/20201214130007 && /usr/local/bin/composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest" failed.
Exit Code: 255 (Unknown error)
If I run the composer line inside the container with the addition of unlimit of the memory, it works:
php -d memory_limit=-1 /usr/local/bin/composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest
I tried to force to force deployer to use to use composer this way, but it didn't work:
# in deployer.php:
set('composer', 'php -d memory_limit=-1 /usr/local/bin/composer');
I think that it is because it is not using the composer from the set when doing deployer:vendors as can be seen from the verbose log:
➤ Executing task deploy:vendors
[main] > if hash unzip 2>/dev/null; then echo 'true'; fi
[main] < true
[main] > if hash composer 2>/dev/null; then echo 'true'; fi
[main] < true
[main] > command -v 'composer' || which 'composer' || type -p 'composer'
[main] < /usr/local/bin/composer
[main] > cd /home/public_html/releases/20201214125356 && /usr/local/bin/composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader --no-suggest
Any suggestions how to fix this?

To change the composer binary used by deployer, you need to set bin/composer, so change this
set('composer', 'php -d memory_limit=-1 /usr/local/bin/composer');
to this
set('bin/composer', 'php -d memory_limit=-1 /usr/local/bin/composer');

Related

execute laravel tests in docker fails

I have the following bash script for Laravel gitlab CI deployment
docker-compose -p project exec php8 bash -c '
composer install --working-dir="dashboard" &&
wp acorn config:clear --allow-root &&
wp acorn view:clear --allow-root &&
wp acorn optimize:clear --allow-root &&
wp rewrite flush --allow-root &&
php dashboard/artisan migrate &&
php dashboard/artisan optimize:clear &&
php vendor/phpunit/phpunit/phpunit --testsuite=Feature'
but the test are not executed because of the following error Could not open input file: vendor/phpunit/phpunit/phpunit if I ls the directory everything seems to be on the right place. How to debug this issue

Vendor folder not being generated despite being run in AWS CodeBuild

When loading my AWS Elastic Beanstalk test website using CodeBuild continual deployment, I get this error:
Warning: require(/var/app/current/clu/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/app/current/clu/public/index.php on line 24 Fatal error: require(): Failed opening required '/var/app/current/clu/public/../vendor/autoload.php' (include_path='.:/usr/share/pear7:/usr/share/php') in /var/app/current/clu/public/index.php on line 24
It seems like the composer files are not being generated.
However, in the CodeBuild logs, they are.
[Container] 2020/02/24 03:21:34 Running command composer install
03:21:38
Loading composer repositories with package information
03:21:38
Installing dependencies (including require-dev) from lock file
03:21:38
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
03:21:38
Package operations: 89 installs, 0 updates, 0 removals
03:21:38
- Installing doctrine/inflector (v1.3.0): Downloading (connecting...)Downloading (100%)
03:21:38
- Installing doctrine/lexer (1.1.0): Downloading (connect..
...
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Discovered Package: [32mfacade/ignition[39m
Discovered Package: [32mfideloper/proxy[39m
Discovered Package: [32mlaravel/tinker[39m
Discovered Package: [32mnesbot/carbon[39m
Discovered Package: [32mnunomaduro/collision[39m
[32mPackage manifest generated successfully.[39m
This is my buildspec.yml code:
version: 0.2
phases:
install:
commands:
export DEBIAN_FRONTEND=noninteractive
#Install php7.1
apt-get update
apt-get install -y software-properties-common
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
apt-get update
# Install PHP
apt-get install -y php7.2\
php7.2-ldap \
php7.2-xml \
php7.2-xmlrpc \
php7.2-zip \
php7.2-mysql \
php7.2-mbstring \
php7.2-mcrypt \
php7.2-gd \
php7.2-readline \
php7.2-opcache \
php7.2-xdebug \
php7.2-dom \
php-xdebug \
php7.2-curl \
unzip
phpenmod xdebug
#Install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php ;
php -r "unlink('composer-setup.php');" ;
mv composer.phar /usr/local/bin/composer
build:
commands:
- echo Build started on `date`
- echo Installing composer deps
- composer install
post_build:
commands:
- echo Build completed on `date`
My laravel filesystem does not have the vendor folder as I would like it to be generated via composer install.
Would greatly appreciate a hand, i've tried so many things.. cant get it to generate properly.
I've also checked via ssh and the folder is not there grrr. Its like its being generated elsewhere.
Thanks!
Adding the following to my buildspec.yml enabled the vendor file to be uploaded to the working server.
artifacts:
files:
- '**/*'
proxy:
upload-artifacts: yes
logs: yes

Docker and laravel not clearing the cache

I have an app running with docker and laravel but there are some instructions that apparently are executed but not functioning.
These instructions are php artisan clear:cache and php artisan optimize.
Sometimes I need to get into the container and run these instructions in order to have my changes reflected in the browsers. Apart from the failures that kubernetes detects due to the unreflected changes
FROM php:7.2.0-fpm as php
RUN apt-get update && apt-get install -y openssl openssh-client \
rsync sshpass zip unzip git vim libmcrypt-dev mysql-client \
libssh2-1-dev libmagickwand-dev \n
gnupg2 --no-install-recommends zlib1g-dev sass \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-enable mcrypt \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install gd \
&& docker-php-ext-install zip \
&& pecl install ssh2-1.0 \
&& docker-php-ext-enable ssh2
RUN curl --silent --location https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs
RUN npm install --global bower
WORKDIR /var/www/html
COPY install-composer.sh install-composer.sh
RUN bash ./install-composer.sh
COPY composer.json ./
COPY composer.lock ./
RUN composer install --no-scripts --no-autoloader
COPY . ./
RUN composer update
RUN composer install
COPY zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
RUN mkdir -p /var/run/php/sock/
RUN sass resources/sass/style.scss:public/assets/stylesheets/style.css
RUN bower install --allow-root
RUN composer dump-autoload
RUN php artisan vendor:publish --provider="Sentry\SentryLaravel\SentryLaravelServiceProvider"
ONBUILD chown -R www-data:www-data .
RUN php artisan optimize && php artisan config:cache \
&& php artisan view:cache && php artisan view:clear
Most of the time I need to get into the container and run the php artisan optimize, view:cache and view:clear again even though they are in the Dockerfile so it shouldn't be necessary to do it all over again
Any commands that are being executed using RUN in the Dockerfile will be executed only during the build phase. If you wish to run them while starting a container so you don't have to run them manually then you need to use a script e.g. bash script that can be used as an ENTRYPOINT for your Dockerfile and then make this script execute the command that you should run to start the application. So your entrypoint.sh can look like this:
# entrypoint.sh
#!/usr/bin/env sh
...
php artisan optimize
php artisan config:cache
php artisan view:cache
php artisan view:clear
...
php artisan serve # or use exec "$#" and pass php artisan serve through CMD in Dockerfile
This will make every container that you start execute all of these commands before start serving your application.
Other links that you might want to check:
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
What does set -e and exec “$#” do for docker entrypoint scripts?
You can also use the cmd:
sudo docker-compose exec php php /var/www/html/path_to_laravel_project_dir/artisan config:cache
it will execute the artisan cmd in the container.
Just ran into a problem of cache:clear with Laravel too (no Docker involved in my case)
Fact is : if Artisan has no rights to clear caches, it just silently fails, proudly telling you cache have been successfully cleared (sigh).
See https://github.com/laravel/framework/issues/1179 for more details
*In my case, adding simple "sudo" before my command did the trick... but I lost half an hour understanding the cause (what an introduction to Laravel/Artisan :p)
*I have a Laravel v6.5

How to run laravel app inside docker container?

I want to get docker container's result from local, following is what I tried.
step1.
create php-composer image using dockerFile.
FROM php:7
RUN apt-get update
RUN apt-get install curl
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN apt-get install -y git
step2.
create container and execute laravel app.
docker run -p 127.0.0.1:3000:8000 --name MyTest -dt php-composer to create a container
docker cp laravelApp/ d4bbb5d36312:/usr/
docker exec -it MyTest bash
cd usr/laravelApp
php artisan serve
After that, terminal shows success info:
Laravel development server started: <http://127.0.0.1:8000>
But when I access 127.0.0.1:3000 at browser, I get nothing.
Why is that?
there are some php extensions that are needed for laravel to work, so you need to install them too, this is the full dockerfile
FROM php:7
RUN apt-get update -y && apt-get install -y openssl zip unzip git
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo mbstring
WORKDIR /app
COPY app /app # this copies all the app files to a folder called `app`
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8000
EXPOSE 8000
then to run the container, run this command only:
docker run -p 3000:8000 --name MyTest
then go to http://localhost:3000
let me know if it didn't work

/bin/sh: 1: composer: not found

I am trying to build a Dockerfile.
FROM php:7
RUN mkdir -p /home/winpc/test/laravelApp/app
WORKDIR /home/winpc/test/laravelApp/app
COPY composer.json /home/winpc/test/laravelApp/app
RUN composer install
COPY . /home/winpc/test/laravelApp/app
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181
But when i run the build command it says:
docker build -t lar-app .
/bin/sh: 1: composer: not found
The command '/bin/sh -c composer install' returned a non-zero code: 127
But when I type just composer it is properly displaying the information
I guess the problem is with the command:
RUN composer install
Here I am using Ubuntu 14.04
As the Stacktrace says, install composer before running composer command.
I've added these lines:
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet
RUN mv composer.phar /usr/local/bin/composer
So your Dockerfile will be:
FROM php:7
# Install composer:
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/1b137f8bf6db3e79a38a5bc45324414a6b1f9df2/web/installer -O - -q | php -- --quiet
RUN mv composer.phar /usr/local/bin/composer
RUN mkdir -p /home/winpc/test/laravelApp/app
WORKDIR /home/winpc/test/laravelApp/app
COPY composer.json /home/winpc/test/laravelApp/app
RUN composer install
COPY . /home/winpc/test/laravelApp/app
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181

Resources