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

Enable Router to be configured with multiple domains #188

Merged
merged 1 commit into from Feb 24, 2021

Conversation

bilbof
Copy link
Contributor

@bilbof bilbof commented Feb 22, 2021

Problem

During the migration to ECS, Replatforming intends to run router in ECS and EC2, using the same backing database managed by Router API, hosted in EC2.

One problem with this approach is that ECS and EC2 apps are served at different domains (as below):

Router looks up the entire backend_url from its database. This currently makes it impossible to run two different Router applications which serve different domains, but use the same database.

Solution

Rather than store the backend_url for a backend in Router API's database, we'll provide backend URLs as environment variables such as

BACKEND_URL_content-store=https://content-store.gov.uk/
BACKEND_URL_search-api=https://search.gov.uk/

If an environment variable matching a backend_id is set Router will use the value of the variable instead of the FQDN backend_url stored in the DB.

This change should have no impact on the current platform since we won't set any new environment variables there.

As it is trivial to bring up new containers in ECS with different sets of environment variables, this will enable us to make router work across domains while using the same database (for workspaces).

Migration path:

  1. Push this change out
  2. Add env var for backends to router instances in ECS

Other approaches

  • Provide an env var for the host domain and add subdomains to backends in Router API (overly complex)
  • write duplicate backend records to the db (unnecessary)

Trello: https://trello.com/c/qtAZfkjg/403-work-out-whether-we-can-make-router-work-with-multiple-domains-and-a-single-database
Design doc: https://docs.google.com/document/d/147FSn4sd80iGZ1KxcJ7OYG2cW_uY-Gc7e7laLhkkMJo/edit#

@bilbof bilbof marked this pull request as ready for review February 24, 2021 10:54
@bilbof bilbof changed the title Enable Router to be configured with a domain Enable Router to be configured with multiple domains Feb 24, 2021
router.go Show resolved Hide resolved
integration_tests/route_loading_test.go Outdated Show resolved Hide resolved
@richardTowers
Copy link
Member

I think you might need to update the PR description to match the commit too :)

Problem
-------

During the migration to ECS, Replatforming intends to run router
in ECS and EC2, using the same backing database managed by
Router API, hosted in EC2.

One problem with this approach is that ECS and EC2 apps
are served at different domains (as below),
- https://calendars.integration.govuk-internal.digital/
- http://calendars.mesh.govuk-internal.digital/

Router looks up the entire backend_url from its database.
This currently makes it impossible to run two different Router
applications which serve different domains, but use the same database.

Solution
--------

Rather than store the backend_url for a backend in Router API's
database, we'll provide backend URLs as environment variables
such as

```
BACKEND_URL_content-store=https://content-store.gov.uk/
BACKEND_URL_search-api=https://search.gov.uk/
```

If an environment variable matching a backend_id is set Router will
use the value of the variable instead of the FQDN backend_url stored
in the DB.

This change should have no impact on the current platform since
we won't set any new environment variables there.

As it is trivial to bring up new containers in ECS with different
sets of environment variables, this will enable us to make router
work across domains while using the same database (for workspaces).

Migration path:

1. Push this change out
2. Add env var for backends to router instances in ECS

**Other approaches**

* Provide an env var for the host domain and add subdomains to backends
  in Router API (overly complex)
* write duplicate backend records to the db (unnecessary)

Trello: https://trello.com/c/qtAZfkjg/403-work-out-whether-we-can-make-router-work-with-multiple-domains-and-a-single-database
Design doc: https://docs.google.com/document/d/147FSn4sd80iGZ1KxcJ7OYG2cW_uY-Gc7e7laLhkkMJo/edit#
@bilbof
Copy link
Contributor Author

bilbof commented Feb 24, 2021

@richardTowers thanks for your feedback! I've improved the test and formatted.

Copy link
Member

@richardTowers richardTowers left a comment

Choose a reason for hiding this comment

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

Beautiful, thanks Bill!

@bilbof bilbof merged commit 7a4cdd6 into master Feb 24, 2021
@bilbof bilbof deleted the bilbof/router-subdomain branch February 24, 2021 16:56
bilbof added a commit to alphagov/govuk-infrastructure that referenced this pull request Apr 16, 2021
This will enable router to route requests to instances in
its own mesh. This follows on from this PR:
alphagov/router#188

I've added the other backends in as placeholders,
acquired using this RouterAPI query:

```ruby
Route.collection.aggregate([
    {"$group" => {"_id" => "$backend_id", "count" => {"$sum" => 1}}}
]).each { |res|
    puts "#{res["_id"]}: #{res["count"]}"
}
```
bilbof added a commit to alphagov/govuk-infrastructure that referenced this pull request Apr 16, 2021
This will enable router to route requests to instances in
its own mesh. This follows on from this PR:
alphagov/router#188

I've added the other backends in as placeholders,
acquired using this RouterAPI query:

```ruby
Route.collection.aggregate([
    {"$group" => {"_id" => "$backend_id", "count" => {"$sum" => 1}}}
]).each { |res|
    puts "#{res["_id"]}: #{res["count"]}"
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants