Deploy to Nomad
Deploy Docker images to a Nomad cluster with Codefresh
Even though Codefresh has great support for Kubernetes and Helm deployments, there is no lock-in on using just Kubernetes. Codefresh can deploy on any infrastructure.
Nomad is an alternative scheduling platform from Hashicorp. It supports docker containers (like Kubernetes), but you can also use Nomad to schedule VMs, Java apps, Go apps or any other standalone executable.
There are several public Docker Images with Nomad, so it is very easy to use Codefresh pipelines to deploy to a Nomad cluster.
In this example, we will use the image at https://hub.docker.com/r/djenriquez/nomad.
The example Nomad project
You can see the example project at https://github.com/codefresh-contrib/nomad-sample-app. The repository contains a simple job specification that deploys a docker container on nomad cluster.
Here is the whole job file:
You need to create a Codefresh account and have a Nomad cluster running. You need to decide on how Codefresh will communicate
with the nomad cluster. In this simple example we just use the
NOMAD_ADDR variable to point the nomad client to our cluster. In a production environment you should use proper ACL and certificate variables as well.
In this example the Nomad cluster is already setup on a VM at Google cloud.
You also need to create a token for the Docker registry so that Nomad can pull your private images on the cluster.
Create a CI/CD pipeline for Nomad deployments
Here is the whole pipeline:
This pipeline does the following:
- Clones the source code through a Git clone step.
- Creates a Docker image for a simple Go application through a build step. The image is automatically pushed to the default Docker registry.
- Replaces all variables in the job spec by running
envsubst. These include:
- The Registry token so that Nomad can access the default Docker registry
- The docker image name and tag to be deployed
- Runs the job to deploy the image to Nomad through a freestyle step.
Run the pipeline and see your deployment succeed.
Here are the environment variables defined for this pipeline.
NOMAD_ADDR variable is holding the URL of the cluster. The
CFCR_LOGIN_TOKEN variable holds authentication for the Codefresh Docker registry.
Verify the deployment
Nomad also comes with its own UI that can show you the result of a deployment.
You can also use Terraform in Codefresh pipelines.