Enable Router to be configured with multiple domains - #188
Merged
Conversation
bilbof
force-pushed
the
bilbof/router-subdomain
branch
from
February 24, 2021 10:41
f7adb1d to
27f2908
Compare
bilbof
marked this pull request as ready for review
February 24, 2021 10:54
|
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
force-pushed
the
bilbof/router-subdomain
branch
from
February 24, 2021 11:19
27f2908 to
9e1c0d5
Compare
Contributor
Author
|
@richardTowers thanks for your feedback! I've improved the test and formatted. |
bilbof
pushed 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
pushed 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"]}" } ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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:
Other approaches
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#