Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put dnsmasq config files in /opt/homebrew/etc #564

Merged
merged 1 commit into from
Jan 31, 2022
Merged

Conversation

KludgeKML
Copy link
Contributor

Why

On M1 machines, even when you can get an app running in govuk-docker, you can't currently access it via the .dev.gov.uk hostname in your browser.

What's the problem

We're using dnsmasq to resolve those hostnames into 127.0.0.1, which the nginx-docker proxy then picks up and routes to the backing app. The existing bin/setup script puts the configuration files for dnsmasq in /usr/local/etc. But on M1 machines /usr/local/etc doesn't exist, and homebrew dnsmasq looks in /opt/homebrew/etc, where the dnsmasq config files and directories already exist. This change updates those paths in bin/setup.

Any other notes

This problem wasn't caught by Doctor, which only checks:

  • is dnsmasq running
  • does the first config file (/etc/resolver/dev.gov.uk) exist?
    ..in this case, both of those were true, but without the other two config files nothing would work. We could perhaps update doctor to make an actual dns request (via dig maybe?) to check that the configuration is working as expected.

@KludgeKML KludgeKML added the M1 PRs for solving M1 Development issues label Jan 26, 2022
@KludgeKML KludgeKML changed the base branch from main to m1-investigation January 26, 2022 16:22
Copy link
Contributor

@Tetrino Tetrino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great for now - hopefully we can do some architecture sniffing in the future but let's get this running first.

bin/setup Outdated
@@ -12,12 +12,11 @@ echo -e "You may need to enter your root password...\n"
sudo mkdir -p /etc/resolver
echo -e "nameserver 127.0.0.1\nport 53" | sudo tee /etc/resolver/dev.gov.uk >/dev/null

echo -e "✅ Configuring dnsmasq [/usr/local/etc/dnsmasq.conf]\n"
echo "conf-dir=/usr/local/etc/dnsmasq.d,*.conf" > /usr/local/etc/dnsmasq.conf
echo -e "✅ Configuring dnsmasq [/opt/homebrew/etc/dnsmasq.conf]\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible to make this cross-architecture compatible by using brew --prefix instead of hardcoding the path:

Suggested change
echo -e "✅ Configuring dnsmasq [/opt/homebrew/etc/dnsmasq.conf]\n"
echo -e "✅ Configuring dnsmasq [$(brew --prefix)/etc/dnsmasq.conf]\n"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, interesting. I'd assumed we'd do a bit of cross-architecture sniffing when we merged into full main, but this is very low-cost, worth doing now. I'll update and confirm it works on this machine, if someone else can then try it on an intel machine.

@kevindew
Copy link
Member

kevindew commented Jan 26, 2022

Thanks @KludgeKML

I wonder if we can make this support both M1 and Intel, so it can be merged in earlier?

E.g. in my pseudo bash

if intel homebrew directory exists 
  echo -e "✅ Configuring dnsmasq [/usr/local/etc/dnsmasq.conf]\n"
  echo "conf-dir=/usr/local/etc/dnsmasq.d,*.conf" > /usr/local/etc/dnsmasq.conf
  
  echo -e "✅ Configuring dnsmasq [/usr/local/etc/dnsmasq.d/development.conf]\n"
  mkdir -p /usr/local/etc/dnsmasq.d
  echo "address=/dev.gov.uk/127.0.0.1" > /usr/local/etc/dnsmasq.d/development.conf
else 
  echo -e "✅ Configuring dnsmasq [/opt/homebrew/etc/dnsmasq.conf]\n"
  echo "conf-dir=/opt/homebrew/etc/dnsmasq.d,*.conf" >> /opt/homebrew/etc/dnsmasq.conf
  
  echo -e "✅ Configuring dnsmasq [/opt/homebrew/etc/dnsmasq.d/development.conf]\n"
  echo "address=/dev.gov.uk/127.0.0.1" > /opt/homebrew/etc/dnsmasq.d/development.conf
fi

Edit: ooh @ollietreend's suggestion is better

@KludgeKML
Copy link
Contributor Author

@ollietreend 's change made, confirmed works on M1 machine.

@kevindew
Copy link
Member

Great @KludgeKML could we branch this to go into the main branch instead of the M1 one? I imagine we only want to use that branch for anything that isn't interoperable.

bin/setup Show resolved Hide resolved
@KludgeKML
Copy link
Contributor Author

@kevindew I can either change this PR to main, or I can close it and reopen on main (maybe with the 3 commits squished into one?). What's the usual preferred option?

@kevindew
Copy link
Member

@KludgeKML I'd change the base of this PR to main (can be done by hitting edit in the top right corner if you're not already aware).

@KludgeKML KludgeKML changed the base branch from m1-investigation to main January 27, 2022 13:43
@KludgeKML
Copy link
Contributor Author

Ug, rebase squash has interacted oddly with this PR. Going to recreate this branch from the head of main with just my changes and update the PR.

 bin/doctor

Put dnsmasq config files in correct location (brew --install) rather
than hardcoding to /usr/local/etc, which doesn't work on M1 machines.

Add checks to bin/doctor to see if the dnsmasq additional config
files exist, and if the app.dev.gov.uk host can be resolved to
127.0.0.1 using the system dig command.
Copy link
Contributor

@ollietreend ollietreend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works on my Intel-based Mac 👍🏻

@KludgeKML KludgeKML merged commit ff55aa1 into main Jan 31, 2022
@KludgeKML KludgeKML deleted the m1-fix-dnsmasq branch January 31, 2022 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M1 PRs for solving M1 Development issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants