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

OPENEUROPA-1739: Add services setup command. #104

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

Conversation

dxvargas
Copy link
Member

OPENEUROPA-1739

Description

Add services setup command and tests.

@dxvargas dxvargas force-pushed the OPENEUROPA-1739 branch 4 times, most recently from 5823b25 to 2186813 Compare August 27, 2019 11:37
Copy link
Member

@voidtek voidtek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somes remarks.

src/Commands/AbstractDrupalCommands.php Show resolved Hide resolved
src/Commands/AbstractDrupalCommands.php Outdated Show resolved Hide resolved
src/Commands/AbstractDrupalCommands.php Outdated Show resolved Hide resolved
tests/Commands/DrupalCommandsTest.php Outdated Show resolved Hide resolved
tests/Commands/DrupalCommandsTest.php Outdated Show resolved Hide resolved
tests/Commands/DrupalCommandsTest.php Outdated Show resolved Hide resolved
voidtek
voidtek previously approved these changes Aug 28, 2019
Copy link
Member

@voidtek voidtek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested.

Copy link
Member

@ademarco ademarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed solution does not implement what the issue is asking. What is proposed here can be achieved via YAML commands with a simple:

  setup:services:
    - { task: "process", source: "services.yml", destination: "${drupal.root}/sites/default/services.yml" }

We basically need to be able to have something like the following in the local runner.yml:

  service_parameters:
    cors.config:
      enabled: ${my_settings.cors.config_enabled}

And this to produce a sites/default/services.yml with:

parameters:
  service_parameters:
    cors.config:
      enabled: false

@dxvargas dxvargas force-pushed the OPENEUROPA-1739 branch 3 times, most recently from 365c822 to 88c15e2 Compare September 4, 2019 14:14
Copy link
Member

@ademarco ademarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on one of our components and it works well, I've just pointed out some changes, after this round I think we can close it.

composer.json Outdated
@@ -10,12 +10,16 @@
"consolidation/robo": "^1.4",
"gitonomy/gitlib": "^1.0",
"nuvoleweb/robo-config": "^0.2.1",
"jakeasmith/http_build_url": "^1.0.1"
"jakeasmith/http_build_url": "^1.0.1",
"symfony/yaml": ">3.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checked against Symfony's major upgrading policy, we should come up with a proper version string here.

Not that Drupal core is already on 3.4.* which should be deprecation free.

Something like this

image

Copy link
Member Author

@dxvargas dxvargas Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok 3.4 or 4.

composer.json Outdated
},
"require-dev": {
"openeuropa/code-review": "~1.0.0-beta3",
"phpunit/phpunit": "~5.5||~6.0"
},
"_readme": [
"We need require a version of 'symfony/yaml' higher then '3.1' since versions before 3.1.0 don't have dumper 'DUMP' constants available and 3.1.0 breaks permissions setup in tests."
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not needed, it's only needed when we fix dependencies when they break builds etc. not when we need a specific version because we use its API, for that having it in the requirements is enough.

Copy link
Member Author

@dxvargas dxvargas Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me there are two kind of dependencies. The first is when we need the package and it wouldn't be fetched if out of composer requirements. Second kind is like here when we're not really requiring the package since it was already being fetched, we're only adding it to adjust the accepted versions. For this later kind of dependencies I think it's good to understand why it was needed and to differentiate it since sometime soon we may remove it from the list, when other packages update their requirements.

Just saying, no problem, I've removed it.

file_put_contents($services_destination_file, 'parameters: false');
if ($configs['force']) {
$force = ' --force';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force is either true or not set at all, it's a valueless parameter, we can remove the inner if.

Copy link
Member Author

@dxvargas dxvargas Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "force" option in configuration wasn't applying directly to the force option in the command, it was also being used to know if a previous service.yml should happen.

But ok let's avoid confusion, I've changed the logic here and I think now it's clear.

settings:
foo: bar
- config:
force: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

force: false is not a thing, 😄 it's either there or it's not. If you want to test it for false then don't set it.

Copy link
Member Author

@dxvargas dxvargas Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

// Read given parameters.
$service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters', []);
$dumper = new Dumper(2);
$yaml = $dumper->dump($service_parameters, PHP_INT_MAX, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this basically prints out a YAML file as Drupal expects to let's move this two lines in a separated protected method, so it can be used on all Drupal commands.

$services_destination_file = $options['root'] . '/sites/' . $options['sites-subdir'] . '/services.yml';

$collection = [];
if (true === (bool) $options['force'] || !file_exists($services_destination_file)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$options['force'] is either true or false, Robo internals make sure of that, we don't need casting.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

$force = '';
if (isset($configs['force'])) {
mkdir($services_destination_dir, 0777, true);
file_put_contents($services_destination_file, 'parameters: false');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have 'parameters: false' as part of the fixture. If more comfortable you can create a separate test for the force option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's in fixture now.

*
* This command will add the configuration under service_parameters present in
* runner.yml into "services.yml" file in the site directory.
*

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add example. Something like:

> drupal:
>   service_parameters:
>     session.storage.options:
>       cookie_lifetime: 0

configuration:
drupal:
service_parameters:
cors.config: false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

 cors.config:
    enabled: false

@msnassar
Copy link

Tested... Works perfectly :)

Comment on lines +342 to +343
$service_parameters['parameters'] = $this->getConfig()->get('drupal.service_parameters', []);
$yaml = $this->dumpYaml($service_parameters);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This better go to the IF statement (line 349) as they are used in the statement only.

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.

4 participants