Skip to content

Commit

Permalink
Create ansible config for deploying Explorer and NeoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanheus committed May 20, 2023
0 parents commit 2424b2c
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
files/SANBI_Wildcard*
files/sanbidev-combat-tb-explorer*
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=== Deploy COMBAT-TB-Explorer and NeoDB

Ansible roles and configuration to deploy [COMBAT TB Explorer and NeoDB](https://academic.oup.com/bioinformatics/article/36/3/982/5554700).

This depends on these files (need to be put in the files/ folder) which are not included in the repository:
1. The SANBI wildcard SSL certificate (SANBI\_Wildcard.all.pem and SANBI\_Wildcard.key)
2. The source code downloaded from [Bitbucket](https://bitbucket.org/sanbidev/combat-tb-explorer/src/master/) using the Download repository option


16 changes: 16 additions & 0 deletions files/combine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

import argparse

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Combine files and ensure that each file used terminates with a line break')
parser.add_argument('output_file', type=argparse.FileType('w'))
parser.add_argument('input_filenames', nargs='+')
args = parser.parse_args()
output = args.output_file
for filename in args.input_filenames:
text = open(filename).read()
if text[-1] != '\n':
text += '\n'
output.write(text)
output.close()
1 change: 1 addition & 0 deletions hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
explorer.sanbi.ac.za ansible_user=ubuntu
13 changes: 13 additions & 0 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- hosts: all
become: true
vars:
container_count: 4
default_container_name: docker
default_container_image: ubuntu
default_container_command: sleep 1
roles:
- docker
- role: explorer
tags:
- explorer
4 changes: 4 additions & 0 deletions roles/docker/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Restart Docker
service:
name: docker
state: restarted
58 changes: 58 additions & 0 deletions roles/docker/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
- name: Install aptitude
ansible.builtin.apt:
name: aptitude
state: latest
update_cache: true

- name: Install required system packages
ansible.builtin.apt:
pkg:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
state: latest
update_cache: true

- name: Add Docker GPG apt Key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: Add Docker Repository
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/ubuntu jammy stable
state: present

- name: Update apt and install docker-ce
ansible.builtin.apt:
name: docker-ce
state: latest
update_cache: true

- name: Install Docker Module for Python
ansible.builtin.pip:
name: docker

- name: Configure MTU for Docker
ansible.builtin.copy:
dest: /etc/docker/daemon.json
owner: root
group: root
content: |
{
"mtu": {{docker_mtu|default("1450")}}
}
notify:
- Restart Docker

- name: Add ansible_user to docker group
ansible.builtin.user:
name: '{{ ansible_user }}'
groups: docker
append: yes

1 change: 1 addition & 0 deletions roles/docker/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker_mtu: 1450
71 changes: 71 additions & 0 deletions roles/explorer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
- name: Install unzip
ansible.builtin.package:
name: unzip
state: present

- name: Unpack Explorer code
ansible.builtin.unarchive:
copy: true
src: "{{explorer_src}}"
dest: "/home/{{ansible_user}}"
owner: "{{ansible_user}}"
creates: "/home/{{ansible_user}}/{{explorer_src|replace('.zip','')}}"

- name: Rename Explorer code
ansible.builtin.file:
src: "/home/{{ansible_user}}/{{explorer_src|replace('.zip', '')}}"
path: "/home/{{ansible_user}}/explorer_src"
state: link

- name: Copy SSL cert in place
ansible.builtin.copy:
src: "{{item}}"
dest: "/home/{{ansible_user}}/explorer_src/docker-svc/nginx"
loop:
- SANBI_Wildcard.all.pem
- SANBI_Wildcard.key

- name: Install jq
ansible.builtin.package:
name: jq
state: present

- name: Save IP address
ansible.builtin.shell:
cmd: "ip --json a |jq -r '.[1]|.addr_info[0].local'"
register: host_ip

- name: Fix hostname of explorer
ansible.builtin.lineinfile:
path: "/home/{{ansible_user}}/explorer_src/docker-compose-prod.yml"
line: " extra_hosts: [\"explorer.sanbi.ac.za:{{host_ip.stdout_lines[0]}}\"]"
search_string: " extra_hosts: [\"explorer.sanbi.ac.za"
state: present

- name: Install docker-compose Python module
ansible.builtin.pip:
name: docker-compose
state: present

- name: Start Explorer
community.docker.docker_compose:
project_src: "/home/{{ansible_user}}/explorer_src"
files:
- docker-compose-prod.yml
state: present

- name: Install systemd unit for explorer
ansible.builtin.template:
src: docker-compose-app.service.j2
dest: /etc/systemd/system/docker-compose-app.service
owner: root
group: root
mode: 0644

- name: Enable systemd unit for explorer
ansible.builtin.systemd:
name: docker-compose-app
daemon_reload: true
enabled: true
state: started
1 change: 1 addition & 0 deletions roles/explorer/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
explorer_src: sanbidev-combat-tb-explorer-f53458ddf00a.zip
18 changes: 18 additions & 0 deletions templates/docker-compose-app.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# /etc/systemd/system/docker-compose-app.service

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service
StartLimitIntervalSec=60

[Service]
WorkingDirectory=/home/{{ansible_user}}/explorer_src
ExecStart=/usr/bin/docker compose up
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=0
Restart=on-failure
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

0 comments on commit 2424b2c

Please sign in to comment.