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
Conversation
This file contains 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
f7adb1d
to
27f2908
Compare
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#
27f2908
to
9e1c0d5
Compare
@richardTowers thanks for your feedback! I've improved the test and formatted. |
richardTowers
approved these changes
Feb 24, 2021
There was a problem hiding this 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
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
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#