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

Move Traefik container into central standalone project and increase Drush functionality

parent 73e6f53c
No related branches found
Tags v1.1.1
No related merge requests found
Pipeline #
......@@ -12,8 +12,7 @@ use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\Event as ScriptEvent;
use Symfony\Component\Filesystem\Filesystem;
use Rych\Random\Random;
use Rych\Random\Encoder\Base64Encoder;
use Symfony\Component\Yaml\Yaml;
class Handler {
......@@ -135,20 +134,60 @@ class Handler {
if ($fs->exists(($settingsPhpFile))) {
$settingsPhp = file_get_contents($settingsPhpFile);
if (strpos($settingsPhp, 'settings.docker.php') === FALSE) {
$settingsPhp .= "\n\nif (file_exists(__DIR__ . '/settings.docker.php')) {include __DIR__ . '/settings.docker.php';}\n";
$settingsPhp .= "\n\nif (file_exists(__DIR__ . '/settings.docker.php')) {\n include __DIR__ . '/settings.docker.php';\n}\n";
file_put_contents($settingsPhpFile, $settingsPhp);
}
}
// Initialize local git working copy
try {
$this->git('ignore docker-compose.yml');
$this->git('ignore settings.docker.php');
foreach ($this->getFiles($projectRoot, $webRoot, $settingsPath) as $template => $def) {
$this->git('ignore ' . $template);
}
}
catch (\Exception $ex) {
// We're ignoring this for now
}
// Update host wider traefik container
$traefikPath = $_SERVER['HOME'] . '/.traefik';
$traefikFile = $traefikPath . '/docker-compose.yml';
if ($fs->exists($traefikFile)) {
$traefik = Yaml::parse(file_get_contents($traefikFile));
}
else {
$fs->mkdir($traefikPath);
$traefik = [
'version' => '2',
'services' => [
'traefik' => [
'image' => 'traefik',
'restart' => 'unless-stopped',
'command' => '-c /dev/null --web --docker --logLevel=DEBUG',
'networks' => [],
'ports' => [
'8000:80',
'8080:8080',
],
'volumes' => [
'/var/run/docker.sock:/var/run/docker.sock',
],
],
],
'networks' => [],
];
}
if (!in_array($options['projectname'], $traefik['services']['traefik']['networks'])) {
$traefik['services']['traefik']['networks'][] = $options['projectname'];
$traefik['networks'][$options['projectname']] = [
'external' => [
'name' => $options['projectname'] . '_default',
],
];
file_put_contents($traefikFile, Yaml::dump($traefik, 9, 2, YAML::DUMP_MULTI_LINE_LITERAL_BLOCK));
exec('docker-compose -f ' . $traefikFile . ' --project-name traefik restart');
}
}
protected function getFiles($projectRoot, $webRoot, $settingsPath) {
......@@ -160,6 +199,15 @@ class Handler {
'docker-compose.yml' => [
'dest' => $projectRoot,
],
'aliases.drushrc.php' => [
'dest' => $projectRoot . '/drush',
],
'drushrc.php' => [
'dest' => $projectRoot . '/drush',
],
'.env' => [
'dest' => $projectRoot,
],
];
}
......@@ -171,6 +219,7 @@ class Handler {
protected function getOptions() {
$extra = $this->composer->getPackage()->getExtra() + ['docker4drupal' => []];
$options = $extra['docker4drupal'] + [
'projectname' => str_replace([' ', '-', '_', '.'], '', basename(getcwd())),
'port' => 8000,
'drupal' => [
'version' => '8',
......
# Do not change manually
COMPOSE_PROJECT_NAME={{ projectname }}
<?php
$aliases['dev'] = array(
'root' => '/var/www/html/{{ webRoot }}',
'uri' => '{{ projectname }}.docker.localhost',
);
$aliases['live'] = array(
'root' => '',
'uri' => '',
'remote-host' => '',
'remote-user' => '',
);
......@@ -8,8 +8,6 @@ services:
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
ports:
- '8306:3306'
php:
image: wodby/drupal-php:{{ php.version }}-2.0.0
......@@ -21,9 +19,10 @@ services:
{% endif %}
volumes:
- ./:/var/www/html
- ./drush:/etc/drush
nginx:
image: wodby/drupal-nginx:{{ drupal.version }}-{{ nginx.version }}-2.0.0
image: wodby/drupal-nginx:{{ drupal.version }}-{{ nginx.version }}
restart: unless-stopped
depends_on:
- php
......@@ -35,7 +34,7 @@ services:
labels:
- 'traefik.backend=nginx'
- 'traefik.port=80'
- 'traefik.frontend.rule=Host:drupal.docker.localhost'
- 'traefik.frontend.rule=Host:{{ projectname }}.docker.localhost'
{% if varnish.enable %}
varnish:
......@@ -49,7 +48,7 @@ services:
labels:
- 'traefik.backend=varnish'
- 'traefik.port=6081'
- 'traefik.frontend.rule=Host:varnish.drupal.docker.localhost'
- 'traefik.frontend.rule=Host:varnish.{{ projectname }}.docker.localhost'
{% endif %}
redis:
......@@ -66,7 +65,7 @@ services:
labels:
- 'traefik.backend=pma'
- 'traefik.port=80'
- 'traefik.frontend.rule=Host:pma.drupal.docker.localhost'
- 'traefik.frontend.rule=Host:pma.{{ projectname }}.docker.localhost'
{% if solr.enable %}
solr:
......@@ -76,7 +75,7 @@ services:
labels:
- 'traefik.backend=solr'
- 'traefik.port=8983'
- 'traefik.frontend.rule=Host:solr.drupal.docker.localhost'
- 'traefik.frontend.rule=Host:solr.{{ projectname }}.docker.localhost'
{% endif %}
mailhog:
......@@ -84,7 +83,7 @@ services:
labels:
- 'traefik.backend=mailhog'
- 'traefik.port=8025'
- 'traefik.frontend.rule=Host:mailhog.drupal.docker.localhost'
- 'traefik.frontend.rule=Host:mailhog.{{ projectname }}.docker.localhost'
{% if node.enable %}
node:
......@@ -93,20 +92,10 @@ services:
labels:
- 'traefik.backend=node'
- 'traefik.port=3000'
- 'traefik.frontend.rule=Host:front.drupal.docker.localhost'
- 'traefik.frontend.rule=Host:front.{{ projectname }}.docker.localhost'
expose:
- "3000"
volumes:
- ./path/to/your/single-page-app:/app
command: sh -c 'npm install && npm run start'
{% endif %}
traefik:
image: traefik
restart: unless-stopped
command: -c /dev/null --web --docker --logLevel=INFO
ports:
- '{{ port }}:80'
- '8080:8080'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
<?php
$options['structure-tables']['common'] = array('cache', 'cache_*', 'history', 'search_*', 'sessions', 'watchdog');
$options['shell-aliases']['pull-sql'] = '!drush -y --structure-tables-key=common sql-sync @live @dev && !drush -y @dev cr && !drush -y @dev dev on';
$options['shell-aliases']['pull-files'] = '!drush -y rsync @live:%files @dev:%files --mode=rlDzq --chown=www-data:www-data --safe-links --max-size=20M && drush -y rsync @live:%private @dev:%private --mode=rlDzq --chown=www-data:www-data --safe-links --max-size=20M';
$options['shell-aliases']['pull-all'] = $options['shell-aliases']['pull-sql'] . ' && ' . $options['shell-aliases']['pull-files'];
<?php
$settings['trusted_host_patterns'] = array(
'^drupal\.docker\.localhost$',
'^{{ projectname }}\.docker\.localhost$',
);
$databases = array (
'default' => array (
......@@ -17,8 +17,3 @@ $databases = array (
),
),
);
if (empty($_SERVER['GOTLP_VER'])) {
$databases['default']['default']['host'] = '127.0.0.1';
$databases['default']['default']['port'] = '8306';
}
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