Sign inSign up

kayako/drone-nomad

By kayako

•Updated over 8 years ago

Drone plugin to facilitate Nomad deployments. Super experimental, do not point it at production.

Image
0

796

kayako/drone-nomad repository overview

⁠drone-nomad

A Drone plugin to facilitate Nomad job deployment. This is an experiment, do not use it for anything you consider important.

⁠Components

The plugin relies on a Lambda function (see ./homeless/lambda_handler.py) to proxy calls to Nomad API.

It can also make changes in the jobspec before triggering the deployment so it is possible to have a partial job specification in git repository and rest of the information in DynamoDB.

⁠Partial Job Specification

To work with partial job specifications the plugin tries to fetch the delta from DynamoDb table.

The DynamoDb table must have a primary key on (job, environment) where job is the Job ID and environment is the target environment which will receive the delta. The patch is expected to be on attribute overrides.

Overrides are written in a specific format which provides control over list of objects and can target objects based on conditions. Generally the delta is applied as recursive dictionary merge but two special formats can be used to control merge behaviour:

  • Attribute.*: Apply the patch on every element in the list
  • @cond(attr [=|!=] val): Apply patch only to the element which satisfies the condition. Only = and != operators are supported.

Given a JSON object:

{
    "Name": "user",
    "Projects": [
        {
            "Name": "drone-nomad",
            "Language": "python"
        },
        {
            "Name": "caddy",
            "Language": "go"
        }
    ]
}

Following override will add a new attribute Owner to every project:

{
    "Projects.*": {
        "Owner": "user"
    }
}

And following attribute will add the same attribute but only to the project with name drone-nomad

{
    "Projects.*": {
        "@cond(Name = drone-nomad)": {
            "Owner": "user"
        }
    }
}

⁠Revision Tracking

Some tasks may require information about their own or some other task's active revision. The plugin automatically tries to propagate the active revision information in two ways:

  1. By updating REVISION meta variable on each updated task
  2. By putting the latest revision in Consul KV under path prefix _config/services/<job_name>/<group_name>/<task_name>/active_tag for each updated task

⁠Plugin Configuration

Following environment variables can be used to configure the plugin:

NameDescriptionDefault ValueRequired
ACCOUNT_NUMBERAWS Account number to useAccount of the EC2 machineNo
DRONE_BUILD_NUMBERBuild numberNoneYes
DRONE_COMMITCommit hash to work withNoneYes
DRONE_DEPLOY_TOName of target environmentNoneYes
NOMAD_BIN_PATHFull path to Nomad binaryassets/nomadNo
PLUGIN_CI_ROLEIAM role name (not arn) to assume in ACCOUNT_NUMBERciNo
PLUGIN_DYNAMODB_TABLEName of the DynamoDB table to work withNoneYes
PLUGIN_LAMBDA_FUNCName of the lambda function to work withNoneYes
PLUGIN_REGIONName of AWS regionRegion of the EC2 machineNo
container_tagContainer tag which will be deployedFirst 8 characters of DRONE_COMMITNo
dcNomad region and datacenter in region:datacenter formatAs specified in Job specNo
only_planset to true to print plan and exitfalseNo
target_jobName of the job file to deployjobspec.nomadNo
target_taskName of the task to changeNoneYes

⁠Example

pipeline:
  deploy:
    image: kayako/drone-nomad
    ci_role: ci-server
    dynamodb_table: drone_nomad_overrides
    lambda_func: DeployFunc
    region: us-east-1
    secrets: [ account_number_production, account_number_staging, account_number_develop ]

Trigger a deployment for this pipeline using drone CLI or github deployment API with remaining parameters:

# with drone cli
drone deploy --param 'container_tag=abcd' \
             --param 'dc=nvirginia:pod_1' \
             --param 'only_plan=true' \
             --param 'target_job=project' \
             --param 'target_task=task_name' \
             project 1 staging
# with github deployment API
curl -s -X POST -H 'Accept: application/vnd.github.ant-man-preview+json' \
    -d '{
      "ref": "staging",
      "environment": "staging",
      "description": "Deploying to staging using github API",
      "payload": "{\"container_tag\":\"abcd\",\"dc\":\"nvirginia:pod_1\",\"only_plan\":true,\"target_job\":\"project\",\"target_task\":\"task_name\"}"
    }' https://api.github.com/repos/octocat/octocat/deployments

Tag summary

Content type

Image

Digest

Size

315.8 MB

Last updated

over 8 years ago

docker pull kayako/drone-nomad