Skip to content

Commit

Permalink
Adds command line script for deploying Open Vault resources
Browse files Browse the repository at this point in the history
* Adds ./deploy executable script for parsing command line args.
  (run ./deploy -h for usage).
* Adds module 'deployer' which takes parsed command line args and provides methods
  for various deployment operations.
* Adds Dockerfile and nginx config file for building/deploying the ov-nginx container used for
  serving both ov_wag and ov-frontend web apps.
* Adds __pycache__ to .gitignore.

Closes #11.
  • Loading branch information
afred committed Jul 6, 2022
1 parent b1aece1 commit bab64de
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Python
__pycache__

# Database
db/

Expand Down
59 changes: 59 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
###
# Command line tool for managing Open Vault deployments
###

from argparse import ArgumentParser, SUPPRESS as NoDefault
from pprint import pp
from deployer import Deployer

parser = ArgumentParser(description='Manage Open Vault deployments')
parser.add_argument('-c', '--context',
required=True,
type=str,
choices=['openvault', 'openvault-demo'],
# TODO: elaborate. This is important and a bit complex.
# It requires that your local ~/.kube/config have these two
# contexts present and properly configured.
help='the kubectl context to use in the deployment')

parser.add_argument('--ov_wag',
type=str,
metavar='TAG|COMMIT|BRANCH|HEAD',
help='version of the ov_wag headless CMS backend to be deployed')

parser.add_argument('--ov-frontend',
type=str,
metavar='TAG|COMMIT|BRANCH|HEAD',
help='version of the ov-frontend website to be deployed')

parser.add_argument('--ov_wag-env',
type=str,
metavar='PATH',
default='./ov_wag/env.yml',
help='path to environment file for ov_wag')

parser.add_argument('--ov_wag-secrets',
type=str,
metavar='PATH',
default='./ov_wag/secrets.yml',
help='path to secrets file for ov_wag')

parser.add_argument('--ov-frontend-env',
type=str,
metavar='PATH',
default='./ov-frontend/env.yml',
help='path to environment file for ov-frontend')

parser.add_argument('--ov-nginx',
action='store_true',
help='rebuild and redeploy ov-nginx image')

# Parses the command line args.
args = parser.parse_args()

# Create a new Deployer instance form parsed command line args.
deployer = Deployer(**vars(args))

# Run the deployment.
deployer.deploy()
80 changes: 80 additions & 0 deletions deployer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
from pprint import pp

class Deployer:
def __init__(self, **kwargs):
# Set attributes from kwargs explicitly
self.context = kwargs.get('context')
self.ov_wag = kwargs.get('ov_wag')
self.ov_wag_env = kwargs.get('ov_wag_env')
self.ov_wag_secrets = kwargs.get('ov_wag_secrets')
self.ov_frontend = kwargs.get('ov_frontend')
self.ov_frontend_env = kwargs.get('ov_frontend_env')
self.ov_nginx = kwargs.get('ov_nginx')
# Switch to the specified kubectl context.
self.set_current_context()

def set_current_context(self):
os.system(f'kubectl config use-context {self.context}')

def build_ov_wag(self):
os.system(f'docker build https://github.com/WGBH-MLA/ov_wag.git#{self.ov_wag} -t {self.ov_wag_tag}')

def build_ov_frontend(self):
os.system(f'docker build https://github.com/WGBH-MLA/ov-frontend.git#{self.ov_frontend} -t {self.ov_frontend_tag}')

def build_nginx(self):
os.system(f'docker build ov-nginx')

def push_ov_wag(self):
os.system(f'docker push {self.ov_wag_tag}')

def push_ov_frontend(self):
os.system(f'docker push {self.ov_frontend_tag}')

def push_nginx(self):
os.system(f'docker push {self.ov_nginx_tag}')

def update_ov_wag_workload(self):
os.system(f'kubectl set image deployment.apps/ov ov={self.ov_wag_tag}')

def update_ov_frontend_workload(self):
os.system(f'kubectl set image deployment.apps/ov-frontend ov-frontend={self.ov_frontend_tag}')

def deploy_ov_wag(self):
print(f'Deploying ov_wag: "{self.ov_wag}"')
self.build_ov_wag()
self.push_ov_wag()
self.update_ov_wag_workload()

def deploy_ov_frontend(self):
print(f'Deploying ov-frontend: "{self.ov_frontend}"')
self.build_ov_frontend()
self.push_ov_frontend()
self.update_ov_frontend_workload()

def deploy(self):
print(f'Starting deployment using context "{self.context}"')
if not (self.ov_wag or self.ov_frontend or self.ov_nginx):
print(f'Nothing specified for deployment.')
else:
if self.ov_wag:
self.deploy_ov_wag()
if self.ov_frontend:
self.deploy_ov_frontend()
if self.ov_nginx:
self.deploy_ov_nginx()

print('Done!')

@property
def ov_wag_tag(self):
return f'wgbhmla/ov_wag:{self.ov_wag}'

@property
def ov_frontend_tag(self):
return f'wgbhmla/ov-frontend:{self.ov_frontend}'

@property
def ov_nginx_tag(self):
return f'wgbhmla/ov-nginx:latest'
3 changes: 3 additions & 0 deletions ov-nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM foggbh/ov-nginx:latest

COPY ./nginx.conf /etc/nginx/nginx.conf
12 changes: 12 additions & 0 deletions ov-nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
events {
worker_connections 4096; ## Default: 1024
}

http {
server {
listen 80 default_server;
location / {
proxy_pass http://ov-frontend:3000;
}
}
}

0 comments on commit bab64de

Please sign in to comment.