From: Wayne Schneider Date: Thu, 11 Aug 2016 22:03:55 +0000 (-0500) Subject: Towards Docker deployment. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=93e24f7f2f88b8a2c7c482cf9463f8a4321211b5;p=lui-solr.git Towards Docker deployment. --- diff --git a/docker/Vagrantfile b/docker/Vagrantfile new file mode 100644 index 0000000..c2d4e33 --- /dev/null +++ b/docker/Vagrantfile @@ -0,0 +1,29 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : +# Build a VM to serve as a Docker server + +Vagrant.configure(2) do |config| + # Target platform is Debian/jessie + config.vm.box = "debian/contrib-jessie64" + + # Give me a little headroom here + config.vm.provider "virtualbox" do |vb| + vb.memory = 4096 + vb.cpus = 2 + end + + # Disable the default share + # Share the project folder on /vagrant + config.vm.synced_folder ".", "/vagrant", disabled: true + config.vm.synced_folder "..", "/vagrant" + + # Set up port forwarding + config.vm.network "forwarded_port", guest: 8983, host: 8983 + + config.vm.provision "ansible" do |ansible| + ansible.playbook = "docker-deploy.yml" + ansible.groups = { + "dev" => ["default"], + } + end +end diff --git a/docker/docker-deploy.yml b/docker/docker-deploy.yml new file mode 100644 index 0000000..628095a --- /dev/null +++ b/docker/docker-deploy.yml @@ -0,0 +1,98 @@ +--- +# deploy a Docker server with 1 Zookeeper, 3 Solr, 1 HAProxy +- hosts: all + + tasks: + - name: Install prereqs from apt + become: yes + apt: name={{ item }} + with_items: + - apt-transport-https + - ca-certificates + - python-virtualenv + - python-pip + + - name: Install prereqs from pip + become: yes + pip: name={{ item }} + with_items: + - docker-py + + - name: Install apt key for Docker + become: yes + apt_key: id=58118E89F3A912897C070ADBF76221572C52609D keyserver=hkp://p80.pool.sks-keyservers.net:80 + + - name: Install apt repository for Docker + become: yes + apt_repository: repo="deb https://apt.dockerproject.org/repo debian-jessie main" + + - name: Create docker group + become: yes + group: name=docker + + - name: Add users to docker group + become: yes + user: name={{ item }} groups=docker + with_items: "{{ docker_users }}" + + - name: Install Docker Engine + become: yes + apt: name=docker-engine + + - name: Start up Docker + become: yes + service: name=docker enabled=yes state=started + + - name: Check for luinet network + command: docker network ls -f name=luinet -q + register: luinet + + - name: Create luinet network + command: docker network create luinet + when: luinet.stdout == "" + + - name: Launch ZooKeeper + docker_container: name=zk1 image=jplock/zookeeper + + - name: Get networks for ZooKeeper + shell: "docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} zk1" + register: zk1_networks + + - name: Attach ZooKeeper to luinet network + command: docker network connect luinet zk1 + when: (zk1_networks.stdout|from_json).luinet is not defined + + - name: Detach ZooKeeper from bridge network + command: docker network disconnect bridge zk1 + when: (zk1_networks.stdout|from_json).bridge is defined + +- hosts: dev + roles: + - dev + +- hosts: prod + roles: + - prod + +- hosts: all + + tasks: + - name: Get networks for Solr + shell: "docker inspect --format={% raw %}'{{json .NetworkSettings.Networks}}'{% endraw %} solr1" + register: solr1_networks + + - name: Attach Solr to luinet network + command: docker network connect luinet solr1 + when: (solr1_networks.stdout|from_json).luinet is not defined + + - name: Detach Solr from bridge network + command: docker network disconnect bridge solr1 + when: (solr1_networks.stdout|from_json).bridge is defined + + # - name: Create Solr container + # docker_container: + # name: solr1 + # tty: yes + # published_ports: 8983:8983 + # #volumes: /vagrant/conf/solr/solr-home:/opt/solr/server/solr + # command: bash -c '/opt/solr/bin/solr start -f -z zk1:2181' diff --git a/docker/group_vars/dev b/docker/group_vars/dev new file mode 100644 index 0000000..4540562 --- /dev/null +++ b/docker/group_vars/dev @@ -0,0 +1,3 @@ +--- +docker_users: + - vagrant diff --git a/docker/group_vars/prod b/docker/group_vars/prod new file mode 100644 index 0000000..b9c7ad5 --- /dev/null +++ b/docker/group_vars/prod @@ -0,0 +1,3 @@ +--- +docker_users: + - "{{ ansible_user_id }}" diff --git a/docker/roles/dev/tasks/main.yml b/docker/roles/dev/tasks/main.yml new file mode 100644 index 0000000..80fff39 --- /dev/null +++ b/docker/roles/dev/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: Build the lui-solr image + docker_image: name=lui-solr path=/vagrant/docker/solr + +- name: Create Solr container + docker_container: + name: solr1 + image: lui-solr + tty: yes + published_ports: 8983:8983 + #volumes: /vagrant/conf/solr/solr-home:/opt/solr/server/solr + command: bash -c '/opt/solr/bin/solr start -f -z zk1:2181' + state: present diff --git a/docker/roles/prod/tasks/main.yml b/docker/roles/prod/tasks/main.yml new file mode 100644 index 0000000..eee7663 --- /dev/null +++ b/docker/roles/prod/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Disable Docker apt repo + become: yes + apt_repository: repo="deb https://apt.dockerproject.org/repo debian-jessie main" state=absent diff --git a/docker/solr/Dockerfile b/docker/solr/Dockerfile new file mode 100644 index 0000000..e289f80 --- /dev/null +++ b/docker/solr/Dockerfile @@ -0,0 +1,6 @@ +# Create Solr data directory as expected by lui-solr solrconfig.xml +FROM solr:6.1.0 +MAINTAINER Index Data +USER root +RUN mkdir -p /var/lib/masterkey/lui/solr/lui && chown -R solr:solr /var/lib/masterkey/lui/solr +USER solr \ No newline at end of file