deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Deployer unable to find composer installed recipes

Open jamieburchell opened this issue 9 years ago • 56 comments

Q A
Issue Type Question
Deployer Version 6.0.3
Local Machine OS WSL
Remote Machine OS CentOS 7

Description

Deployer fails to find and require recipes installed via the method included in the third party recipe instructions

Steps to reproduce

Install recipes:

composer require deployer/recipes --dev

Add a recipe as per docs:

require 'recipe/cachetool.php';

Run deployment:

dep deploy production OR php deployer.phar deploy production

Result:

PHP Warning:  require(recipe/cachetool.php): failed to open stream: No such file or directory in /mnt/d/web/deploy.php on line 3
PHP Fatal error:  require(): Failed opening required 'recipe/cachetool.php' (include_path='phar:///mnt/d/web/deployer.phar/bin/../:.:/usr/share/php') in /mnt/d/web/blog.ib3.uk/deploy.php on line 3

Content of deploy.php

<?php
namespace Deployer;

require 'recipe/composer.php';
require 'recipe/cachetool.php';

// Project name
set('application', 'Example');

// Project repository
set('repository', '[email protected]:foo');

// Hosts
host('xxx')
	->stage('production')
	->user('deploy')
    ->set('deploy_path', '/var/www')
    ->set('cachetool', '127.0.0.1:9000');

// Shared files/dirs between deploys
add('shared_dirs', [
	'web/app/upgrade',
	'web/app/uploads',
	'web/app/wfcache',
	'web/app/wflogs'
]);

// Copy config
task('enable_prod_config', function() {
	run('cp "{{release_path}}/.env.prod" "{{release_path}}/.env"');
})->onStage('production');
after('deploy:update_code', 'enable_prod_config');

// Clear opcache
after('deploy:symlink', 'cachetool:clear:opcache');

// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', true);

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

Worked around the issue thus:

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'vendor/deployer/recipes');

Should that be part of the documtation or is something broken?

jamieburchell avatar Sep 22 '17 22:09 jamieburchell

So for my understanding the autoload from root project is not loaded. Here is a problem: when using phar it will load only phar autoload, when composer installed – project root.

Yes, it's true.

One more solution: when building phar archive create a bootstrap file (with all needed classes) and require it as first line in bin/dep file. After load project root's autoload.php file. This way symfony classes will be already preloaded and no need of deployer's autoload. I like this approach better when others. But it may have a bug: if using something in deploy.php what is relaying on older symfony components when bootstraped with deployer.

antonmedv avatar Oct 17 '17 10:10 antonmedv

@antonmedv IMO there will be never problem with adding require 'vendor/autoload.php' to deploy.php when you install deployer with composer require deployer/deployer as at this level developer already needs to solve the potential conflicts.

Problem will only occur ONLY when we use phar based deployer. For that case there is simple solution however. Deployer needs to detect if there is vendors/autoload.php from root project and if yes they it should require that file BEFORE require autoload from phar. This way the deployer classes will have precedence over that one from root vendors.

kszymukowicz avatar Oct 17 '17 11:10 kszymukowicz

Deployer needs to detect if there is vendors/autoload.php from root project and if yes they it should require that file BEFORE require autoload from phar.

Yes, this is a solution too. I think I'll try to implement this.

antonmedv avatar Oct 17 '17 11:10 antonmedv

After lots of thinking, here is what I came up with:

Installing with composer

  • Deployer will try to locate autoload.php file (local or global) and require it.
  • Scan vendor dir for composer.json files and fetch stuff like this:
    "extra": {
        "deployer": {
            "include_path": "recipe/"
        }
    }
    
  • Next add all found include_path to set_include_path — this allows to simple recipe requirement:
     require 'laravel.php';
     require 'slack.php';
    

Installing with archive

  • Download phar to local deployer.phar or bin/dep.
  • Commit phar file to repository (to save version number).
  • Save scan on vendor step as on composer installation.
  • No autoload.php file required, you need to manually add it to your deploy.php file if needed.
  • All required files by deployer included in single bootstrap file inside phar.
  • If called global installed dep it will check existing next files in project:
    • deployer.phar
    • bin/dep
    • vendor/bin/dep
  • If on of this files found, call it instead of global on (this allows global dep (for example of version v7) to call project installed deployer).

antonmedv avatar Nov 02 '17 10:11 antonmedv

I build a docker image for CI/DEPLOYER there with deployer/recipes installed globally and deployer is install with phar

composer global require deployer/recipes --dev 

then in my deployer.php of project

