Giter Site home page Giter Site logo

marathon_deploy's Introduction

Build Status

Marathon Deploy

A Marathon command-line deployment tool in Ruby. Takes a json or yaml file describing an application and pushes it to the Marathon REST API

Feature Summary

  • Deploy a single application descriptor to multiple marathon endpoints
  • Checks for existing deployment of application before starting new deployment
  • Polls for Healthcheck results after deployment
  • Proper exit codes for easier integration with Jenkins automated pipelines
  • Deploy file macro substitution using values from locally set environment (ENV) variables (macros have the format %%MACRO_NAME%% and must match the environment variable name)
  • Inject environment variables into a deployment when local environment variables with the format: MARATHON_DEPLOY_FOO=BAR are set (MARATHON_DEPLOY prefix will be removed in final json payload).
  • PRODUCTION / PREPRODUCTION modes (specified with --environment)
  • Rolling upgrade deployment strategy (Marathon default)

Roadmap Features

  • Record actions and json payload to a database (for rollback, history, auditing)
  • Deploy a deployment descriptor containing multiple applications
  • Specify deployment strategy (using minimumHealthCapacity) as an option. See Marathon Deployment document

Installation

Ensure Ruby (1.9+) and ruby-dev and gem are installed on you system, then run:

$ gem install marathon_deploy

Executables from this gem:

$ marathon_deploy  (client program executable, automatically added to $PATH)
$ json2yaml (convenience utility for converting json to yaml)
$ expand_macros (expands all macros in the form %%MACRO%% with value of ENV[MACRO])

Usage

Help

>marathon_deploy -h
Usage: bin/marathon_deploy [options]
    -u, --url MARATHON_URL(S)        Default: ["http://localhost:8080"]
    -l, --logfile LOGFILE            Default: STDOUT
    -d, --debug                      Run in debug mode
    -v, --version                    Version info
    -f, --force                      Force deployment when sending same deploy JSON to Marathon
    -n, --noop                       No action. Just display what would be performed.
    -e, --environment ENVIRONMENT    Default: PREPRODUC

Overriding configuration based on environment

By using the -e <ENVIRONMENT> switch you can specify a custom environment which can overwrite the settings in the deploy file. For example, setting -e STAGING and creating a STAGING.yml or STAGING.json file in the same folder with the deploy file will trigger the overwriting process.

See examples/run-with-env-overrides.sh for a demo of this feature. Here we are specifying different memory settings and appending a custom health-check based on environment.

Example Deployfile

By default, a file called 'deploy.yml' is searched for in the current directory where deploy.rb is run from. An alternative file name can be provided with the -f parameter.

The file format must conform to the Marathon API specification

Minimalistic example (using Docker container):

id: python-example-stable
cmd: echo python stable `hostname` > index.html; python3 -m http.server 8080
mem: 16
cpus: 0.1
instances: 5
container:
  type: DOCKER
  docker:
    image: ubuntu:14.04
    network: BRIDGE
    portMappings:
    - containerPort: 8080
      hostPort: 0
      protocol: tcp
env:
  SERVICE_TAGS: python,webapp,http,weight=100
  SERVICE_NAME: python
healthChecks:
- portIndex: 0
  protocol: TCP
  gracePeriodSeconds: 30
  intervalSeconds: 10
  timeoutSeconds: 30
  maxConsecutiveFailures: 3
- path: "/"
  portIndex: 0
  protocol: HTTP
  gracePeriodSeconds: 30
  intervalSeconds: 10
  timeoutSeconds: 30
  maxConsecutiveFailures: 3

JSON to YAML file conversion

As a convenience, the provided json2yaml.rb script can convert a JSON file to the arguably more human-readable YAML format:

$json2yaml marathon-webapp.json  > marathon-webapp.yaml

Parsing a file with macro expansion from ENV variables

A helper script which takes a file and replaces all macros having the format %%MACRO%% with the values from ENV variables. Script will fail if there are no ENV values for macro names contained in the template.

$expand_macros -h
Usage: bin/expand_macros.rb [options]
    -o, --outfile OUTFILE            Default: STDOUT
    -l, --logfile LOGFILE            Default: STDOUT
    -d, --debug                      Run in debug mode
    -v, --version                    Version info
    -f, --force                      force overwrite of existing OUTFILE
    -t, --template TEMPLATE_FILE     Input file. Default: dockerfile.tpl
    -h, --help                       Show this message

Contributing

  1. Fork it ( https://github.com/[my-github-username]/marathon_deploy/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

marathon_deploy's People

Contributors

j1n6 avatar sgran avatar sielaq avatar thyrlian avatar vgrigoruk avatar

Watchers

 avatar

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.