Git Product home page Git Product logo

consul-deployment-agent's Introduction

consul-deployment-agent

Build Status

A cross platform service that synchronises the set of applications installed on a machine with a manifest stored in a Consul key value store.

See this Overview for more information about what exactly the CDA does.

Package Format

consul-deployment-agent installs applications packaged in the AWS CodeDeploy revision format. This is a .zip file containing your code and an appspec.yml file that describes how to install the application.

Hook Scripts

consul-deployment-agent supports the following subset of the deployment lifecycle hooks:

  • BeforeInstall
  • AfterInstall
  • StartApplication
  • ValidateService

Hook Script Execution Environment

consul-deployment-agent sets the following variables in the hook script execution environment

Variable Value
APPLICATION_ID ?
DEPLOYMENT_BASE_DIR ?
DEPLOYMENT_ID Environment Manager deployment ID for this application installation
LIFECYCLE_EVENT The name of the currently executing lifecycle event. One of BeforeInstall, AfterInstall, StartApplication, ValidateService
EM_SERVICE_SLICE The slice the service is being installed to. One of blue, green, none
EM_SERVICE_NAME The name of the service being installed
EM_SERVICE_PORT The port on which the service should listen
EM_SERVICE_VERSION The version of the service being installed

Command line options

$ python agent/core.py -h
usage: core.py [-h] [-config-dir CONFIG_DIR] [-v]

optional arguments:
  -h, --help            show this help message and exit
  -config-dir CONFIG_DIR
                        Location of configuration files (e.g. config.yml and
                        config-logging.yml)
  -v, --version         show program's version number and exit

Configuration

Deployment agent supports multiple configuration files. The agent will look for configuration files in the same directory as the executable.

Filename Description Example
config-logging.yml (optional) Python logging module configuration. If not specified, logs will be sent to stdout with level set to DEBUG. [sample-config-logging.yml] (https://github.thetrainline.com/PlatformServices/consul-deployment-agent/blob/master/config/sample-config-logging.yml)
config.yml (optional) Various configuration settings. See example for supported options. [sample-config.yml] (https://github.thetrainline.com/PlatformServices/consul-deployment-agent/blob/master/config/sample-config.yml)

Development

Prerequisites (Linux and Windows)

Please make sure you have downloaded and setup the following first. You might also need to update your path environment variables for this to work.

  1. Python 2.7.X
  2. Consul agent

Setting up your PYTHONPATH

If you are checking this out for the first time you will need to make sure that you have setup your PYTHONPATH environment variable.

For example if you have checked out this project to:

C:\code\consul-deployment-agent

OR

~/code/consul-deployment-agent

Then you would need to make sure you set this exact path as a value.

For windows:

SET PYTHONPATH=C:\code\consul-deployment-agent

For linux:

export PYTHONPATH=~/code/consul-deployment-agent

Linux development

First, initialise the dependencies by running:

  sudo make init

Start Consul agent in development mode:

  consul agent -dev

To start the deployment agent:

  python agent/core.py

Running the tests:

  sudo make init-test
  make test

Windows development

First, initialise the dependencies by running:

  pip install -r requirements.txt

Start Consul agent in development mode:

  consul agent -dev -advertise=127.0.0.1

Start the deployment agent:

  python agent/core.py

Running the tests:

  pip install -r test-requirements.txt
  nosetests --verbosity=2 tests

Deployment simulation

Follow these steps to perform a deployment simulation:

  1. Upload a deployment package to tl-deployment-sandbox S3 bucket in the Sandbox account
  2. Start Consul agent as per instructions above.
  3. Start Consul deployment agent as per instructions above.
  4. Run the following script to trigger the deployment:
  ./scripts/deploy_service.py -n <service_name> -p <service_port> -v <version> -s <slice_name> -t <environment_type> -c <cluster_name> -b tl-deployment-sandbox -k <s3_object_key>

consul-deployment-agent's People

Contributors

christurvil avatar davidihunt avatar dscottie avatar duncanhall avatar filso avatar jeanml avatar lynxman avatar merlin-taylor avatar philliplambert avatar stuartio avatar tl-jakecross avatar trainb0t avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

consul-deployment-agent's Issues

Allow Sensu health checks defined as PowerShell scripts

Given that you have defined the following in healthchecks.yml:

 some-service-is-running:
    name: some-service-is-running
    local_script: is-running.ps1
    interval: 10

the check that will be generated by CDA will look like:

  "checks": {
    "order-notification-service-is-running": {
      "command": "C:\\temp\\e3c9cfb0-f92c-11e6-be86-8389fd3ece3c\\archive\\healthchecks\\sensu\\is-running.ps1",
      "interval": 10
    }
  }
}

when running this check, Sensu client will always timeout and eventually, by the look of it, stop. this is because Sensu client doesn't know how to run PowerShell scripts out of the box. looking at other system checks, e.g. consul-deployment-agent, we need to define the check as follows for it to run properly:

  "checks": {
    "order-notification-service-is-running": {
      "command": "powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -file \"C:\\temp\\e3c9cfb0-f92c-11e6-be86-8389fd3ece3c\\archive\\healthchecks\\sensu\\is-running.ps1\"",
      "interval": 10
    }
  }
}

