-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ansible config for deploying Explorer and NeoDB
- Loading branch information
0 parents
commit 2424b2c
Showing
11 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
files/SANBI_Wildcard* | ||
files/sanbidev-combat-tb-explorer* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
explorer.sanbi.ac.za ansible_user=ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- name: Restart Docker | ||
service: | ||
name: docker | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker_mtu: 1450 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
explorer_src: sanbidev-combat-tb-explorer-f53458ddf00a.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |