Skip to main content

Deploying a system of contexts

An Ampersand script can describe a system of several contexts, with the statement CONTEXT A INCLUDES B, and since Ampersand 6 the front-ends of that system, with the statement FRONTEND <name> ON <context> FOR <roles>. The command ampersand deploy turns such a script into a directory that runs the system with Docker Compose. Every service in that directory builds on the image of this framework, so this guide describes what the framework contributes, and what a deployment needs from the image it builds on. The syntax of systems of contexts is described in the Ampersand documentation.

What ampersand deploy generates​

ampersand deploy main.adl --output-dir deploy
docker compose -f deploy/compose.yaml up -d --build
deploy/install.sh

The output directory holds a compose file with one MariaDB server and three kinds of services.

  • A back-end per database. Its Dockerfile builds on the framework image, compiles the context that installs the database with ampersand proto, and builds the Angular front-end of that context with every interface of its back-end. The application answers on its own port, as a prototype of one context does.
  • A front-end per FRONTEND statement. Its Dockerfile uses the framework image to compile the interfaces of that front-end with ampersand proto --for-frontend <name> and to build them with Angular. An nginx server serves the result and passes every request under /api/ on to its back-end, so the browser sees one origin, and the session cookie of the back-end holds for the front-end.
  • A database user per back-end. The database server runs db-init/01-grants.sh when it starts with an empty volume. A back-end has every right on its own database, SELECT on the databases it reads, and SELECT, INSERT, UPDATE and DELETE on a database it writes through a rule, a classification or an interface.

install.sh installs the back-ends in the order of system.json: a database after every database it reads, because its tables are views on theirs. system.json lists the back-ends, the front-ends and the install order for a program to read.

What the framework image provides​

The generated Dockerfiles build on the image that the variable FRAMEWORK_IMAGE names, and ampersandtarski/prototype-framework:latest when it is not set. Its compiler compiles the scripts inside the image, so the image has to contain Ampersand 6.1.1 or later; this framework accepts compiler 6.1.1 and later (backend/generics/compiler-version.txt). Set FRAMEWORK_IMAGE in .env to a released version, such as ampersandtarski/prototype-framework:v3.0.0, so that a rebuild gives the same application.

A back-end reads its configuration from the environment that the compose file gives it.

VariableWhat it holds
AMPERSAND_DBHOSTthe database server, db
AMPERSAND_DBUSER, AMPERSAND_DBPASSthe database user of this back-end, named after its service
AMPERSAND_DBNAMEthe database of this back-end
AMPERSAND_CONTEXT_DBNAMESthe databases it reads, as <database in the script>=<database on the server>, separated by ;

The compiler writes a view for every table in a database that a back-end reads, with the name of that database in the script. The framework puts the name on the server in its place when it installs the database (design choice OK-27). A database thus gets another name on the server by a variable in .env, without a change to the script, which is how a new version runs next to the old one during a migration.

Front-ends​

A front-end contains the interfaces of its back-end for its roles, a role below one of them, and the interfaces without FOR. Its back-end serves every session, whichever front-end the request comes from, so its menu lists every interface of the roles that are active in the session. A front-end shows a menu item, a button under "New" or a link to another interface only when it contains that interface (design choice OK-37). A user of the desk of the clerks thus sees the interfaces of the desk, also when the role Manager is active in the session.

Testing a deployment​

test/multi-context/run-deployment.sh <scenario> in this repository builds the deployment of a scenario on a framework image, runs it, and checks every back-end and front-end; all runs every scenario. The scenario frontends has two back-ends, two front-ends and a role hierarchy. The README of test/multi-context describes the scenarios and the checks.