This folder demonstrates an example setup of ORM with some rules and backend services. It uses docker-compose
to launch the ORM components (HAProxy and Varnish) along with some mock backend services to demonstrate some simple ORM rule capabilities.
In this example we use a scenario where we have a web site under the domain orm.localdomain
and subdomain subdomain.orm.localdomain
. We have three fictional teams (team-a, team-b and team-c) which all write and run their own backend services. team-a is responsible for all services that run under orm.localdomain
. team-b and team-c is sharing the domain subdomain.orm.localdomain
.
- All requests to http://orm.localdomain should go to team-a:s service team-a-service, except requests with paths that begins with
/secret/
- All requests with url:s that begins with http://orm.localdomain/secret/ should go to team-a:s service team-a-secret-service.
- All requests to the legacy site http://orm-legacy.localdomain should be redirected to the site http://orm.localdomain
- All requests to http://subdomain.orm.localdomain should by default go to team-b:s service team-b-service.
- All requests to url:s that begins with http://subdomain.orm.localdomain/team-c/ should go to team-c:s service team-c-service (and not to team-b-service above).
Requirement 1 is realized in rules/team-a/service.yml by the rule with description Team A service backend
. Rule Team A redirect from orm-legacy to orm
in the same file solves 2. Requirement 3 is defined in another file rules/team-a/secret-service.yml with a single rule Team A secret service backend
.
Finally team-b and team-c have their rules for 4 and 5 in their respective files rules/team-b/service.yml and rules/team-c/service.yml.
When running ORM, all rule files will get parsed, analyzed and finally generate output in the form of HAProxy and Varnish config. It's not necessary to understand the output (unless you want to debug or develop ORM) but if you're curious, check the config/
folder.
Run docker run --name orm --rm -v ${PWD}:${PWD} -w ${PWD} -it svtwebcoreinfra/orm -G globals.yml -r 'rules/**/*.yml' -o config/
to generate config. Run ORM with -h
for available options and what they mean.
Run docker-compose up -d
to spin up the ORM components and backend services. Look into docker-compose.yml
. See that the ORM components haproxy and varnish mounts the config which was generated to config/
. Also note that each team service mounts a different html page (which will enable us to verify and debug if the rules work.)
The HAProxy status page is available at http://localhost:8888. orm_external
and orm_loopback
are internal ORM backends. At the bottom you can see all the teams' service backends team_a_secret_service_backend
, team_a_service_backend
, team_b_service_backend
and team_c_service_backend
.
When everything is up and running, you can verify that the rules are working by using curl (or another http tool/browser that supports setting the Host
header). ORM is listening for HTTP on port 8080.
Verify requirements:
curl -v -H 'Host: orm.localdomain' localhost:8080
should get a response from Team A.curl -v -H 'Host: orm.localdomain' localhost:8080/secret/
should get a response from Team A:s secret service.curl -v -H 'Host: orm-legacy.localdomain' localhost:8080
should give a redirect toorm.localdomain
.curl -v -H 'Host: subdomain.orm.localdomain' localhost:8080
should get a response from Team B.curl -v -H 'Host: subdomain.orm.localdomain' localhost:8080/team-c/
should get a response from Team C.
You can try different paths and domains (Host
headers) to see what ORM responds with.
Try to add, remove and change rules. ORM will let you now if there is any syntax error or if there are any collisions between rules. After any change, do not forget to also run docker run --name orm --rm -v ${PWD}:${PWD} -w ${PWD} -it svtwebcoreinfra/orm -G globals.yml -r 'rules/**/*.yml' -o config/
to generate new config and docker-compose restart haproxy varnish
to reload the new config.
orm -G globals.yml -r 'rules/**/*.yml' -o config/
docker-compose up -d
curl -v -H 'Host: orm.localdomain' localhost:8080
This folder contains:
rules/: Contains the ORM rules for all teams. See syntax reference here.
globals.yml: Contains configuration for the ORM components as well as global ORM settings. See syntax reference here.
docker-compose.yml: Defining all containers, for ORM components as well as the teams' services.
varnish/: Contains a Dockerfile to build a Varnish Docker image, used as an ORM component in docker-compose.yml
. (For HAProxy, the standard image is used).
nginx-content/`: Contains nginx config and static html pages used by the teams' services.