deployer: Deployer unable to find composer installed recipes

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', 'git@bitbucket.org: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?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 6
  • Comments: 56 (43 by maintainers)

Commits related to this issue

Most upvoted comments

Example remedy:

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

What’s the status of this please? I just noticed deployer/recipes is abandoned but including recipe/cachetool.php without them doesn’t work for me and the composer and CodeIgniter recipes I use in older projects are missing it seems?

Was the recipe repo prematurely archived and abandoned before v7 of Deployer was released?

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

I just read every comment in this thread, and I’m still not sure what I’m supposed to do to fix this problem.

  • Installed phar globally following installation instructions in documentation.
  • require succeeds for present recipe folder.
  • require fails for non-existent contrib folder.

I did not see a solution in this thread for getting contrib files to work. Did I miss it?

@jamieburchell @memen45 As always in live, playing with the kids, computer or enjoying lunch with your loved ones is more important than correcting documentation or code on a open source project.

Really appreciate the efforts made by the contributors of course! Just wanted to help out here. With regards to the documentation, I have seen many projects where this is lacking. And that is not a problem at all. I think the following could help a lot:

  • Use versions in the documentation
  • Mark incomplete sections in the documentation (e.g. ‘This section is incomplete’, ‘This section requires examples’ etc). This way users are aware that it isn’t complete, and at the same time potential contributors know how to contribute.
  • Provide some steps for contributors to contribute properly (i.e. how to build and test the project locally on your pc). I noticed a pull request #2267 where the contributor doesn’t know how to make a test. And for me, I know some php and the code base seems to be very clearly written, but I have no idea how to modify and then build the source code again. Adding a small guide (if possible just provide links to existing guides and make remarks for the changes) could really help to make contributing easier.

Those are just some things that I noticed as I started diving in only weeks ago. Apart from this, I really like the Deployer software and the functionality it brings, so thanks a lot for that!

@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.

At a minimum update the documentation to show that the include path needs to include the deployer recipes directory. As it stands all the examples and documents suggest it “just works” without, when it doesn’t.

I think that’s where the confusion has come from - between the deployer/recipes composer package being archived/deprecated but not able to find the recipes in the current stable version and of course the confusing documentation when faced with the above. By the way, I love Deployer and use it on all my work projects.

Indeed, documentation is wildly incomplete and contradicting itself. I do not know what the idea is of the maintainer(s), as the website looks very nice, but the information is very limited.

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

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).