Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

func "test" in deploy.php not working properly #1845

Closed
pquerner opened this issue May 21, 2019 · 8 comments
Closed

func "test" in deploy.php not working properly #1845

pquerner opened this issue May 21, 2019 · 8 comments

Comments

@pquerner
Copy link

Q A
Issue Type Bug, Question
Deployer Version 6.4.3
Local Machine OS MacOS 10.14.4
Remote Machine OS N/A

Description

I am trying to figure out how I can test if its the first time running on a server when deploying a TYPO3 instance.
I figured I could check the filesize of "LocalConfiguration.php". If the created symlink filesize is 0, I know I run for the first time.

Steps to reproduce

Content of deploy.php

// Tasks
task('build', function () {
    //Remove {{deploy_path}}/typo3conf if exists, cause thats the wrong folder!
    run('cd {{deploy_path}} && if [ -d typo3conf ]; then rm -rf typo3conf; fi');

    run('cd {{release_path}} && {{php_composer}} install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');

    //Is first run?
    run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf');
    if (TRUE === test('[[ -f LocalConfiguration.php && ! -s LocalConfiguration.php ]]')) {
        run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf && touch pqtest');
        run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf && rm LocalConfiguration.php');
        run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf && rm PackageStates.php');
    } else {
        run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf && ln -s {{deploy_path}}/shared/typo3conf/LocalConfiguration.php LocalConfiguration.php');
        run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf && ln -s {{deploy_path}}/shared/typo3conf/PackageStates.php PackageStates.php');
    }
});

The filesize (of a symlink file) is 0, therefore the if condition should match, (And it does match) but the condition won't get properly executed in PHP's world.

➜  typo3conf git:(master) ✗ if [[ -f LocalConfiguration.php && ! -s LocalConfiguration.php ]]; then echo 'true'; fi
true
➜  typo3conf git:(master) ✗ ls -lah
total 0
drwxr-xr-x   5 pascal.querner  staff   160B May 21 11:53 .
drwxr-xr-x   9 pascal.querner  staff   288B May 21 11:53 ..
lrwxr-xr-x   1 pascal.querner  staff    84B May 21 11:53 LocalConfiguration.php -> /Users/pq/projects/xxx/_deploytest/shared/typo3conf/LocalConfiguration.php
lrwxr-xr-x   1 pascal.querner  staff    79B May 21 11:53 PackageStates.php -> /Users/pq/projects/xxx/_deploytest/shared/typo3conf/PackageStates.php
drwxr-xr-x  10 pascal.querner  staff   320B May 21 11:53 ext
➜  typo3conf git:(master) ✗ cat LocalConfiguration.php #empty return

Output log

➤ Executing task build
[localhost] > cd /Users/pq/projects/xxx/_deploytest && if [ -d typo3conf ]; then rm -rf typo3conf; fi
[localhost] > cd /Users/pq/projects/xxx/_deploytest/releases/20190521095837 && composer install --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader
[localhost] < Loading composer repositories with package information
[localhost] < Installing dependencies from lock file
[localhost] < Dependency resolution completed in 0.002 seconds
[localhost] < Analyzed 238 packages to resolve dependencies
[localhost] < Analyzed 668 rules to resolve dependencies
[localhost] < Nothing to install or update
[localhost] < Generating optimized autoload files
[localhost] < Register typo3/console-plugin file in root package autoload definition
[localhost] < Writing TYPO3_ACTIVE_FRAMEWORK_EXTENSIONS environment variable
[localhost] < The following TYPO3 core extensions are marked as active: about, adminpanel, backend, belog, beuser, core, extbase, extensionmanager, felogin, filelist, fluid, fluid_styled_content, form, frontend, impexp, info, install, recordlist, redirects, reports, rte_ckeditor, scheduler, seo, setup, sys_note, t3editor, tstemplate, viewpage
[localhost] < Register typo3/cms-composer-installer file in root package autoload definition
[localhost] < Inserting TYPO3_COMPOSER_MODE constant
[localhost] < Generating class alias map file
[localhost] < Inserting class alias loader into main autoload.php file
[localhost] < Executing TYPO3 installer scripts
[localhost] > cd /Users/pq/projects/xxxx/_deploytest/releases/20190521095837 && cd public/typo3conf
[localhost] > if [[ -f LocalConfiguration.php && ! -s LocalConfiguration.php ]]; then echo 'true'; fi
[localhost] > cd /Users/pq/projects/xxx/_deploytest/releases/20190521095837 && cd public/typo3conf && ln -s /Users/pq/projects/xxx/_deploytest/shared/typo3conf/LocalConfiguration.php LocalConfiguration.php
[localhost] > cd /Users/pq/projects/xxx/_deploytest/releases/20190521095837 && cd public/typo3conf && ln -s /Users/pq/projects/xx/_deploytest/shared/typo3conf/PackageStates.php PackageStates.php
• done on [localhost]
@antonmedv
Copy link
Member

So, what do you think we need to fix?

@pquerner
Copy link
Author

Well, first I want to find out if I've done anything wrong.

@antonmedv
Copy link
Member