$composerHome = getenv("COMPOSER_HOME") ?: (getenv("HOME") . '/.composer/');
if (is_dir($composerHome)) {
    include $composerHome . '/vendor/autoload.php';
} else {
    $xdgComposerHome = getenv('XDG_CONFIG_HOME') ?: (getenv("HOME") . '/.config');
    $xdgComposerHome = $xdgComposerHome . '/composer';
    if (is_dir($xdgComposerHome)) {
        include $xdgComposerHome . '/vendor/autoload.php';
    }
}

It Just works well

@antonmedv

ihipop avatar Jan 23 '18 14:01 ihipop

Can't you just include the recipes in the phar? Or build a phar with and without plugins? I'm not sure how many people are building custom recipes anyways? I'm also having trouble including the Slack recipe when using the phars.. (Because of Symfony conflicts etc)

barryvdh avatar Feb 13 '18 07:02 barryvdh

I would like to keep them separately. And definitely going to this it for phars and composers require 'recipe.php'.

But may be popular stuff like slack should go to main repo.

antonmedv avatar Feb 13 '18 08:02 antonmedv

Can't you just include the recipes in the phar? Or build a phar with and without plugins? I'm not sure how many people are building custom recipes anyways? I'm also having trouble including the Slack recipe when using the phars.. (Because of Symfony conflicts etc)

I got the feeling that you need to composer require the deployer in your project (and also the custom recipes/plugins/classes etc) in case you need something more customized then the phar.

IMO using the phar only works for rather simple/standard use-cases... most use-cases need more flexibility and dont work with the phar.

staabm avatar Feb 13 '18 08:02 staabm

yes but that's pretty difficult with conflicting dependencies, eg. like symfony console and Magento2.

I haven't looked at most recipes, but I guess they have similar dependencies (like the HTTP utilities), so it wouldn't impact the phar too much to include Slack alone, or alle of them, right?

barryvdh avatar Feb 13 '18 08:02 barryvdh

Yes, but this is wrong path. See my note upper.

antonmedv avatar Feb 13 '18 08:02 antonmedv

Example remedy:

require 'vendor/deployer/recipes/recipe/rsync.php';

hooch avatar Sep 17 '18 10:09 hooch

Updating phar on our build server broke our deployment process due to:

dep6 deploy test -vvv
PHP Warning:  require_once(recipe/symfony4.php): failed to open stream: No such file or directory in /home/xxxxx/jenkins-slave/workspace/xxxxx.com_develop-

These recipes were present in that phar previously?

jkobus avatar Sep 24 '18 14:09 jkobus

What version of dep?

antonmedv avatar Sep 24 '18 14:09 antonmedv

Well it seems that this problem is somewhere on my side, although I have no idea why this happens. I downloaded deployer from this url - its 6.0.5:

https://deployer.org/releases/v6.0.5/deployer.phar (in bin as dep6)

I also have two other versions in bin:

6.3.0 (as dep) 4.3.1 (as dep4)

I only updated the 6.3.0 as two others are version-locked for compatibility.

The one used in deployment that went broken is 6.0.5 (dep6).

Im wondering if its possible that in bin I had an old phar with this receipt and after update to 6.3 it was removed. My include path during install:

PHP Fatal error:  require_once(): Failed opening required 'recipe/symfony4.php' (include_path='phar:///usr/local/bin/dep6/bin/../:.:/usr/share/php') in /home/xxx/jenkins-slave/workspace/xxx.com_develop-BE4ZFIKIUWRUVBXYXPR6E5MC2IFLQN4GNM2FRXXL35N7JLIBZUEA/deploy.php on line 9

jkobus avatar Sep 24 '18 14:09 jkobus

include_path looks normal. Try running this script locally.

antonmedv avatar Sep 24 '18 19:09 antonmedv

Just thought I'd share my experience with php 7.0.32: I had the same problem require(): Failed opening required 'recipe/ .......

I finally traced it to the presence of the ioncube_loader extension. Disabled ioncube and everything works normally.

davefarthing avatar Oct 24 '18 07:10 davefarthing

include_path looks normal. Try running this script locally.

why not just include the autoloader? https://github.com/deployphp/deployer/issues/1371#issuecomment-359814638

ihipop avatar Oct 24 '18 07:10 ihipop

I am having same problem caused by ioncube. Everything works perfectly without ioncube

alinalexandru avatar Mar 03 '20 21:03 alinalexandru

This is how I "solved" the issue

require 'phar:///usr/local/bin/dep/recipe/common.php';

Even though the get_include_path() was phar:///usr/local/bin/dep/bin/../:.:/usr/local/lib/php

alinalexandru avatar Mar 03 '20 21:03 alinalexandru

Well. This one is over. Almost 3 years since opening. Now recipes gonna live in deployer repo: https://github.com/deployphp/deployer/tree/master/contrib

antonmedv avatar Apr 25 '20 22:04 antonmedv