TYPO3 / Surf

Easy and powerful PHP deployment tool
https://docs.typo3.org/other/typo3/surf/master/en-us/
GNU General Public License v3.0
98 stars 53 forks source link

SURF 3.4.2 - Changes to Dependency Injection creates error 'You have requested a non-existent service "TYPO3\Surf\Domain\Model\SimpleWorkflow"' #773

Closed garvinhicking closed 1 year ago

garvinhicking commented 1 year ago

Expected Behavior

Running deployment should use Symfony DI to build. I believe the recent update from @sabbelasichon (Thank you for your work!) made a change from Symfony DI 5.x to 6.x and a change in this commit:

https://github.com/TYPO3/Surf/compare/3.4.1...master#diff-32b7574ebf31b7df6df8cb142368104942b32cf39cd292acb02171f05479b92a

introced it. We get the error message below; sadly I'm a bit short on time and cannot investigate further, but if it doesn't ring a bell for any of you quickly, I can try to spend time on it in a few weeks. So long we revert back to the working 3.3.15 version.

Actual Behavior

An error appears about a non-existant service. See below.

Steps to Reproduce the Problem

Use this composer.json on a PHP 8.1 / 8.2 install:

{
  "name": "debug/surf",
  "repositories": [
    {
      "type": "composer",
      "url": "https://composer.typo3.org/"
    }
  ],
  "require": {
    "typo3/surf": "^3.0"
  }
}

Run composer install.

Here's our workflow definition (Production.Staging.php); there are a lot of config variables, you cannot use it directly, but maybe something is obviously wrong with it on how DI would need implentation now:

<?php
$mainContext = 'Production';
$subContext  = 'Staging';
$environment = $mainContext . '.' . $subContext;

// Get SSH deployment target
// Allows two notations, either "user@host" or just "host".
$sshParts = explode('@', $configuration['hostName']);

if (isset($sshParts[1])) {
    $sshUser  = $sshParts[0];
    $hostName = $sshParts[1];
} else {
    $sshUser  = `whoami`;
    $hostName = $sshParts[0];
}

// Ensures backwards compatibility with versions, where hostPort is not declared in the configuration array.
$sshPort = $configuration['hostPort'] ?? 22;

// Setup deployment target
$liveNode = new \TYPO3\Surf\Domain\Model\Node($environment);
$liveNode->setHostname($hostName)
    ->setOption('username', $sshUser)
    ->setOption('port', $sshPort);

if (isset($configuration['_sshKey']) && strlen($configuration['_sshKey'])) {
    $liveNode->setOption('privateKeyFile', $configuration['_sshKey']);
}

// Propagate configuration values to SURF Options
$application = new \TYPO3\Surf\Application\TYPO3\CMS($configuration['applicationName']);
$application->addNode($liveNode)
    ->setOption('useApplicationWorkspace',      $configuration['_useApplicationWorkspace'])
    ->setOption('phpBinaryPathAndFilename',     $configuration['phpBinary'])
    ->setOption('composerCommandPath',          $configuration['_composerCommandPath'])
    ->setOption('keepReleases',                 $configuration['keepReleases'])
    ->setOption('repositoryUrl',                $configuration['repositoryUrl'])
    ->setOption('branch',                       $configuration['gitBranch'])

    ->setOption('scriptFileName',               $configuration['typo3ConsoleBinary'])
    ->setOption('typo3CliBinary',               $configuration['_typo3CliBinary'])
    ->setOption('webDirectory',                 $configuration['webDirectory'])
    ->setOption('baseUrl',                      $configuration['baseUrl'])

    ->setOption('context',                      $mainContext . '/' . $subContext)
    ->setOption('rsyncExcludes',                $configuration['rsyncExcludes'])
    ->setOption('scriptIdentifier',             time())

    ->setOption(
        TYPO3\Surf\Task\TYPO3\CMS\FlushCachesTask::class . '[arguments]',
        []
    )

    ->setOption(
        'scriptBasePath',
        \Neos\Utility\Files::concatenatePaths([$deployment->getWorkspacePath($application), $configuration['webDirectory']])
    )
    ->setDeploymentPath($configuration['deploymentPath']);

$deployment->addApplication($application);

$symlinks = $commandsAfterSymlinks = [];

$deployment->onInitialize(function() use ($deployment, $application, $configuration, $symlinks, $commandsAfterSymlinks) {
    $workflow = $deployment->getWorkflow();
    // Some irrelevant defineTask/addTasks stripped
});

Maybe it's relevant; our Production.Staging.php file actually looks like this:

<?php
$configuration = [
  // ...
];

require __DIR__ . '/workflow.php';

and then the PHP-Code above is called workflow.php. We use this to have the same workflow for multiple recipes, depending on a base configuration.

Now the actual error that we get:

In Container.php line 272:

  [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
  You have requested a non-existent service "TYPO3\Surf\Domain\Model\SimpleWorkflow".  

Exception trace:
  at /var/www/html/deployment/vendor/symfony/dependency-injection/Container.php:272
 Symfony\Component\DependencyInjection\Container->make() at /var/www/html/deployment/vendor/symfony/dependency-injection/Container.php:220
 Symfony\Component\DependencyInjection\Container->get() at /var/www/html/deployment/vendor/typo3/surf/src/Domain/Model/Deployment.php:500
 TYPO3\Surf\Domain\Model\Deployment->createSimpleWorkflow() at /var/www/html/deployment/vendor/typo3/surf/src/Domain/Model/Deployment.php:125
 TYPO3\Surf\Domain\Model\Deployment->initialize() at /var/www/html/deployment/vendor/typo3/surf/src/Integration/Factory.php:54
 TYPO3\Surf\Integration\Factory->getDeployment() at /var/www/html/deployment/vendor/typo3/surf/src/Command/DeployCommand.php:62
 TYPO3\Surf\Command\DeployCommand->execute() at /var/www/html/deployment/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at /var/www/html/deployment/vendor/symfony/console/Application.php:1040
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/deployment/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at /var/www/html/deployment/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at /var/www/html/deployment/vendor/typo3/surf/src/Cli/Symfony/ConsoleApplication.php:37
 TYPO3\Surf\Cli\Symfony\ConsoleApplication->run() at /var/www/html/deployment/vendor/typo3/surf/bin/surf:28
 include() at /var/www/html/deployment/vendor/bin/surf:120

deploy [--configurationPath [CONFIGURATIONPATH]] [--force] [--] [<deploymentName>]

Failed to execute command deployment/vendor/bin/surf deploy Production.Staging -vvv: exit status 1

Specifications

sabbelasichon commented 1 year ago

@garvinhicking Thanks. I should simulate the whole process in the CI to avoid such regressions. Thanks. I have tried and fixed it with the latest release.

garvinhicking commented 1 year ago

@sabbelasichon You rock, that's aweome. Seems to be working now for us! Many, many thanks. Have a nice family-weekend :-)

sabbelasichon commented 1 year ago

Same for you