From 286cf623392c1a8e1231fc038cc933ce4563f956 Mon Sep 17 00:00:00 2001 From: enxebre Date: Tue, 12 May 2015 11:56:41 +0100 Subject: [PATCH] moving marathon out to a pluggable container --- .gitignore | 1 + CONTRIBUTING.md | 124 +++++++++++++++++++ Vagrantfile | 3 + bootstrap/aws/util.sh | 1 + bootstrap/common.sh | 4 + bootstrap/digitalocean/util.sh | 1 + bootstrap/vagrant/util.sh | 1 + inventory/aws/inventory | 3 + inventory/digitalocean/inventory | 3 + packer/scripts/ubuntu/install_marathon.sh | 11 -- packer/ubuntu-14.04_amd64-amis.json | 5 +- packer/ubuntu-14.04_amd64-droplet.json | 5 +- packer/ubuntu-14.04_amd64-google.json | 5 +- packer/ubuntu-14.04_amd64.json | 5 +- plugins.yml | 4 + roles/marathon/defaults/main.yml | 5 - roles/marathon/handlers/main.yml | 6 - roles/marathon/meta/main.yml | 128 -------------------- roles/marathon/tasks/main.yml | 22 ---- roles/marathon/templates/marathon-consul.j2 | 11 -- roles/marathon/vars/main.yml | 2 - site.yml | 11 +- 22 files changed, 153 insertions(+), 208 deletions(-) create mode 100644 CONTRIBUTING.md delete mode 100755 packer/scripts/ubuntu/install_marathon.sh create mode 100644 plugins.yml delete mode 100644 roles/marathon/defaults/main.yml delete mode 100644 roles/marathon/handlers/main.yml delete mode 100644 roles/marathon/meta/main.yml delete mode 100644 roles/marathon/tasks/main.yml delete mode 100644 roles/marathon/templates/marathon-consul.j2 delete mode 100644 roles/marathon/vars/main.yml diff --git a/.gitignore b/.gitignore index 7efe242c..b362012c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ packer/*.pem .wercker *.cache ssh.config +plugins diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..fb575fed --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,124 @@ +How to contribute +================= + +Apollo is based on an strong open-source philosophy so we would love your contributions. + +## Apollo Core + +Apollo is built on top of several opensource tecnologies: + +* [Packer](https://packer.io) for automating the build of the base images +* [Terraform](https://www.terraform.io/) for provisioning the infrastructure +* [Apache Mesos](http://mesos.apache.org/) for cluster management, scheduling and resource isolation +* [Consul](http://consul.io) for service discovery, DNS +* [Docker](http://docker.io) for application container runtimes +* [Weave](https://github.com/zettio/weave) for networking of docker containers + +We want Apollo core to be as slim as possible providing a cloud agnostic Mesos cluster with an autodiscovery system based on consul for multi-service tasks. + +This reduces the impact of core changes allowing the user customise Apollo behaviour via plugins for satisfying the requirements of a given project. + +If you find an issue belonging to any of the tools used by Apollo please, refer to the project in question. + +## Contributing to Apollo Core + +* Submit an issue describing your proposed change to the Apollo repo. + +* Fork the repo, develop and test your feature. + +* Submit a pull request. + +## Contributing to Apollo Core Plugins + +* Create a new issue describing your proposed change to the plugin repo. + +* Fork the repo, develop and test your feature. + +* Create a pull request. + +## Developing Apollo Plugins + +We want Apollo to be as pluggable as possible making contributions easier via core-agnostic plugins giving them freedom and flexibility regarding isolated testing, development and release management. + +A new Apollo plugin is purely an Ansible role stuck to some Apollo conventions and hooked into an Apollo deploy. + +* Generate your plugin scaffolder: + +At the moment we rely on [ansible-galaxy](http://docs.ansible.com/galaxy.html) for generating the plugin scaffolder, we will be providing a custom scaffolder for matching better the Apollo conventions soon. + +```yml +ansible-galaxy init marathon +``` + +* Hook up a the new plugin e.g yet another framework on top of Mesos into Apollo adding your role in the plugins.yml. For more info see [advanced-control-over-role-requirements-files](http://docs.ansible.com/galaxy.html#advanced-control-over-role-requirements-files). E.g: + +```yml +# Apollo core plugins. +- src: https://github.com/Capgemini/apollo-core-plugin-marathon.git + path: ./plugins + name: marathon +``` + +* Add the plugin into the playbook editing site.yml like: + +```yml +- hosts: mesos_masters + roles: + - { role: mesos, mesos_install_mode: "master", tags: ["mesos-master"] } + - zookeeper + - { role: '../plugins/marathon' } +``` + + +## Best practices. + +* When creating a new plugin we are keen on using the ansible role for deploying Mesos frameworks inside containers so we achieve total flexibility, reusability and portabilty across operating systems. + +```yml +# tasks for running docker marathon +- name: run marathon container + when: marathon_enabled == "Y" + docker: + name: marathon + image: "{{ marathon_image }}" + state: started + restart_policy: always + - "{{ marathon_port }}:{{ marathon_port }}" + net: host + command: "--master {{marathon_master_peers}} --zk {{marathon_zk_peers}}" + hostname: "{{ hostname }}" + volumes: + - "/var/run/docker.sock:/tmp/docker.sock" +``` + +* The variables in the role following the pattern: + +```yml +pluginname_variablename: value +``` + +will be automatically overridable via environment variables using the pattern "APOLLO_PLUGINNAME_VARNAME". Every plugin should provide the capacity for been enabled or disabled via these variables e.g: + +```yml +marathon_enabled: 'Y' +marathon_version: 'v0.8.1' +``` + +* Your plugin must ensure state is consistent when it is disabled, e.g: +```yml +- name: stop marathon container + when: marathon_enabled == "N" + docker: + name: marathon + image: "{{ marathon_image }}" + state: stopped +``` + + +## Contributing a new Apollo Plugin + +* Apollo gives official support only for core plugins. + +* If you think your plugin should be part of Apollo core plugins please create a new issue describing your feature, and explaining the motivation. + +* You can hook up your own plugins into Apollo even if they are not core plugins as explained in section above. diff --git a/Vagrantfile b/Vagrantfile index e726c559..44fade0c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -31,6 +31,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| "zookeeper_servers:children" => ["mesos_masters"], "consul_servers:children" => ["mesos_masters"], "weave_servers:children" => ["mesos_slaves", "load_balancers"], + "marathon_servers:children" => ["mesos_masters"], } # Mesos master nodes @@ -45,6 +46,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| } end mesos_zk_url = "zk://"+master_infos.map{|master| master[:ip]+":2181"}.join(",")+"/mesos" + marathon_zk_url = "zk://"+master_infos.map{|master| master[:ip]+":2181"}.join(",") zookeeper_conf = master_infos.map{|master| "server.#{master[:zookeeper_id]}"+"="+master[:ip]+":2888:3888"}.join("\n") consul_join = master_infos.map{|master| master[:ip]}.join(" ") @@ -76,6 +78,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| zookeeper_id: node[:zookeeper_id], zookeeper_conf: zookeeper_conf, mesos_zk_url: mesos_zk_url, + marathon_zk_url: marathon_zk_url, consul_join: consul_join, consul_advertise: node[:ip], mesos_local_address: node[:ip], diff --git a/bootstrap/aws/util.sh b/bootstrap/aws/util.sh index 536be73a..732e831a 100644 --- a/bootstrap/aws/util.sh +++ b/bootstrap/aws/util.sh @@ -30,6 +30,7 @@ verify_prereqs() { apollo_launch() { terraform_apply + get_ansible_requirements ansible_ssh_config ansible_playbook_run diff --git a/bootstrap/common.sh b/bootstrap/common.sh index 767c68d1..63c54bf7 100644 --- a/bootstrap/common.sh +++ b/bootstrap/common.sh @@ -13,6 +13,10 @@ get_apollo_variables() { echo ${var_list[@]} } +get_ansible_requirements() { + ansible-galaxy install -f -n -r plugins.yml +} + check_terraform_version() { local IFS='.' diff --git a/bootstrap/digitalocean/util.sh b/bootstrap/digitalocean/util.sh index 0c302802..3b7e95e6 100644 --- a/bootstrap/digitalocean/util.sh +++ b/bootstrap/digitalocean/util.sh @@ -22,6 +22,7 @@ verify_prereqs() { apollo_launch() { terraform_apply + get_ansible_requirements ansible_playbook_run open_urls } diff --git a/bootstrap/vagrant/util.sh b/bootstrap/vagrant/util.sh index 1426623b..280a1500 100644 --- a/bootstrap/vagrant/util.sh +++ b/bootstrap/vagrant/util.sh @@ -13,6 +13,7 @@ verify_prereqs() { } apollo_launch() { + get_ansible_requirements vagrant up --provision } diff --git a/inventory/aws/inventory b/inventory/aws/inventory index 92b07c4d..d14a3460 100644 --- a/inventory/aws/inventory +++ b/inventory/aws/inventory @@ -19,6 +19,9 @@ load_balancers [zookeeper_servers:children] mesos_masters +[marathon_servers:children] +mesos_masters + [consul_servers:children] mesos_masters diff --git a/inventory/digitalocean/inventory b/inventory/digitalocean/inventory index e51d2b7e..5fcec3b4 100644 --- a/inventory/digitalocean/inventory +++ b/inventory/digitalocean/inventory @@ -13,6 +13,9 @@ load_balancers [zookeeper_servers:children] mesos_masters +[marathon_servers:children] +mesos_masters + [consul_servers:children] mesos_masters diff --git a/packer/scripts/ubuntu/install_marathon.sh b/packer/scripts/ubuntu/install_marathon.sh deleted file mode 100755 index 4907da46..00000000 --- a/packer/scripts/ubuntu/install_marathon.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -eux -set -o pipefail - -sudo apt-get -y update -sudo apt-get install -y marathon=${MARATHON_VERSION} - -sudo service marathon stop || true -echo manual | sudo tee /etc/init/marathon.override >/dev/null -sudo mkdir -p /etc/marathon/conf -echo 300000 | sudo tee /etc/marathon/conf/task_launch_timeout >/dev/null diff --git a/packer/ubuntu-14.04_amd64-amis.json b/packer/ubuntu-14.04_amd64-amis.json index 075822e4..dd150e17 100644 --- a/packer/ubuntu-14.04_amd64-amis.json +++ b/packer/ubuntu-14.04_amd64-amis.json @@ -3,7 +3,6 @@ "aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}", "aws_secret_key": "{{env `AWS_ACCESS_KEY`}}", "mesos_version": "0.22.0-1.0.ubuntu1404", - "marathon_version": "0.8.1-1.0.171.ubuntu1404", "consul_version": "0.5.0", "weave_version": "v0.10.0", "version": "0.22.0" @@ -33,15 +32,13 @@ "environment_vars": [ "CONSUL_VERSION={{user `consul_version`}}", "WEAVE_VERSION={{user `weave_version`}}", - "MESOS_VERSION={{user `mesos_version`}}", - "MARATHON_VERSION={{user `marathon_version`}}" + "MESOS_VERSION={{user `mesos_version`}}" ], "scripts": [ "scripts/ubuntu/base.sh", "scripts/common/sshd.sh", "scripts/ubuntu/install_docker.sh", "scripts/ubuntu/install_mesos.sh", - "scripts/ubuntu/install_marathon.sh", "scripts/common/install_consul.sh", "scripts/ubuntu/install_dnsmasq.sh", "scripts/common/install_weave.sh" diff --git a/packer/ubuntu-14.04_amd64-droplet.json b/packer/ubuntu-14.04_amd64-droplet.json index fd3a624e..a74c1db9 100644 --- a/packer/ubuntu-14.04_amd64-droplet.json +++ b/packer/ubuntu-14.04_amd64-droplet.json @@ -4,7 +4,6 @@ "digitalocean_region": "lon1", "digitalocean_size": "512MB", "mesos_version": "0.22.0-1.0.ubuntu1404", - "marathon_version": "0.8.1-1.0.171.ubuntu1404", "consul_version": "0.5.0", "weave_version": "v0.10.0", "version": "0.22.0" @@ -29,15 +28,13 @@ "environment_vars": [ "CONSUL_VERSION={{user `consul_version`}}", "WEAVE_VERSION={{user `weave_version`}}", - "MESOS_VERSION={{user `mesos_version`}}", - "MARATHON_VERSION={{user `marathon_version`}}" + "MESOS_VERSION={{user `mesos_version`}}" ], "scripts": [ "scripts/ubuntu/base.sh", "scripts/common/sshd.sh", "scripts/ubuntu/install_docker.sh", "scripts/ubuntu/install_mesos.sh", - "scripts/ubuntu/install_marathon.sh", "scripts/common/install_consul.sh", "scripts/ubuntu/install_dnsmasq.sh", "scripts/common/install_weave.sh" diff --git a/packer/ubuntu-14.04_amd64-google.json b/packer/ubuntu-14.04_amd64-google.json index 64393673..ab3862b6 100644 --- a/packer/ubuntu-14.04_amd64-google.json +++ b/packer/ubuntu-14.04_amd64-google.json @@ -3,7 +3,6 @@ "account_file": "{{env `GCS_ACCOUNT_FILE`}}", "project_id": "{{env `GCS_PROJECT_ID`}}", "mesos_version": "0.22.0-1.0.ubuntu1404", - "marathon_version": "0.8.1-1.0.171.ubuntu1404", "consul_version": "0.5.0", "weave_version": "v0.10.0" }, @@ -29,15 +28,13 @@ "environment_vars": [ "CONSUL_VERSION={{user `consul_version`}}", "WEAVE_VERSION={{user `weave_version`}}", - "MESOS_VERSION={{user `mesos_version`}}", - "MARATHON_VERSION={{user `marathon_version`}}" + "MESOS_VERSION={{user `mesos_version`}}" ], "scripts": [ "scripts/ubuntu/base.sh", "scripts/common/sshd.sh", "scripts/ubuntu/install_docker.sh", "scripts/ubuntu/install_mesos.sh", - "scripts/ubuntu/install_marathon.sh", "scripts/common/install_consul.sh", "scripts/ubuntu/install_dnsmasq.sh", "scripts/common/install_weave.sh" diff --git a/packer/ubuntu-14.04_amd64.json b/packer/ubuntu-14.04_amd64.json index 2c86e3b0..c011e09f 100644 --- a/packer/ubuntu-14.04_amd64.json +++ b/packer/ubuntu-14.04_amd64.json @@ -5,7 +5,6 @@ "hostname": "ubuntu", "version": "0.22.0", "mesos_version": "0.22.0-1.0.ubuntu1404", - "marathon_version": "0.8.1-1.0.171.ubuntu1404", "consul_version": "0.5.0", "weave_version": "v0.10.0", "access_token": "{{env `ATLAS_TOKEN`}}" @@ -55,8 +54,7 @@ "environment_vars": [ "CONSUL_VERSION={{user `consul_version`}}", "WEAVE_VERSION={{user `weave_version`}}", - "MESOS_VERSION={{user `mesos_version`}}", - "MARATHON_VERSION={{user `marathon_version`}}" + "MESOS_VERSION={{user `mesos_version`}}" ], "scripts": [ "scripts/ubuntu/base.sh", @@ -67,7 +65,6 @@ "scripts/common/sshd.sh", "scripts/ubuntu/install_docker.sh", "scripts/ubuntu/install_mesos.sh", - "scripts/ubuntu/install_marathon.sh", "scripts/common/install_consul.sh", "scripts/ubuntu/install_dnsmasq.sh", "scripts/common/install_weave.sh" diff --git a/plugins.yml b/plugins.yml new file mode 100644 index 00000000..4d869d5b --- /dev/null +++ b/plugins.yml @@ -0,0 +1,4 @@ +# Apollo core plugins. +- src: https://github.com/Capgemini/apollo-core-plugin-marathon.git + path: ./plugins + name: marathon diff --git a/roles/marathon/defaults/main.yml b/roles/marathon/defaults/main.yml deleted file mode 100644 index 002953d6..00000000 --- a/roles/marathon/defaults/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -# defaults file for marathon -marathon_port: 8080 -consul_dir: /etc/consul.d -marathon_local_address: "{{ansible_eth0.ipv4.address}}" diff --git a/roles/marathon/handlers/main.yml b/roles/marathon/handlers/main.yml deleted file mode 100644 index accda582..00000000 --- a/roles/marathon/handlers/main.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -# handlers file for marathon -# Restart service marathon, in all cases -- name: Restart marathon - service: name=marathon state=restarted - sudo: yes diff --git a/roles/marathon/meta/main.yml b/roles/marathon/meta/main.yml deleted file mode 100644 index 78598b03..00000000 --- a/roles/marathon/meta/main.yml +++ /dev/null @@ -1,128 +0,0 @@ ---- -galaxy_info: - author: Graham Taylor - description: - company: Capgemini - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: license (MIT) - min_ansible_version: 1.2 - # - # Below are all platforms currently available. Just uncomment - # the ones that apply to your role. If you don't see your - # platform on this list, let us know and we'll get it added! - # - platforms: - #- name: EL - # versions: - # - all - # - 5 - # - 6 - # - 7 - #- name: GenericUNIX - # versions: - # - all - # - any - #- name: Fedora - # versions: - # - all - # - 16 - # - 17 - # - 18 - # - 19 - # - 20 - #- name: SmartOS - # versions: - # - all - # - any - #- name: opensuse - # versions: - # - all - # - 12.1 - # - 12.2 - # - 12.3 - # - 13.1 - # - 13.2 - #- name: Amazon - # versions: - # - all - # - 2013.03 - # - 2013.09 - #- name: GenericBSD - # versions: - # - all - # - any - #- name: FreeBSD - # versions: - # - all - # - 8.0 - # - 8.1 - # - 8.2 - # - 8.3 - # - 8.4 - # - 9.0 - # - 9.1 - # - 9.1 - # - 9.2 - - name: Ubuntu - versions: - # - all - # - lucid - # - maverick - # - natty - # - oneiric - # - precise - # - quantal - # - raring - # - saucy - - trusty - #- name: SLES - # versions: - # - all - # - 10SP3 - # - 10SP4 - # - 11 - # - 11SP1 - # - 11SP2 - # - 11SP3 - #- name: GenericLinux - # versions: - # - all - # - any - #- name: Debian - # versions: - # - all - # - etch - # - lenny - # - squeeze - # - wheezy - # - # Below are all categories currently available. Just as with - # the platforms above, uncomment those that apply to your role. - # - categories: - - cloud - #- cloud:ec2 - #- cloud:gce - #- cloud:rax - #- clustering - #- database - #- database:nosql - #- database:sql - #- development - #- monitoring - #- networking - #- packaging - - system - #- web -dependencies: - - role: consul - # List your role dependencies here, one per line. Only - # dependencies available via galaxy should be listed here. - # Be sure to remove the '[]' above if you add dependencies - # to this list. diff --git a/roles/marathon/tasks/main.yml b/roles/marathon/tasks/main.yml deleted file mode 100644 index 04d791a1..00000000 --- a/roles/marathon/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -# tasks file for marathon -- name: Set Marathon hostname - copy: - content: "{{marathon_local_address}}" - dest: /etc/marathon/conf/hostname - mode: 0644 - sudo: yes - -- name: remove marathon override - file: path=/etc/init/marathon.override state=absent - -- name: ensure marathon is running (and enable it at boot) - service: name=marathon state=started enabled=yes - -- name: Set Marathon consul service definition - sudo: yes - template: - src: marathon-consul.j2 - dest: "{{ consul_dir }}/marathon.json" - notify: - - Restart consul diff --git a/roles/marathon/templates/marathon-consul.j2 b/roles/marathon/templates/marathon-consul.j2 deleted file mode 100644 index 6ca3ec6d..00000000 --- a/roles/marathon/templates/marathon-consul.j2 +++ /dev/null @@ -1,11 +0,0 @@ -{ - "service": { - "name": "marathon", - "tags": [ "marathon" ], - "port": {{ marathon_port }}, - "check": { - "script": "curl --silent --show-error --fail --dump-header /dev/stderr --retry 2 http://{{ marathon_local_address }}:{{ marathon_port }}/ping", - "interval": "10s" - } - } -} diff --git a/roles/marathon/vars/main.yml b/roles/marathon/vars/main.yml deleted file mode 100644 index 81800958..00000000 --- a/roles/marathon/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for marathon diff --git a/site.yml b/site.yml index 6e653ccf..21281a33 100644 --- a/site.yml +++ b/site.yml @@ -3,25 +3,22 @@ roles: - dnsmasq - consul + - docker + - weave + - registrator - hosts: mesos_masters roles: - { role: mesos, mesos_install_mode: "master", tags: ["mesos-master"] } - zookeeper - - marathon + - { role: '../plugins/marathon' } vars: consul_is_server: true - hosts: mesos_slaves roles: - { role: mesos, mesos_install_mode: "slave", tags: ["mesos-slave"] } - - docker - - weave - - registrator - hosts: load_balancers roles: - - docker - - weave - - registrator - haproxy