-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy refactor #22
Merged
Merged
deploy refactor #22
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3b4a936
Deployer refactor to allow other deployments
mrharpo 687d1dc
Refactor --ov-nginx to str
mrharpo f9c1cf2
Re-enable run check
mrharpo fb78bdf
Refactor src for github or local functionality
mrharpo e3cfd20
Fix ov-nxing repo name
mrharpo e71a30b
Split build commands outside class
mrharpo 4c54f24
Merge branch 'main' into 19-deploy-refactor
mrharpo 5d1bde0
Remove src override for ov-nginx
mrharpo ba53c43
Merge branch 'main' into 19-deploy-refactor
mrharpo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,8 +1,32 @@ | ||
from subprocess import run | ||
from subprocess import run as sub_run | ||
from pydantic import BaseModel | ||
|
||
OV_WAG_URL = 'https://github.com/WGBH-MLA/ov-wag.git' | ||
OV_FRONTEND_URL = 'https://github.com/WGBH-MLA/ov-frontend.git' | ||
GITHUB_URL = 'https://github.com/WGBH-MLA/' | ||
OV_WAG_URL = GITHUB_URL + 'ov-wag.git' | ||
OV_FRONT_URL = GITHUB_URL + 'ov-frontend.git' | ||
HUB_ACCOUNT = 'wgbhmla' | ||
|
||
|
||
def run(cmd: str): | ||
"""Run a shell command, and error on non-zero exit code""" | ||
sub_run(cmd, shell=True, check=True) | ||
|
||
|
||
def build_image(repo_name, tag, src=''): | ||
"""Build and tag docker image from a repo#tag""" | ||
run(f'docker build {src or repo_name} -t {HUB_ACCOUNT}/{repo_name}:{tag}') | ||
|
||
|
||
def push_image(repo_name, tag): | ||
"""Push a tagged docker image to hub.docker.com | ||
|
||
Requires the user to be logged in""" | ||
run(f'docker push {HUB_ACCOUNT}/{repo_name}:{tag}') | ||
|
||
|
||
def update_workload(pod, tag): | ||
"""Sets the backend pod image to the proper tag""" | ||
run(f'kubectl set image deployment.apps/{pod} {pod}={HUB_ACCOUNT}/{pod}:{tag}') | ||
|
||
|
||
class Deployer(BaseModel): | ||
|
@@ -17,103 +41,41 @@ class Deployer(BaseModel): | |
ov_wag_secrets: str = None | ||
ov_frontend: str = None | ||
ov_frontend_env: str = None | ||
ov_nginx: bool = None | ||
|
||
def run(self, cmd): | ||
run(cmd, shell=True, check=True) | ||
ov_nginx: str = None | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
self.set_current_context() | ||
|
||
def set_current_context(self): | ||
"""Switch to the specified kubectl context.""" | ||
self.run(f'kubectl config use-context {self.context}') | ||
|
||
def build_ov_wag(self): | ||
"""Build the backend ov_wag docker image""" | ||
self.run(f'docker build {OV_WAG_URL}#{self.ov_wag} -t {self.ov_wag_tag}') | ||
|
||
def build_ov_frontend(self): | ||
"""Build the frontend ov-frontend docker image""" | ||
self.run( | ||
f'docker build {OV_FRONTEND_URL}#{self.ov_frontend} -t {self.ov_frontend_tag}' | ||
) | ||
|
||
def build_nginx(self): | ||
"""Build the proxy nginx docker image""" | ||
self.run(f'docker build ov-nginx') | ||
|
||
def push_ov_wag(self): | ||
"""Push the backend ov_wag docker image to hub.docker.com | ||
run(f'kubectl config use-context {self.context}') | ||
|
||
Requires the user to be logged in""" | ||
self.run(f'docker push {self.ov_wag_tag}') | ||
def _deploy(self, repo_name, tag, src=''): | ||
"""Deploy helper function | ||
|
||
def push_ov_frontend(self): | ||
"""Push the frontend ov-frontend docker image to hub.docker.com | ||
|
||
Requires the user to be logged in""" | ||
self.run(f'docker push {self.ov_frontend_tag}') | ||
|
||
def push_nginx(self): | ||
"""Push the proxy nginx docker image to hub.docker.com | ||
|
||
Requires the user to be logged in""" | ||
self.run(f'docker push {self.ov_nginx_tag}') | ||
|
||
def update_ov_wag_workload(self): | ||
"""Sets the backend pod image to""" | ||
self.run(f'kubectl set image deployment.apps/ov ov={self.ov_wag_tag}') | ||
|
||
def update_ov_frontend_workload(self): | ||
self.run( | ||
f'kubectl set image deployment.apps/ov-frontend ov-frontend={self.ov_frontend_tag}' | ||
) | ||
|
||
def deploy_ov_wag(self): | ||
"""Deploy the backend""" | ||
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): | ||
"""Deploy the frontend""" | ||
print(f'Deploying ov-frontend: "{self.ov_frontend}"') | ||
self.build_ov_frontend() | ||
self.push_ov_frontend() | ||
self.update_ov_frontend_workload() | ||
|
||
def deploy_ov_nginx(self): | ||
"""Deploy the proxy | ||
|
||
TODO: deploy proxy""" | ||
print(f'Deploying ov_nginx: "{self.ov_nginx}"') | ||
Deploy an individual image from a repo and tag name""" | ||
build_image(repo_name, tag, src=src) | ||
push_image(repo_name, tag) | ||
update_workload(pod=repo_name, tag=tag) | ||
|
||
def deploy(self): | ||
"""Run the deployment process using the current context""" | ||
"""Deploy all | ||
|
||
Run the full deployer process using the current context""" | ||
print(f'Starting deployment using context "{self.context}"') | ||
|
||
if not any([self.ov_wag, self.ov_frontend, self.ov_nginx]): | ||
raise Exception(f'Nothing specified for deployment.') | ||
if self.ov_wag: | ||
self.deploy_ov_wag() | ||
self._deploy('ov-wag', self.ov_wag, src=f'{OV_WAG_URL}#{self.ov_wag}') | ||
if self.ov_frontend: | ||
self.deploy_ov_frontend() | ||
self._deploy( | ||
'ov-frontend', | ||
self.ov_frontend, | ||
src=f'{OV_FRONT_URL}#{self.ov_frontend}', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto above |
||
) | ||
if self.ov_nginx: | ||
self.deploy_ov_nginx() | ||
self._deploy('ov-nginx', self.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' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrharpo does this mean
src
will always be used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it's not needed in the nginx deploy, so we could remove it there.