Skip to content

Commit 34d513d

Browse files
committed
Case 27689; Allow root to be overriden by environment variables
1 parent 742e921 commit 34d513d

File tree

9 files changed

+32
-40
lines changed

9 files changed

+32
-40
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ e.g. https://raw.githubusercontent.com/dennisinteractive/drupal_console_commands
7777
- **-h** Show all the available arguments and options
7878
- **--no-interaction** Will execute the command without asking any optional argument
7979

80+
# Environment variables
81+
By default, the commands will use parameters from the site.yml, but it is possible to override them using environment variables.
82+
83+
For example, to override the root directory you can set the variable before calling `site:build`
84+
85+
`export site_destination_directory="/directory/"`
86+
8087
# Usage example
8188
```
8289
drupal site:build

chain/chain-site-build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: drupal site:build --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos"
1+
# Usage: drupal site:build --placeholder="name:subscriptions"
22
command:
33
name: site:build
44
description: 'Builds a new site.'
@@ -14,4 +14,3 @@ commands:
1414
options:
1515
placeholder:
1616
- 'name:%{{name}}'
17-
- 'root:%{{root|/vagrant/repos}}'

chain/chain-site-compile-artifact.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

chain/chain-site-compile.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: drupal site:compile --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos"
1+
# Usage: drupal site:compile --placeholder="name:subscriptions"
22
command:
33
name: site:compile
44
description: 'Compiles the source, downloading and extracting the packages.'
@@ -8,12 +8,12 @@ commands:
88
arguments:
99
name: '%{{name}}'
1010
options:
11-
destination-directory: '%{{root|/vagrant/repos}}/%{{name}}'
11+
destination-directory: '${{site_destination_directory}}'
1212
# Run npm
1313
- command: exec
1414
arguments:
15-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name package.json -execdir sh -c "npm install" \;'
15+
bin: 'cd ${{site_destination_directory}}/web; find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name package.json -execdir sh -c "npm install" \;'
1616
# Run grunt
1717
- command: exec
1818
arguments:
19-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name Gruntfile.js -execdir sh -c "grunt" \;'
19+
bin: 'cd ${{site_destination_directory}}/web; find . -type d \( -name node_modules -o -name contrib -o -path ./core \) -prune -o -name Gruntfile.js -execdir sh -c "grunt" \;'

chain/chain-site-construct.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Usage: drupal site:construct --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos"
1+
# Usage: drupal site:construct --placeholder="name:subscriptions"
22
command:
33
name: site:construct
44
description: 'Sets the site up based on current configuration and database.'
55
commands:
66
# Clear cache
77
- command: exec
88
arguments:
9-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; drush cr;'
9+
bin: 'cd ${{site_destination_directory}}/web; drush cr;'
1010
# Set default drush alias
1111
- command: exec
1212
arguments:
13-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; drush site-set @site;'
13+
bin: 'cd ${{site_destination_directory}}/web; drush site-set @site;'
1414
# Run db updates
1515
- command: exec
1616
arguments:
17-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; drush updb -y;'
17+
bin: 'cd ${{site_destination_directory}}/web; drush updb -y;'
1818
# Import configuration twice to fix a problem with config import when new modules are added to core.extensions.yml
1919
- command: exec
2020
arguments:
21-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; drush cim -y; drush cim -y'
21+
bin: 'cd ${{site_destination_directory}}/web; drush cim -y; drush cim -y'
2222
# Clear cache
2323
- command: exec
2424
arguments:
25-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/web; drush cr;'
25+
bin: 'cd ${{site_destination_directory}}/web; drush cr;'

chain/chain-site-rebuild-prod.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: drupal site:rebuild:prod --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos"
1+
# Usage: drupal site:rebuild:prod --placeholder="name:subscriptions"
22
command:
33
name: site:rebuild:prod
44
description: 'Peforms necessary steps to build the site from a given source.'
@@ -8,10 +8,8 @@ commands:
88
options:
99
placeholder:
1010
- 'name:%{{name}}'
11-
- 'root:%{{root|/vagrant/repos}}'
1211
# Build the site based on existing setup.
1312
- command: site:construct
1413
options:
1514
placeholder:
1615
- 'name:%{{name}}'
17-
- 'root:%{{root|/vagrant/repos}}'

chain/chain-site-rebuild.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: drupal site:rebuild --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos"
1+
# Usage: drupal site:rebuild --placeholder="name:subscriptions"
22
command:
33
name: site:rebuild
44
description: 'Peforms necessary steps to build the site from a given source.'
@@ -8,7 +8,6 @@ commands:
88
options:
99
placeholder:
1010
- 'name:%{{name}}'
11-
- 'root:%{{root|/vagrant/repos}}'
1211
# Generate the settings.
1312
- command: site:configure
1413
options:
@@ -23,4 +22,3 @@ commands:
2322
options:
2423
placeholder:
2524
- 'name:%{{name}}'
26-
- 'root:%{{root|/vagrant/repos}}'

chain/chain-site-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Usage: drupal site:test --placeholder="name:subscriptions" --placeholder="root:/vagrant/repos" --placeholder="behat_params:--tags=bannerimage"
1+
# Usage: drupal site:test --placeholder="name:subscriptions" --placeholder="behat_params:--tags=bannerimage"
22
command:
33
name: site:test
44
description: 'Sets the test suites up and then runs them.'
@@ -14,8 +14,8 @@ commands:
1414
# Run Behat
1515
- command: exec
1616
arguments:
17-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}/tests; ./behat %{{behat_params|-n}};'
17+
bin: 'cd ${{site_destination_directory}}/tests; ./behat %{{behat_params|-n}};'
1818
# Run phpunit
1919
- command: exec
2020
arguments:
21-
bin: 'cd %{{root|/vagrant/repos}}/%{{name}}; ./vendor/bin/phpunit;'
21+
bin: 'cd ${{site_destination_directory}}; ./vendor/bin/phpunit;'

src/Command/SiteBaseCommand.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ protected function _validateDestination(InputInterface $input) {
275275
$this->destination = '/tmp/' . $this->siteName;
276276
}
277277

278+
// Allow destination to be overriden by environment variable. i.e.
279+
// export site_destination_directory="/directory/"
280+
if (!getenv('site_destination_directory')) {
281+
putenv("site_destination_directory=$this->destination");
282+
}
283+
else {
284+
$this->destination = getenv('site_destination_directory');
285+
}
286+
278287
// Make sure we have a slash at the end.
279288
if (substr($this->destination, -1) != '/') {
280289
$this->destination .= '/';

0 commit comments

Comments
 (0)