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

add support of multiple values in host label #3899

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

magicaner
Copy link

@magicaner magicaner commented Sep 18, 2024

Allow usage of (c1 OR c2) AND (c3 or c4) condition to select() query

The existing solution does not allow OR conditions in the scope of single label value in the select query.
The following example is only possible:

task(...).select('stage=prod & role=web, stage=qa & role=web')

In other words, only the following conditions could be defined in the query:

(condition1 and condition2) or (condition3 and condition4)

Example:

stage=prod & role=web, stage=qa & role=web, stage=qa & role=db, stage=prod & role=db

But in most cases, we need the following query:

(condition1 or condition2) and (condition3 or condition4)

Example:

stage=prod|qa & role=web|db

The PR is adding that support.

Example of usage:

Define hosts

host('prod.example.org') 
    ->set('hostname', 'example.cloud.google.com')
    ->setLabel( 'stage' => 'prod' 'role' => ['build','web','redis'] ])
;
host('prod-db.example.org')
    ->set('hostname', 'example.cloud.google.com')
    ->setLabel( 'stage' => 'prod' 'role' => ['db'] ])
; 
host('qa.example.org')
    ->set('hostname', 'example.cloud.google.com')
    ->setLabel( 'stage' => 'qa' 'role' => ['build','web','redis','db'] ]); 

host('dev.example.org')
    ->set('hostname', 'example.cloud.google.com')
    ->setLabel( 'stage' => 'dev' 'role' => ['build','web','redis','db'] ]); 

Define tasks

desc('Reload Http');
task('reload:http', function () {
    run('/usr/sbin/service nginx reload &> /dev/null');
})->select('stage=prod|qa|dev & role=web');
  • Bug fix #…?

  • New feature?

  • BC breaks?

  • Tests added?

  • Docs added?

    Please, regenerate docs by running next command:
    $ php bin/docgen
    

- example of usage:
  host('prod.example.org')
      ->set('hostname', 'example.cloud.google.com');
      ->setLabel(
          'state' => 'prod'
          'role' => ['build','web','redis']
      ]);

  host('prod-db.example.org')
        ->set('hostname', 'example.cloud.google.com');
        ->setLabel(
            'state' => 'prod'
            'role' => ['db']
        ]);
  host('qa.example.org')
      ->set('hostname', 'example.cloud.google.com');
      ->setLabel(
          'state' => 'qa'
          'role' => ['build','web','redis','db']
      ]);
  host('dev.example.org')
        ->set('hostname', 'example.cloud.google.com');
        ->setLabel(
            'state' => 'qa'
            'role' => ['build','web','redis','db']
        ]);
  ...

  desc('Clear pagespeed');
  task('pagespeed:clear', function () {
      run("rm -rf {{deploy_path}}/{{pagespeed_path}}* || true");
  })->select('stage=prod|qa & role=web'); // assuming pagespeed is installed only on prod and qa envs
@antonmedv
Copy link
Member

Nice!

@antonmedv
Copy link
Member

Actually, what about implementing a better support with and or operators and ( ) brackets?

@antonmedv
Copy link
Member

Please fix tests and add docs.

@antonmedv
Copy link
Member

test / e2e is failing for other reasos.

@magicaner
Copy link
Author

magicaner commented Sep 23, 2024

Actually, what about implementing a better support with and or operators and ( ) brackets?

I don't feel like that is necessary. The feature in PR covers all my requirements at the moment.
Adding brakets will increase the complexity of expression. My goal was to improve its readability. Visual readability.
Can you provide the example of what you mean?

@magicaner magicaner force-pushed the adjust-select-to-support-OR-condition branch 2 times, most recently from 4f2f2ae to fa6c4cb Compare September 23, 2024 07:40
@magicaner magicaner force-pushed the adjust-select-to-support-OR-condition branch from fa6c4cb to 46f2a23 Compare September 23, 2024 07:40
@magicaner
Copy link
Author

@antonmedv I have updated docs and tests.

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

Successfully merging this pull request may close these issues.

2 participants