localgovdrupal / localgov_microsites_project

Project template for Drupal sites built with the LocalGov Drupal Microsites distribution.
https://localgovdrupal.org/products/microsites
GNU General Public License v2.0
5 stars 4 forks source link

Default DDEV config for running tests. #52

Open finnlewis opened 5 months ago

finnlewis commented 5 months ago

Working with @opdavies on testing microsites, and experiencing issues on his NixOS operating system.

It seems that to run the tests in phpunit, we need to be able to resolve domains from inside ddev.

group-1.web group-2.web group-3.web group-4.web group-5.web

Some experimenting locally suggests that DDEV wants these to be in the /ets/hosts file of the host machine.

DDEV can attempt to add these automaticallly by defining them as FQDNs.

See https://ddev.readthedocs.io/en/latest/users/extend/additional-hostnames/

On @opdavies's machine, DDEV was not allowed to write these to /etc/hosts, as it is less permissive than Ubuntu,

opdavies commented 5 months ago

I have removed the manual group-*.web entries from my /etc/hosts file, so they are no longer there.

I have warnings as DDEV can't add them automatically on ddev start, but this doesn't prevent the tests from running.

This is the output from ddev start:

➜  localgov_microsites_project ddev start
Starting localgov-microsites...
 Container ddev-ssh-agent  Recreate
 Container ddev-ssh-agent  Recreated
 Container ddev-ssh-agent  Started
ssh-agent container is running: If you want to add authentication to the ssh-agent container, run 'ddev auth ssh' to enable your keys.
time="2024-05-10T18:01:34+02:00" level=warning msg="/home/opdavies/Code/work/localgov_microsites_project/.ddev/docker-compose.selenium-chrome.yaml: `version` is obsolete"
The hostname group-1.web is not currently resolvable, trying to add it to the hosts file
DDEV needs to run with administrative privileges.
This is normally to add unresolvable hostnames to the hosts file.
You may be required to enter your password for sudo or allow escalation.
DDEV is about to issue the command:
  sudo --preserve-env=HOME /nix/store/np9cl7ghbc7lwk9llxgsnphql956s0ql-ddev-1.23.0/bin/ddev hostname group-1.web 127.0.0.1

Failed to add hosts entry group-1.web: open /etc/hosts: read-only file system

The hostname group-2.web is not currently resolvable, trying to add it to the hosts file
DDEV needs to run with administrative privileges.
This is normally to add unresolvable hostnames to the hosts file.
You may be required to enter your password for sudo or allow escalation.
DDEV is about to issue the command:
  sudo --preserve-env=HOME /nix/store/np9cl7ghbc7lwk9llxgsnphql956s0ql-ddev-1.23.0/bin/ddev hostname group-2.web 127.0.0.1

Failed to add hosts entry group-2.web: open /etc/hosts: read-only file system

The hostname group-3.web is not currently resolvable, trying to add it to the hosts file
DDEV needs to run with administrative privileges.
This is normally to add unresolvable hostnames to the hosts file.
You may be required to enter your password for sudo or allow escalation.
DDEV is about to issue the command:
  sudo --preserve-env=HOME /nix/store/np9cl7ghbc7lwk9llxgsnphql956s0ql-ddev-1.23.0/bin/ddev hostname group-3.web 127.0.0.1

Failed to add hosts entry group-3.web: open /etc/hosts: read-only file system

The hostname group-4.web is not currently resolvable, trying to add it to the hosts file
DDEV needs to run with administrative privileges.
This is normally to add unresolvable hostnames to the hosts file.
You may be required to enter your password for sudo or allow escalation.
DDEV is about to issue the command:
  sudo --preserve-env=HOME /nix/store/np9cl7ghbc7lwk9llxgsnphql956s0ql-ddev-1.23.0/bin/ddev hostname group-4.web 127.0.0.1

Failed to add hosts entry group-4.web: open /etc/hosts: read-only file system

The hostname group-5.web is not currently resolvable, trying to add it to the hosts file
DDEV needs to run with administrative privileges.
This is normally to add unresolvable hostnames to the hosts file.
You may be required to enter your password for sudo or allow escalation.
DDEV is about to issue the command:
  sudo --preserve-env=HOME /nix/store/np9cl7ghbc7lwk9llxgsnphql956s0ql-ddev-1.23.0/bin/ddev hostname group-5.web 127.0.0.1

Failed to add hosts entry group-5.web: open /etc/hosts: read-only file system

Building project images...
.Project images built in 1s.
 Container ddev-localgov-microsites-selenium-chrome  Created
 Container ddev-localgov-microsites-db  Recreate
 Container ddev-localgov-microsites-web  Recreate
 Container ddev-localgov-microsites-db  Recreated
 Container ddev-localgov-microsites-web  Recreated
 Container ddev-localgov-microsites-db  Started
 Container ddev-localgov-microsites-selenium-chrome  Started
 Container ddev-localgov-microsites-web  Started
Waiting for web/db containers to become ready: [web db]
Starting ddev-router if necessary...
 Container ddev-router  Created
 Container ddev-router  Started
Waiting for additional project containers to become ready...
All project containers are now ready.
Successfully started localgov-microsites
Project can be reached at https://localgov-microsites.ddev.site https://group-1.web https://group-2.web https://group-3.web https://group-4.web https://group-5.web https://localgov-micro-1.ddev.site https://localgov-micro-2.ddev.site https://localgov-micro-3.ddev.site https://localgov-micro-4.ddev.site https://localgov-micro-5.ddev.site https://localgov-micro.ddev.site https://127.0.0.1:32797

The fix seems to be adding this to .ddev/config.yaml:

additional_fqdns:
  - group-1.web
  - group-2.web
  - group-3.web
  - group-4.web
  - group-5.web

After adding this, restarting DDEV and running ddev ssh, ping group-1.web works and GroupAdminAccessTest, which was previously failing locally, is passing.

2024-05-10_18-08