Module licenseware.cli.devops_creator.devops_creator
Expand source code
import os
import random
from dataclasses import dataclass, asdict
from licenseware.cli.base_creator import BaseCreator
from licenseware.cli.utils import get_random_int
from .templates import github_workflows_templates
from .templates import aws_cloud_formation_templates
from .templates import deploy_templates
from .templates import root_templates
@dataclass
class paths:
github_workflows: str = '.github/workflows'
aws_cloudformation: str = './cloudformation-templates'
deploy_folder: str = './deploy'
deploy_jupyter_folder: str = './deploy/jupyter'
root: str = "./"
class DevOpsCreator(BaseCreator):
def __init__(self, app_id: str):
super().__init__(app_id)
def create_lint(self):
self.create_file(
filename='lint.yml',
filepath=paths.github_workflows,
template_resource=github_workflows_templates
)
def create_release_publish_notif(self):
self.create_file(
filename='release-publish-notif.yml',
filepath=paths.github_workflows,
template_resource=github_workflows_templates
)
def create_deploy_on_dev_workflow_file(self):
self.create_file(
filename="app-dash.yml".replace("app-dash", self.entity_dash),
filepath=paths.github_workflows,
template_filename="app-dash.yml.jinja",
template_resource=github_workflows_templates,
load_balancer_priority=get_random_int()
)
def create_deploy_on_prod_workflow_file(self):
self.create_file(
filename="app-dash-prod.yml".replace("app-dash", self.entity_dash),
filepath=paths.github_workflows,
template_filename="app-dash-prod.yml.jinja",
template_resource=github_workflows_templates,
load_balancer_priority=get_random_int()
)
def create_deploy_on_dev_cloudformation_file(self):
self.create_file(
filename="app-dash-api.yml".replace("app-dash", self.entity_dash),
filepath=paths.aws_cloudformation,
template_filename="app-dash-api.yml.jinja",
template_resource=aws_cloud_formation_templates
)
def create_deploy_on_prod_cloudformation_file(self):
self.create_file(
filename="app-dash-api-prod.yml".replace("app-dash", self.entity_dash),
filepath=paths.aws_cloudformation,
template_filename="app-dash-api-prod.yml.jinja",
template_resource=aws_cloud_formation_templates
)
def create_deploy_envs_files(self):
self.create_file(
filename=".env.app_title".replace("app_title", self.entity_title),
filepath=paths.deploy_folder,
template_filename="env.app_title.jinja",
template_resource=deploy_templates,
redis_db = get_random_int()
)
self.create_file(
filename=".env.debug",
filepath=paths.deploy_folder,
template_filename="env.debug.jinja",
template_resource=deploy_templates,
redis_db = get_random_int()
)
def create_deploy_jupyter_files(self):
self.create_file(
filename="docker-compose.yml",
filepath=paths.deploy_jupyter_folder,
template_resource=deploy_templates,
redis_db = get_random_int()
)
self.create_file(
filename="requirements.txt",
filepath=paths.deploy_jupyter_folder,
template_resource=deploy_templates,
redis_db = get_random_int()
)
def create_devops_root_files(self):
for file in ['docker-compose.yml', 'docker-compose-mongo.yml', 'docker-entrypoint.sh', "Dockerfile",
"Dockerfile.stack", "makefile", "pre-commit-config.yaml",
"Procfile", "Procfile.stack", "Procfile.local"]:
self.create_file(
filename=file,
filepath=paths.root,
template_resource=root_templates
)
self.create_file(
filename=".dockerignore",
filepath=paths.root,
template_filename="dockerignore.jinja",
template_resource=root_templates
)
def create(self):
for _, path in asdict(paths()).items():
if not os.path.exists(path): os.makedirs(path)
self.create_lint()
self.create_release_publish_notif()
self.create_deploy_on_dev_workflow_file()
self.create_deploy_on_prod_workflow_file()
self.create_deploy_on_dev_cloudformation_file()
self.create_deploy_on_prod_cloudformation_file()
self.create_deploy_envs_files()
self.create_deploy_jupyter_files()
self.create_devops_root_files()
Classes
class DevOpsCreator (app_id: str)
-
This class uses the given
entity_id
which can be: uploader_id, report_id, app_id etc Theentity_id
will have multiple derivate shapes (see bellow transformations in the init method) which will be passed to jinja templates as template variablesEach file creation class should inherit (if possible) from this class.
As an example you can see
licenseware/cli/uploader_creator
package.Expand source code
class DevOpsCreator(BaseCreator): def __init__(self, app_id: str): super().__init__(app_id) def create_lint(self): self.create_file( filename='lint.yml', filepath=paths.github_workflows, template_resource=github_workflows_templates ) def create_release_publish_notif(self): self.create_file( filename='release-publish-notif.yml', filepath=paths.github_workflows, template_resource=github_workflows_templates ) def create_deploy_on_dev_workflow_file(self): self.create_file( filename="app-dash.yml".replace("app-dash", self.entity_dash), filepath=paths.github_workflows, template_filename="app-dash.yml.jinja", template_resource=github_workflows_templates, load_balancer_priority=get_random_int() ) def create_deploy_on_prod_workflow_file(self): self.create_file( filename="app-dash-prod.yml".replace("app-dash", self.entity_dash), filepath=paths.github_workflows, template_filename="app-dash-prod.yml.jinja", template_resource=github_workflows_templates, load_balancer_priority=get_random_int() ) def create_deploy_on_dev_cloudformation_file(self): self.create_file( filename="app-dash-api.yml".replace("app-dash", self.entity_dash), filepath=paths.aws_cloudformation, template_filename="app-dash-api.yml.jinja", template_resource=aws_cloud_formation_templates ) def create_deploy_on_prod_cloudformation_file(self): self.create_file( filename="app-dash-api-prod.yml".replace("app-dash", self.entity_dash), filepath=paths.aws_cloudformation, template_filename="app-dash-api-prod.yml.jinja", template_resource=aws_cloud_formation_templates ) def create_deploy_envs_files(self): self.create_file( filename=".env.app_title".replace("app_title", self.entity_title), filepath=paths.deploy_folder, template_filename="env.app_title.jinja", template_resource=deploy_templates, redis_db = get_random_int() ) self.create_file( filename=".env.debug", filepath=paths.deploy_folder, template_filename="env.debug.jinja", template_resource=deploy_templates, redis_db = get_random_int() ) def create_deploy_jupyter_files(self): self.create_file( filename="docker-compose.yml", filepath=paths.deploy_jupyter_folder, template_resource=deploy_templates, redis_db = get_random_int() ) self.create_file( filename="requirements.txt", filepath=paths.deploy_jupyter_folder, template_resource=deploy_templates, redis_db = get_random_int() ) def create_devops_root_files(self): for file in ['docker-compose.yml', 'docker-compose-mongo.yml', 'docker-entrypoint.sh', "Dockerfile", "Dockerfile.stack", "makefile", "pre-commit-config.yaml", "Procfile", "Procfile.stack", "Procfile.local"]: self.create_file( filename=file, filepath=paths.root, template_resource=root_templates ) self.create_file( filename=".dockerignore", filepath=paths.root, template_filename="dockerignore.jinja", template_resource=root_templates ) def create(self): for _, path in asdict(paths()).items(): if not os.path.exists(path): os.makedirs(path) self.create_lint() self.create_release_publish_notif() self.create_deploy_on_dev_workflow_file() self.create_deploy_on_prod_workflow_file() self.create_deploy_on_dev_cloudformation_file() self.create_deploy_on_prod_cloudformation_file() self.create_deploy_envs_files() self.create_deploy_jupyter_files() self.create_devops_root_files()
Ancestors
Methods
def create(self)
-
Expand source code
def create(self): for _, path in asdict(paths()).items(): if not os.path.exists(path): os.makedirs(path) self.create_lint() self.create_release_publish_notif() self.create_deploy_on_dev_workflow_file() self.create_deploy_on_prod_workflow_file() self.create_deploy_on_dev_cloudformation_file() self.create_deploy_on_prod_cloudformation_file() self.create_deploy_envs_files() self.create_deploy_jupyter_files() self.create_devops_root_files()
def create_deploy_envs_files(self)
-
Expand source code
def create_deploy_envs_files(self): self.create_file( filename=".env.app_title".replace("app_title", self.entity_title), filepath=paths.deploy_folder, template_filename="env.app_title.jinja", template_resource=deploy_templates, redis_db = get_random_int() ) self.create_file( filename=".env.debug", filepath=paths.deploy_folder, template_filename="env.debug.jinja", template_resource=deploy_templates, redis_db = get_random_int() )
def create_deploy_jupyter_files(self)
-
Expand source code
def create_deploy_jupyter_files(self): self.create_file( filename="docker-compose.yml", filepath=paths.deploy_jupyter_folder, template_resource=deploy_templates, redis_db = get_random_int() ) self.create_file( filename="requirements.txt", filepath=paths.deploy_jupyter_folder, template_resource=deploy_templates, redis_db = get_random_int() )
def create_deploy_on_dev_cloudformation_file(self)
-
Expand source code
def create_deploy_on_dev_cloudformation_file(self): self.create_file( filename="app-dash-api.yml".replace("app-dash", self.entity_dash), filepath=paths.aws_cloudformation, template_filename="app-dash-api.yml.jinja", template_resource=aws_cloud_formation_templates )
def create_deploy_on_dev_workflow_file(self)
-
Expand source code
def create_deploy_on_dev_workflow_file(self): self.create_file( filename="app-dash.yml".replace("app-dash", self.entity_dash), filepath=paths.github_workflows, template_filename="app-dash.yml.jinja", template_resource=github_workflows_templates, load_balancer_priority=get_random_int() )
def create_deploy_on_prod_cloudformation_file(self)
-
Expand source code
def create_deploy_on_prod_cloudformation_file(self): self.create_file( filename="app-dash-api-prod.yml".replace("app-dash", self.entity_dash), filepath=paths.aws_cloudformation, template_filename="app-dash-api-prod.yml.jinja", template_resource=aws_cloud_formation_templates )
def create_deploy_on_prod_workflow_file(self)
-
Expand source code
def create_deploy_on_prod_workflow_file(self): self.create_file( filename="app-dash-prod.yml".replace("app-dash", self.entity_dash), filepath=paths.github_workflows, template_filename="app-dash-prod.yml.jinja", template_resource=github_workflows_templates, load_balancer_priority=get_random_int() )
def create_devops_root_files(self)
-
Expand source code
def create_devops_root_files(self): for file in ['docker-compose.yml', 'docker-compose-mongo.yml', 'docker-entrypoint.sh', "Dockerfile", "Dockerfile.stack", "makefile", "pre-commit-config.yaml", "Procfile", "Procfile.stack", "Procfile.local"]: self.create_file( filename=file, filepath=paths.root, template_resource=root_templates ) self.create_file( filename=".dockerignore", filepath=paths.root, template_filename="dockerignore.jinja", template_resource=root_templates )
def create_lint(self)
-
Expand source code
def create_lint(self): self.create_file( filename='lint.yml', filepath=paths.github_workflows, template_resource=github_workflows_templates )
def create_release_publish_notif(self)
-
Expand source code
def create_release_publish_notif(self): self.create_file( filename='release-publish-notif.yml', filepath=paths.github_workflows, template_resource=github_workflows_templates )
Inherited members
class paths (github_workflows: str = '.github/workflows', aws_cloudformation: str = './cloudformation-templates', deploy_folder: str = './deploy', deploy_jupyter_folder: str = './deploy/jupyter', root: str = './')
-
paths(github_workflows: str = '.github/workflows', aws_cloudformation: str = './cloudformation-templates', deploy_folder: str = './deploy', deploy_jupyter_folder: str = './deploy/jupyter', root: str = './')
Expand source code
class paths: github_workflows: str = '.github/workflows' aws_cloudformation: str = './cloudformation-templates' deploy_folder: str = './deploy' deploy_jupyter_folder: str = './deploy/jupyter' root: str = "./"
Class variables
var aws_cloudformation : str
var deploy_folder : str
var deploy_jupyter_folder : str
var github_workflows : str
var root : str