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
"extra": {
"docker4drupal": {
"projectname": "[NAME OF CURRENT DIRECTORY]",
"live": {
"root": "",
"uri": "",
"host": "",
"user": ""
},
"drupal": {
"version": 8
},
......@@ -275,7 +281,38 @@ That allows you to simply call the following command to only update docker4drupa
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
......
......@@ -67,8 +67,9 @@ class Handler {
* Configure Drupal Project for Docker.
*
* @param ScriptEvent $event
* @param bool $overwrite
*/
public function configureProject($event) {
public function configureProject($event, $overwrite = FALSE) {
// We only do the fancy stuff for developers
if (!$event->isDevMode()) {
......@@ -118,7 +119,10 @@ class Handler {
$options['webRoot'] = $webRoot . '/';
foreach ($this->getFiles($projectRoot, $webRoot, $settingsPath) as $template => $def) {
$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'));
$rendered = $twig->render($template, $options);
if (!empty($def['add2yaml']) && isset($options[$template])) {
......@@ -180,9 +184,11 @@ class Handler {
],
'aliases.yml' => [
'dest' => $projectRoot . '/drush',
'add2yaml' => TRUE,
],
'drush.yml' => [
'dest' => $projectRoot . '/drush',
'add2yaml' => TRUE,
],
'.env' => [
'dest' => $projectRoot,
......@@ -202,6 +208,12 @@ class Handler {
'docker0' => [
'ip' => $this->getLocalIpv4('docker0'),
],
'live' => [
'root' => '',
'uri' => '',
'host' => '',
'user' => '',
],
'drupal' => [
'version' => '8',
],
......
......@@ -52,7 +52,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface {
*/
public static function config($event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->configureProject($event);
$handler->configureProject($event, TRUE);
}
}
......@@ -6,8 +6,8 @@ $aliases['dev'] = array(
);
$aliases['live'] = array(
'root' => '',
'uri' => '',
'remote-host' => '',
'remote-user' => '',
'root' => '{{ live.root }}',
'uri' => '{{ live.uri }}',
'remote-host' => '{{ live.host }}',
'remote-user' => '{{ live.user }}',
);
......@@ -4,7 +4,7 @@ sites:
root: '/var/www/html/{{ webRoot }}'
uri: '{{ projectname }}.docker.localhost:8000'
live:
root: ''
uri: ''
remote-host: ''
remote-user: ''
root: '{{ live.root }}'
uri: '{{ live.uri }}'
remote-host: '{{ live.host }}'
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