In order to use the template infrastructure, you need an application that meets the following requirements.
- The application's source code lives in a folder that lives in the project root folder e.g.
/app
. - The application folder needs to have a
Makefile
that has a build targetrelease-build
that takes in a Makefile variableOPTS
, and passes thoseOPTS
as options to thedocker build
command. The top level Makefile in this repo will call the application'srelease-build
make target passing in release tags to tag the docker image with. - The web application needs to listen on the port defined by the environment variable
PORT
, rather than hardcode thePORT
. This allows the infrastructure to configure the application to listen on a container port specified by the infrastructure. See The Twelve-Factor App to learn more about designing applications to be portable to different infrastructure environments using environment variables. - The web application needs to have a health check endpoint at
/health
that returns an HTTP 200 OK response when the application is healthy and ready to accept requests. - The Docker image needs to have
wget
installed. This is used in the container task defintion's healthcheck configuration in order to ping the application's/health
endpoint. If you want to use a different healthcheck command (e.g.curl
) then you'll need to modify thehealthCheck
configuration in theaws_ecs_task_definition
resource in modules/service/main.tf.
If your application needs a database, it must also:
- Have a
db-migrate
command available in the container's PATH for running migrations. If you use a migration framework like Alembic or Flyway you can create adb-migrate
script that then calls your framework's binary. - Both the application service container and the container running the
db-migrate
script will receive the following environment variables that are needed to connect to the database using IAM authentication:DB_HOST
- the hostname to connect toDB_PORT
- the port that the database is listening onDB_NAME
- the PostgreSQL database to connect toDB_USER
- the username to log in as. For the application it will beapp
, and for the database migrations it will bemigrator
DB_SCHEMA
- the name of the PostgreSQL schema to be used by the application
The infra template includes an example "hello, world" application that works with the template. The source code for this test application is at app.
A live demo of the test application is fully deployed by the https://github.com/navapbc/platform-test repo, which is used for testing the infra template. Please check that repo's README to locate a URL for seeing the live demo.
You can use the following template applications with the template infrastructure. Each of these includes a script to generate a working application that works with this infra template.