diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6bc621 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +docker-compose.external_links.yaml diff --git a/commands/host/propagate-external-links b/commands/host/propagate-external-links new file mode 100755 index 0000000..6c8bc05 --- /dev/null +++ b/commands/host/propagate-external-links @@ -0,0 +1,37 @@ +#!/usr/bin/python + +## Description: Generates .ddev/docker-compose.external_links.yaml and adds external_links to all services to enable access to domains in the web container. +## Usage: propagate-external-links +## Example: "ddev propagate-external-links" + +import subprocess +import yaml + +# Get processed docker compose config. +command = ("ddev", "debug", "compose-config") +result = subprocess.run(command, capture_output=True, text=True) +output = result.stdout.strip() +compose = yaml.safe_load(output) + +# Get list of services, but 'web'. +services_list = compose['services'].keys() - ['web'] + +# Get 'web' service external links and transform to link to 'web' instead of 'ddev-router'. +# We prefer 'web' because it works equally and it is a self contained solution (the router +# may not be available). +web_external_links = compose['services']['web']['external_links'] +web_external_links_to_web = [x.replace('ddev-router:', 'web:') for x in web_external_links] + +# Generate a compose file that declares the above external_links for all services. +# We need to filter the list to avoid duplicate items. +data = dict() +data['services'] = dict() +for service in services_list: + service_current_external_links = compose['services'][service].get('external_links', []) + service_extra_external_links = [x for x in web_external_links_to_web if x not in service_current_external_links] + + data['services'][service] = dict() + data['services'][service]['external_links'] = service_extra_external_links + +with open('.ddev/docker-compose.external_links.yaml', 'w') as file: + yaml.dump(data, file) diff --git a/config.aljibe.yaml b/config.aljibe.yaml index 0a411f6..cc2c09c 100644 --- a/config.aljibe.yaml +++ b/config.aljibe.yaml @@ -1,4 +1,10 @@ #ddev-generated -# Custom config to alter composer executable in case Drupal is defining a custom version. -# See https://github.com/ddev/ddev/issues/6602 for more details. -hooks: \ No newline at end of file +fail_on_hook_fail: True +hooks: + pre-start: + - exec-host: | + if pip3 show PyYAML &>/dev/null; then + ddev propagate-external-links + else + echo "[ERROR] Aljibe requires python with yaml extension." + fi