deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Can't use Guzzle in custom recipe

Open sts-ryan-holton opened this issue 2 years ago • 1 comments

  • Deployer version:
  • Deployment OS: CentOS 8 Stream

I've recently updated to Deployer 7. I'm using PHP 8 and have a custom recipe that uses Guzzle, previously in Deployer 6 it would find and use the recipe and Guzzle without an issue, but in Deployer 7 throws an error that says GuzzleHttp\Client can't be found, but it should be able to be found since it's included in the project and was never removed, what's going on here?

deploy.php

<?php
namespace Deployer;

use GuzzleHttp\Client;

require 'vendor/autoload.php';
require 'recipe/common.php';
require 'deploy/recipe/fudge-npm.php';
require 'deploy/recipe/fudge-composer.php';
require 'deploy/recipe/fudge-nuxt.php';
require 'deploy/recipe/fudge-duration.php';
require 'deploy/recipe/fudge-github.php';

// Project repository
set('repository', '[email protected]:stsonline/application-fudge.git');

// [Optional] Timeout in seconds, set to 14,400 (4 hours) for max compatibility.
set('default_timeout', 14400);

// Shared files/dirs between deploys
add('shared_files', ['.env', 'brand-theme.scss']);

// Set number of releases to keep
set('keep_releases', 3);

// Writable dirs by web server
set('allow_anonymous_stats', false);

// All brands
// See the README.md for list of friendly brand names for these hosts.
host('1my ip')
    ->set('branch', 'main')
    ->set('labels', ['stage' => 'all'])
    ->set('repository', 'git@fudge:stsonline/application-fudge')
    ->set('remote_user', 'root')
    ->set('deploy_path', '/var/www/include-forms/fudge');

// deploy
task('deploy', [
  'deploy:duration:datetime:start',
  // 'deploy:github:validate',
  'deploy:prepare',
  'deploy:release',
  'deploy:update_code',
  'npm:install',
  'composer:install',
  'deploy:shared',
  'deploy:writable',
  'nuxt:generate',
  'deploy:clear_paths',
  'deploy:symlink',
  'deploy:unlock',
  'deploy:cleanup',
  'deploy:success',
  'deploy:duration:datetime:finish'
]);

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

Custom github recipe file:

<?php
/*
 * Github
 */

namespace Deployer;

use Symfony\Component\Console\Input\InputOption;

option('disable-github-checks', false, InputOption::VALUE_OPTIONAL, 'disable github checks');

desc('Validate Github release with specified tag');
task('deploy:github:validate', function () {
    $tag = input()->getOption('tag');

    // package.json version
    $package = json_decode(file_get_contents('./package.json'), true);

    // disable github checks
    $disableGithubChecks = false;
    if (input()->hasOption('disable-github-checks')) {
      $disableGithubChecks = input()->getOption('disable-github-checks');
    }

    // get the latest release from Github
    // check if we should disable checks
    if ($disableGithubChecks) {
      writeln("<comment>Github checks are disabled, this is highly discouraged</comment>");
    } else {
      $client = new \GuzzleHttp\Client();
      $res = $client->request('GET', 'https://api.github.com/repos/stsonline/application-fudge/releases', [
          'headers' => [
              // NOTE: token must not be removed from Github
              'Authorization' => 'token gdfdfgdfg',
          ]
      ]);
    }
});

sts-ryan-holton avatar Jun 16 '22 15:06 sts-ryan-holton

Please debug autoloading.

antonmedv avatar Jun 16 '22 16:06 antonmedv

For what it's worth, I get the same problem with PHP 7.4 after upgrading:

$ php -v
PHP 7.4.30 (cli) (built: Jun  9 2022 09:20:03) ( NTS )

$ composer -v
Composer version 2.4.1 2022-08-20 11:44:50

$ vendor/bin/dep
 Error  in deploy.php on line 6:

  Class 'Dotenv\Dotenv' not found

This minimal test script runs fine when run with php (php test.php), showing that Dotenv is installed and resolvable:

<?php

require('vendor/autoload.php');

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
print_r($_ENV);

Any hints on how to debug are welcome!

danmichaelo avatar Sep 01 '22 20:09 danmichaelo