Try test('-f LocalConfiguration.php && ! -s LocalConfiguration.php')

@pquerner
Copy link
Author

pquerner commented May 22, 2019

test('-f LocalConfiguration.php && ! -s LocalConfiguration.php')
[localhost] > if -f LocalConfiguration.php && ! -s LocalConfiguration.php; then echo 'true'; fi
[localhost] < sh: -f: command not found

Other tests:

test('[ -f LocalConfiguration.php && ! -s LocalConfiguration.php ]')

Output:

[localhost] > if [ -f LocalConfiguration.php && ! -s LocalConfiguration.php ]; then echo 'true'; fi
[localhost] < sh: line 0: [: missing `]'
test('[ -f LocalConfiguration.php ] && [ ! -s LocalConfiguration.php ]')

Output:

[localhost] > if [ -f LocalConfiguration.php ] && [ ! -s LocalConfiguration.php ]; then echo 'true'; fi

(does not echo "true")

test('[[ -f LocalConfiguration.php ] && [ ! -s LocalConfiguration.php ]]')
In Process.php line 239:
                                                                                                                     
  [Symfony\Component\Process\Exception\ProcessFailedException]                                                       
  The command "if [[ -f LocalConfiguration.php ] && [ ! -s LocalConfiguration.php ]]; then echo 'true'; fi" failed.  
                                                                                                                     
  Exit Code: 2(Misuse of shell builtins)                                                                             
                                                                                                                     
  Working directory: /Users/pq/projects/xxxx/typo3-cms-xxx                                        
                                                                                                                     
  Output:                                                                                                            
  ================                                                                                                   
                                                                                                                     
                                                                                                                     
  Error Output:                                                                                                      
  ================                                                                                                   
  sh: -c: line 0: syntax error in conditional expression                                                             
  sh: -c: line 0: syntax error near `]'                                                                              
  sh: -c: line 0: `if [[ -f LocalConfiguration.php ] && [ ! -s LocalConfiguration.php ]]; then echo 'true'; fi'      
                                                                                                                     

Exception trace:
 Symfony\Component\Process\Process->mustRun() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Utility/ProcessRunner.php:51
 Deployer\Utility\ProcessRunner->run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/functions.php:301
 Deployer\run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/functions.php:345
 Deployer\test() at /Users/pq/projects/xxx/typo3-cms-xx/deploy.php:91
 Deployer\Deployer::Deployer\{closure}() at n/a:n/a
 call_user_func() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Task/Task.php:105
 Deployer\Task\Task->run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Executor/SeriesExecutor.php:60
 Deployer\Executor\SeriesExecutor->run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Console/TaskCommand.php:142
 Deployer\Console\TaskCommand->execute() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/vendor/symfony/console/Command/Command.php:252
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/vendor/symfony/console/Application.php:946
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Console/Application.php:133
 Deployer\Console\Application->doRunCommand() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/vendor/symfony/console/Application.php:248
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/vendor/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/src/Deployer.php:331
 Deployer\Deployer::run() at phar:///usr/local/Cellar/deployer/6.4.3/bin/dep/bin/dep:125
 require() at /usr/local/Cellar/deployer/6.4.3/bin/dep:4

@pquerner
Copy link
Author

pquerner commented May 22, 2019

I found the problem. I am in the wrong workdir.

[localhost] > cd /Users/pq/projects/xxx/_deploytest/releases/20190522082821 && cd public/typo3conf
[localhost] > pwd
[localhost] < /Users/pq/projects/xx/typo3-cms-xx
/Users/pq/projects/xx/typo3-cms-xx/deploy.php:92:
string(56) "/Users/pq/projects/xx/typo3-cms-xx"
[localhost] > if [[ -f LocalConfiguration.php  &&  ! -s LocalConfiguration.php ]]; then echo 'true'; else echo 'false'; fi
[localhost] < false
run('cd {{release_path}} && cd {{typo3_webroot}}/typo3conf');
    $x = run("pwd");
    var_dump($x);
    $x = run("if [[ -f LocalConfiguration.php  &&  ! -s LocalConfiguration.php ]]; then echo 'true'; else echo 'false'; fi");
    var_dump($x);
    die('LINE : ' . __LINE__ . ' METHOD : ' . __METHOD__);

Maybe test() should switch to the dir I've cd'd to ?
Passing in the fullpath works fine of course.

test('[[ -f {{release_path}}/{{typo3_webroot}}/typo3conf/LocalConfiguration.php  &&  ! -s {{release_path}}/{{typo3_webroot}}/typo3conf/LocalConfiguration.php ]]')

@antonmedv
Copy link
Member

Hmmm, but I think if it cd to dir it will break code for many mode devs.
Now this is solution:

test('[[ -f {{release_path}}/{{typo3_webroot}}/typo3conf/LocalConfiguration.php  &&  ! -s {{release_path}}/{{typo3_webroot}}/typo3conf/LocalConfiguration.php ]]')

@pquerner
Copy link
Author

pquerner commented May 23, 2019 via email

@antonmedv
Copy link
Member

Fixed in master. Please verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants