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

TYPO3 RunCommandTask affects repository directory #784

Closed MarcoRemy closed 7 months ago

MarcoRemy commented 7 months ago

To fix any missing files and folders, I added a RunCommandTask with install:fixfolderstructure to the deployment of my TYPO3 package.

// /opt/typo3-cms-repo/.surf/Development.php

/* ... */

$deployment
    ->addApplication($app)
    ->onInitialize(
        function () use ($deployment, $app) {
            $deployment->getWorkflow()
                /* ... */

                // does not work as expected
                ->defineTask('FixFolderStructureTask', \TYPO3\Surf\Task\TYPO3\CMS\RunCommandTask::class, ['command' => 'install:fixfolderstructure'])
                ->afterTask(\TYPO3\Surf\Task\TYPO3\CMS\SetUpExtensionsTask::class, 'FixFolderStructureTask', $app)
        }
    );

Log output

localhost (TYPO3-App) FixFolderStructureTask
(localhost): "test -f '/srv/www/typo3-deployed/releases/20240408154751/vendor/bin/typo3'"
(localhost): "cd '/srv/www/typo3-deployed/releases/20240408154751' && TYPO3_CONTEXT='Development' php 'vendor/bin/typo3' 'install:fixfolderstructure'"
> The following directory structure has been fixed:
> Directory /public/typo3temp successfully created.
> Fixed permission on /public/typo3temp.
> File /public/typo3temp/index.html successfully created.
> Set content to /public/typo3temp/index.html
> Fixed permission on /public/typo3temp/index.html.
> Directory /public/typo3temp/assets successfully created.
> Fixed permission on /public/typo3temp/assets.
> Directory /public/typo3temp/assets/compressed successfully created.
> Fixed permission on /public/typo3temp/assets/compressed.
...

Expected Behavior

According to the log output the working dir is correctly changed to the target release directory before the command is executed. So the working directory will be /srv/www/typo3-deployed/releases/20240408154751 and the dirs and files should be created in there.

/srv/www/typo3-deployed/releases/20240408154751
- public/typo3temp
- public/typo3temp/index.html
- ...

Actual Behavior

Instead, the action is performed inside the initial repo directory from which the deployment was called.

/opt/typo3-cms-repo
- public/typo3temp
- public/typo3temp/index.html
- ...

This leaves the target release directory completely unaffected.

Side note: The command language:update won't download language files into the target release dir /srv/www/typo3-deployed/releases/20240408154751/var/labels but /opt/typo3-cms-repo/var/labels

Specifications

simonschaufi commented 7 months ago

This is rather a support issue than an actual bug. Would you be willing to sponsor me for support?

MarcoRemy commented 7 months ago

This is actually an unexpected behaviour. The command should not affect the source git repository dir after all.

I've spent quite some time understanding the functionality of Surf and I don't think I've made a mistake. Reporting this issue is really the last resort.

I have just discovered that this only happens when Surf is run from the local Composer installation vendor/bin/surf. If the directly downloaded phar is used alone with the deployment configuration file (outside the repo) the process works as expected.

There may be a problem switching to the correct working directory. The command is executed in the git repo where surf was called from.

I'll leave this here and no further help is needed. However, I still consider this a bug.

Thank you for your reply.