Skip to content

Review Apps with Nomad

This example demonstrates how to use the Review Apps GitLab feature with HashiCorp Nomad. Scripts are executed in container images in GitLab CI/CD.

GitLab CI/CD is Used to:

  1. Build an image with app's build environment and push it to a container registry.
  2. Build an app (MkDocs static site) in its prepared environment.
  3. Build an image that serves the app, and push it to a container registry.
  4. Deploy an app into Nomad.

This demo is not connected to a real Nomad cluster, so you can only view job logs and the mainstream version of the app in GitLab Pages. Feel free to fork it and use with your cluster.

You'll Need:

  1. A Nomad cluster accessible for project's GitLab CI/CD Runners.
  2. A domain name with a wildcard DNS record for your review apps: we use the <branch>.<project>.example.com URLs, so you need to have a *.example.com domain pointed to your load balancer(s).
  3. Some load balancing infrastructure. We suggest the following setup:
    1. A Consul cluster for service discovery and health checks.
    2. A fabio service job on every Nomad client (fabio is connected to Consul).
    3. A wildcard DNS record points to all Nomad clients (several A records), so that you can use load balancer on every Nomad client.
    4. fabio listens to Consul Catalog events, and automatically adds new services to the routing table. All we need to have a service available on its desired domain name is to add a urlprefix tag to nomad job spec.
  4. A container registry. This demo uses the GitLab container registry, but you can use any other registry accessible for GitLab Runners.
  5. A Scheduled Pipeline to update app's build environment image. There's only one job reacting to schedules in this demo, so you can create a schedule without variables.

    WARNING
    Push-triggered pipelines will fail with the manifest unknown error, unless you run a Scheduled Pipeline for the first time.

How to Use an External Container Registry

  1. In Settings > CI/CD > Variables:
    1. Set the DOCKER_AUTH_CONFIG variable that provides registry credentials. Note that we assume it's a File variable.
  2. In .gitlab-ci.yml:
    1. Replace the .gitlab-registry-login anchor with an .external-registry-login appropriate to your CONTAINER_BUILDER.
    2. Replace the $CI_REGISTRY_IMAGE variable to your registry address in APP_BUILDER_IMAGE and APP_SERVER_IMAGE variables.