Skip to content
Snippets Groups Projects
Commit e8a8ff88 authored by jurgenhaas's avatar jurgenhaas
Browse files

#7 Always refresh settings files, allow live alias parameters in composer.json

parent 0e01f5e1
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -191,6 +191,12 @@ To overwrite the default settings for the Docker environment, add the relevant p ...@@ -191,6 +191,12 @@ To overwrite the default settings for the Docker environment, add the relevant p
"extra": { "extra": {
"docker4drupal": { "docker4drupal": {
"projectname": "[NAME OF CURRENT DIRECTORY]", "projectname": "[NAME OF CURRENT DIRECTORY]",
"live": {
"root": "",
"uri": "",
"host": "",
"user": ""
},
"drupal": { "drupal": {
"version": 8 "version": 8
}, },
...@@ -275,7 +281,38 @@ That allows you to simply call the following command to only update docker4drupa ...@@ -275,7 +281,38 @@ That allows you to simply call the following command to only update docker4drupa
composer d4d composer d4d
``` ```
Note, that docker4drupal configuration does not overwrite existing setting files. If you want to get them changed, you have to delete them first. Note, that docker4drupal configuration **does overwrite** existing setting files when you run this script.
Therefore, you can add custom content to the settings files by adding another key to the `extra/docker4drupal` section with the file name as the key and additional settings underneath. Example:
```json
{
"extra": {
"docker4drupal": {
"docker-compose.yml": {
"services": {
"php": {
"environment": {
"MY_VAR": "value"
}
},
"mariadbd6": {
"image": "wodby/mariadb:10.1",
"environment": {
"MYSQL_ROOT_PASSWORD": "password",
"MYSQL_DATABASE": "drupal",
"MYSQL_USER": "drupal",
"MYSQL_PASSWORD": "drupal"
}
}
}
}
}
}
}
```
This will add another environment variable to the php container and define a second mariadb container named `mariadbd6` which may be used e.g. for a migration from a separate database.
## Tipps & Tricks ## Tipps & Tricks
......
...@@ -67,8 +67,9 @@ class Handler { ...@@ -67,8 +67,9 @@ class Handler {
* Configure Drupal Project for Docker. * Configure Drupal Project for Docker.
* *
* @param ScriptEvent $event * @param ScriptEvent $event
* @param bool $overwrite
*/ */
public function configureProject($event) { public function configureProject($event, $overwrite = FALSE) {
// We only do the fancy stuff for developers // We only do the fancy stuff for developers
if (!$event->isDevMode()) { if (!$event->isDevMode()) {
...@@ -118,7 +119,10 @@ class Handler { ...@@ -118,7 +119,10 @@ class Handler {
$options['webRoot'] = $webRoot . '/'; $options['webRoot'] = $webRoot . '/';
foreach ($this->getFiles($projectRoot, $webRoot, $settingsPath) as $template => $def) { foreach ($this->getFiles($projectRoot, $webRoot, $settingsPath) as $template => $def) {
$file = $def['dest'] . '/' . $template; $file = $def['dest'] . '/' . $template;
if (!$fs->exists($file)) { if ($overwrite || !$fs->exists($file)) {
if ($fs->exists($file)) {
$fs->rename($file, $file . '.orig');
}
$twig_loader->setTemplate($template, file_get_contents($pluginRoot . '/templates/' . $template . '.twig')); $twig_loader->setTemplate($template, file_get_contents($pluginRoot . '/templates/' . $template . '.twig'));
$rendered = $twig->render($template, $options); $rendered = $twig->render($template, $options);
if (!empty($def['add2yaml']) && isset($options[$template])) { if (!empty($def['add2yaml']) && isset($options[$template])) {
...@@ -180,9 +184,11 @@ class Handler { ...@@ -180,9 +184,11 @@ class Handler {
], ],
'aliases.yml' => [ 'aliases.yml' => [
'dest' => $projectRoot . '/drush', 'dest' => $projectRoot . '/drush',
'add2yaml' => TRUE,
], ],
'drush.yml' => [ 'drush.yml' => [
'dest' => $projectRoot . '/drush', 'dest' => $projectRoot . '/drush',
'add2yaml' => TRUE,
], ],
'.env' => [ '.env' => [
'dest' => $projectRoot, 'dest' => $projectRoot,
...@@ -202,6 +208,12 @@ class Handler { ...@@ -202,6 +208,12 @@ class Handler {
'docker0' => [ 'docker0' => [
'ip' => $this->getLocalIpv4('docker0'), 'ip' => $this->getLocalIpv4('docker0'),
], ],
'live' => [
'root' => '',
'uri' => '',
'host' => '',
'user' => '',
],
'drupal' => [ 'drupal' => [
'version' => '8', 'version' => '8',
], ],
......
...@@ -52,7 +52,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface { ...@@ -52,7 +52,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
*/ */
public static function config($event) { public static function config($event) {
$handler = new Handler($event->getComposer(), $event->getIO()); $handler = new Handler($event->getComposer(), $event->getIO());
$handler->configureProject($event); $handler->configureProject($event, TRUE);
} }
} }
...@@ -6,8 +6,8 @@ $aliases['dev'] = array( ...@@ -6,8 +6,8 @@ $aliases['dev'] = array(
); );
$aliases['live'] = array( $aliases['live'] = array(
'root' => '', 'root' => '{{ live.root }}',
'uri' => '', 'uri' => '{{ live.uri }}',
'remote-host' => '', 'remote-host' => '{{ live.host }}',
'remote-user' => '', 'remote-user' => '{{ live.user }}',
); );
...@@ -4,7 +4,7 @@ sites: ...@@ -4,7 +4,7 @@ sites:
root: '/var/www/html/{{ webRoot }}' root: '/var/www/html/{{ webRoot }}'
uri: '{{ projectname }}.docker.localhost:8000' uri: '{{ projectname }}.docker.localhost:8000'
live: live:
root: '' root: '{{ live.root }}'
uri: '' uri: '{{ live.uri }}'
remote-host: '' remote-host: '{{ live.host }}'
remote-user: '' remote-user: '{{ live.user }}'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment