Skip to content

Commit 6fb38ca

Browse files
committed
Start work on python script for simplyfing tagserver installation
1 parent 97b8d8f commit 6fb38ca

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

devops/capistrano/config/deploy.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,27 @@
4949
task :copy_env_app do
5050
on roles(:app) do
5151
execute '(cp /home/ubuntu/tagbase-server/.env /home/ubuntu/tagbase-server/current;)'
52-
execute '(mkdir -p /home/ubuntu/tagbase-server/current/service/nginx/ssl;)'
53-
execute '(cd /home/ubuntu/tagbase-server/current/service/nginx/ssl; openssl req -x509 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 365 -subj "/C=GB/ST=London/L=London/O=Alros/OU=IT Department/CN=localhost")'
52+
execute '(mkdir -p /home/ubuntu/tagbase-server/current/services/nginx/ssl;)'
53+
execute '(cd /home/ubuntu/tagbase-server/current/services/nginx/ssl; openssl req -x509 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem -sha256 -days 365 -subj "/C=GB/ST=London/L=London/O=Alros/OU=IT Department/CN=localhost")'
5454
end
5555
end
5656

5757
desc 'Rebuild dependencies'
5858
task :rebuild_deps do
5959
on roles(:app) do
6060
# Your restart mechanism here, for example:
61-
execute '(cd /home/ubuntu/tagbase-server/current; sudo docker-compose build --build-arg POSTGRES_PASSWORD="tagbase" --build-arg POSTGRES_PORT="5432" --build-arg NGINX_USER="tagbase" --build-arg NGINX_PASS="tagbase")'
61+
execute '(cd /home/ubuntu/tagbase-server/current; docker-compose build --build-arg NGINX_PASS="tagbase" --build-arg NGINX_USER="tagbase" --build-arg PGBOUNCER_PORT=“6432” --build-arg POSTGRES_PASSWORD="tagbase" --build-arg POSTGRES_PORT="5432")'
6262

63-
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down; sudo docker-compose -p'tagbase' up -d)"
63+
#execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down; sudo docker-compose -p'tagbase' up -d)"
64+
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down; sudo docker-compose up -d)"
6465
end
6566
end
6667

6768
task :restart_app do
6869
on roles(:app) do
6970
# Your restart mechanism here, for example:
70-
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose -p'tagbase' down)"
71-
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose -p'tagbase' up -d)"
71+
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose down)"
72+
execute "(cd /home/ubuntu/tagbase-server/current; sudo docker-compose up -d)"
7273
end
7374
end
7475
after :deploy, 'deploy:copy_env_app'

devops/configure_servers.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import subprocess
3+
import argparse
4+
5+
6+
def handle_args():
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument('--tagbase-server-home', type=str)
9+
parser.add_argument('--installation-user', type=str)
10+
parser.add_argument('--prod-servers', type=str, nargs='*')
11+
parser.add_argument('--dev-servers', type=str, nargs='*')
12+
parser.add_argument('--dev-servers-sshkey-path', type=str)
13+
parser.add_argument('--prod-servers-sshkey-path', type=str)
14+
return vars(parser.parse_args())
15+
16+
17+
def log_tb(msg):
18+
print("[TAGBASE] {}".format(msg))
19+
20+
21+
def create_ansible_servers_file(inventory_file_path, prod_servers, dev_servers, installation_user, dev_servers_sshkey_path, prod_servers_sshkey_path):
22+
with open(inventory_file_path, 'w') as inv_file:
23+
if prod_servers != None:
24+
inv_file.write("[prod_servers]\n")
25+
for prod_server in prod_servers:
26+
inv_file.write("{}\n".format(prod_server))
27+
inv_file.write("[prod_servers:vars]\n")
28+
inv_file.write("ansible_user={}\n".format(installation_user))
29+
inv_file.write("ansible_ssh_private_key_file={}\n".format(prod_servers_sshkey_path))
30+
31+
if dev_servers != None:
32+
inv_file.write("[dev_servers]\n")
33+
for dev_server in dev_servers:
34+
inv_file.write("{}\n".format(dev_server))
35+
inv_file.write("[dev_servers:vars]\n")
36+
inv_file.write("ansible_user={}\n".format(installation_user))
37+
inv_file.write("ansible_ssh_private_key_file={}\n".format(dev_servers_sshkey_path))
38+
39+
log_tb("Completed writing {}".format(inventory_file_path))
40+
41+
42+
def run_ansible_inventory_file(tagserver_home, inventory_file_path):
43+
playbook_file_path = "{}/tagserver_playbook.yaml".format(tagserver_home)
44+
ansible_cmd = "ansible-playbook -i {} {} -v".format(inventory_file_path, playbook_file_path)
45+
subprocess.run(ansible_cmd, shell=True)
46+
log_tb("Completed configuring servers")
47+
48+
49+
if __name__ == "__main__":
50+
args = handle_args()
51+
tagbase_server_home = args['tagbase_server_home']
52+
tagbase_server_devops_home = '{}/{}'.format(tagbase_server_home, 'tagbase-server/devops')
53+
inventory_file_path = '{}/inventory_2'.format(tagbase_server_devops_home)
54+
create_ansible_servers_file(inventory_file_path, args['prod_servers'], args['dev_servers'], args['installation_user'], args['dev_servers_sshkey_path'], args['prod_servers_sshkey_path'])
55+
#run_ansible_inventory_file(tagserver_home, inventory_file_path)

devops/inventory

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#[dev_server]
2-
#tagbase_server_devserver docker_service_name=tagbase_server_devserver
3-
4-
#[prod_server]
1+
#[prod_servers]
52
#one.example.com
63
#ansible_env.TAGBASE_DEV_SERVER
74

devops/tagserver_playbook.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@
5454
- net-tools
5555
- postgresql-client
5656

57-
# - name: Install docker-compose
58-
# command: sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
59-
#
60-
# - name: Create symbolic link for docker-compose
61-
# command: sudo ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose
62-
#
63-
# - name: Setting permissions right for docker-compose
64-
# command: sudo chmod +x /usr/local/bin/docker-compose
65-
6657
- name: Create dir for project
6758
command: mkdir -p /home/ubuntu/tagbase-server/
6859

0 commit comments

Comments
 (0)