Skip to content

Commit

Permalink
feat(configuration): allow additionalNeeds for host-configurations …
Browse files Browse the repository at this point in the history
…to declare additional needs

Currently a project can declare a list of `needs` globally or on a host-bases. `additionalNeeds`
allows user to append additional needs to the global list of needs for a particular host-config
  • Loading branch information
stmh committed Jul 16, 2022
1 parent bdfe66d commit 5edacb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/configuration.md
Expand Up @@ -52,6 +52,8 @@ List here all needed methods for that type of project. Available methods are:
* `laravel` for laravel-based applications
* `k8s` to interact with an application hosted in a Kubernetes cluster

Needs can be set also per `host`. You can also declare `additionalNeeds` per host. If you need to "remove" a need on a per host-bases you need to completely override `needs`.

**Example for drupal 7**

```yaml
Expand Down Expand Up @@ -151,6 +153,7 @@ This will print all host configuration for the host `staging`.
The main use-case is to run different scripts per type, see the `common`-section.
* `rootFolder` the web-root-folder of the installation, typically exposed to the public.
* `needs` a list of needed methods, if not set, the globally set `needs` gets used.
* `additionalNeeds` a list of additional needs. The list will be appended to the global or per-host `needs`-declaration.
* `configName` is set by phabalicious, it's the name of the configuration
* `supportsInstalls`, default is true for `types` != `prod`. If sent to true you can run the `install`-task
* `supportsCopyFrom`, default is true. If set to true, you can use that configuration as a source for the `copy-from`-task.
Expand Down
4 changes: 4 additions & 0 deletions src/Configuration/ConfigurationService.php
Expand Up @@ -714,6 +714,10 @@ private function validateHostConfig($config_name, Node $data)
$data->get('needs')->push('script');
}
}
if ($data->has('additionalNeeds')) {
$data->get('additionalNeeds')->ensureArray();
$data->get('needs')->merge($data->get('additionalNeeds'));
}

$data = $this->applyDefaults($data, new Node($defaults, 'host defaults'), $this->disallowDeepMergeForKeys);
/**
Expand Down
11 changes: 11 additions & 0 deletions tests/ConfigurationServiceTest.php
Expand Up @@ -217,6 +217,17 @@ public function testMissingRemoteYaml()
$config = $this->config->getHostConfig("test");
}

public function testAdditionalNeeds()
{

$this->config->getMethodFactory()->addMethod(new SshMethod($this->logger));
$this->config->getMethodFactory()->addMethod(new ScriptMethod($this->logger));
$this->config->readConfiguration(__DIR__ . '/assets/additional-needs-tests');
$needs = $this->config->getHostConfig('test')->get('needs');
$this->assertContains('ssh', $needs);
$this->assertContains('script', $needs);
}

public function testResolveInheritanceRefs()
{
$data = new Node([
Expand Down
14 changes: 14 additions & 0 deletions tests/assets/additional-needs-tests/fabfile.yaml
@@ -0,0 +1,14 @@
name: additional-needs-test


needs:
- scripts

hosts:
test:
host: localhost
user: root
additionalNeeds:
- ssh


0 comments on commit 5edacb2

Please sign in to comment.