now, because of the way we have to define checks using the yaml file specification, i.e. local_script or server_script + script_arguments, it means that Windows users cannot include the powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -file bit of the command as this won't match a filename on disk. this validation is done in CDA before registering a check.

Move Sensu local scripts to standard location at deployment time

We are getting alerts raised by Sensu shortly after deployments that are caused by how we are handling check scripts ans Sensu client's inability to pick up check definition changes quickly enough.

For example:

  1. Deployment 1 defines a check with a script called my-check.sh
  2. Deployment agent creates a Sensu check definition as such:
{
  "checks" : {
    "check-name": {
      "command": "/temp/deployments/1/healthchecks/sensu/my-check.sh"
    }
  }
}
  1. Check definition is picked up by Sensu client
  2. Later, deployment 2 redefines the same check with the same script
  3. Deployment agent overwrites the Sensu check definition with:
{
  "checks" : {
    "check-name": {
      "command": "/temp/deployments/2/healthchecks/sensu/my-check.sh"
    }
  }
}
  1. Previous directory /temp/deployments/1 is deleted by deployment agent
  2. Sensu client takes a long time to pick up this change and results in the check failing due to the fact that /temp/deployments/1/healthchecks/sensu/my-check.sh no longer exists on disk.

Potential solutions:

  1. Deployments should automate the silencing of checks until we know for sure that Sensu client has picked up the latest definitions. How we know that? I am not sure.
  2. Deployment agent can more local check scripts to the deployment location of an application, e.g. /opt/application_name/healthchecks/sensu/my-script.sh. When redeploying, we would end up overwriting the existing script to ensure that the checks currently defined still work.

Add support for disabled services

As part of trainline/environment-manager#12, Environment Manager now supports the "disabling" of services - preventing any future infrastructure from installing particular services. This is done by adding a Status value to the key/value store.

To complete this feature the Consul Deployment Agent needs to first check for the existence of this property and ignore installations if the Status value is 'Disabled'.

Extracting ZIP file with unicode content fails

Hello,

It seems unzipping certain type or archives are not supported.

Here is the stracktrace hit while trying to deploy my app:

[2017-08-03 15:41:38,237] [DEBUG] Extracting /opt/consul-deployment-agent/deployments/dummy-service/dummy-id/bundle.zip to /opt/consul-deployment-agent/deployments/dummy-service/dummy-id/archive.
[2017-08-03 15:41:40,358] [ERROR] 'ascii' codec can't decode byte 0xf0 in position 19: ordinal not in range(128)
Traceback (most recent call last):
  File "agent/deployment_stages/common.py", line 19, in run
  File "agent/deployment_stages/download_bundle_from_s3.py", line 25, in _run
  File "zipfile.py", line 1024, in extract
  File "zipfile.py", line 1065, in _extract_member
  File "posixpath.py", line 80, in join
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 19: ordinal not in range(128)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.