Elixir/Phoenix Cloud SDK and Deployment Tool

Download .zip Download .tar.gz View on GitHub

Nomad Tutorials

Table of Contents

Installation and Configuration

To use Nomad first do the following steps:

  1. Add nomad to your list of dependencies in mix.exs:

      def deps do
          [{:nomad, "~> 0.5.1"}]
      def deps do 
          [{:nomad, github: "sashaafm/nomad" }]
  2. Ensure nomad is started before your application:

      def application do
        [applications: [:nomad]]
  3. For every cloud provider you will need to add to your desired environment the following:

     config :nomad, 
       cloud_provider: <provider_atom>
  4. Each provider needs different configurations

    To use Amazon Web Services the following configurations are needed:

     config :nomad,
       cloud_provider: :aws

    Then pass your AWS Access Key ID and AWS Secret Access Key as System variables when launching the application like so:

     AWS_ACCESS_KEY_ID=<aws_access_key_id> AWS_SECRET_ACCESS_KEY=<secret_access_key>

    To use Google Cloud Platform the following configurations are needed:

     config :nomad,
       cloud_provider: :gcl
     config :goth, 
       json: "config/creds.json" |> Path.expand |>!

    Where 'creds.json' is the JSON file with your account credentials that you may download from your Google Cloud Console. Alternatively you may name the file whatever you want as long as you change the config accordingly.

The atom passed in the :cloud_provider key will tell Nomad what API function blocks will need to be generated.

Storage Tutorial

Nomad provides an API for interaction with cloud storage services like Amazon S3 or Google Cloud Storage. For this tutorial let's create a storage bucket, upload a file, delete it and then delete the bucket. We'll be using Google Cloud Storage so be sure to input the necessary configs first. Fire up Nomad in IEx with iex -s mix:

First let's create the storage bucket. This function takes 3 arguments - the name, the region and the storage class.

iex> Nomad.Storage.create_storage "storage_nomad_tutorial", "europe-west1", "STANDARD"

All right! Let's check if it indeed was created.

iex> Nomad.Storage.list_storages
["storage_nomad_1", "storage_nomad_2", "storage_nomad_tutorial"]

Everything seems correct. Now let's upload a file to our new storage. The Nomad.Storage.put_item also takes 3 arguments - the desired storage name, the filepath of the file we want to upload and the storage path (the directory in the storage where we want to store the file).

iex> Nomad.Storage.put_item "storage_nomad_tutorial", "", "random/tutorial/"

Success! Let's confirm it was indeed uploaded with the Nomad.Storage.list_items function.

iex> Nomad.Storage.list_items "storage_nomad_tutorial"     

There it is. Nomad also creates the directory structure if it doesn't exist. Let's delete it.

iex> Nomad.Storage.delete_item "storage_nomad_tutorial", "random/tutorial/"
iex> Nomad.Storage.list_items "storage_nomad_tutorial"

The file was deleted! Now to finish we'll delete the storage.

iex> Nomad.Storage.delete_storage "storage_nomad_tutorial"
iex> Nomad.Storage.list_storages
["storage_nomad_1", "storage_nomad_2"]

And there it is! Remember that you could have used any other supported cloud provider in the exact same way as long as you change the configurations to the appropriate ones! No code changes required!

SQL Tutorial

The SQL API in Nomad let's you manage database instances. Similarly to the Storage API you can create, delete, reboot, list database instances and more! Let's follow the same path as in the previous tutorial and create a database instance in Google Cloud SQL (be sure to configure Nomad to use Google Cloud Platform).

To create a database instance we'll use the Nomad.SQL.insert_instance function.