Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_load_config(self):
_config_file = os.path.join(CWD, 'test/fixtures/template_config.yml')
config_loader = ConfigLoader(_config_file)
template_config = config_loader.load()
self.assertEqual("eggs", template_config["vars"]["imageTag"])
def test_follows_extends(self):
httpretty.register_uri(httpretty.POST, "https://sts.amazonaws.com/",
body=open(os.path.join(os.getcwd(), 'test', 'fixtures', 'sts-get-caller-identity-response.xml')).read(),
content_type="application/xml")
httpretty.register_uri(httpretty.POST, "https://api.ecr.us-east-1.amazonaws.com/",
body=open(os.path.join(os.getcwd(), 'test', 'fixtures', 'ecr-repositories-response.json')).read(),
content_type="application/x-amz-json-1.1")
docker_compose_yml = os.path.join(CWD, 'test/fixtures/project/hokusai/docker-compose-extends.yml.j2')
rendered_templates = docker_compose_helpers.follow_extends(docker_compose_yml)
self.assertEqual(len(rendered_templates), 1)
with open(rendered_templates[0], 'r') as f:
struct = yaml.safe_load(f.read())
self.assertEqual(struct['services']['nancy']['build']['context'], '../')
def setUp(self):
self.template_path = os.path.join(CWD, 'test/fixtures/project/hokusai')
def setUp(self):
self.kubernetes_yml = os.path.join(CWD, 'test/fixtures/kubernetes-config.yml')
def setup(project_name, template_remote, template_dir, template_vars, allow_missing_vars):
mkpath(os.path.join(CWD, HOKUSAI_CONFIG_DIR))
config.create(clean_string(project_name))
ecr = ECR()
if ecr.project_repo_exists():
print_green("Project repo %s already exists. Skipping create." % ecr.project_repo)
else:
ecr.create_project_repo()
print_green("Created project repo %s" % ecr.project_repo)
scratch_dir = None
if template_remote:
scratch_dir = tempfile.mkdtemp()
git_repo_and_branch = template_remote.split('#', 1)
git_repo = git_repo_and_branch[0]
if len(git_repo_and_branch) == 2:
git_branch = git_repo_and_branch[1]
@click.option('--project-name', type=click.STRING, default=os.path.basename(hokusai.CWD), help='The project name (default: name of current directory)')
@click.option('--template-remote', type=click.STRING, help='Git remote of templates to use - you can specify a branch via #')
@click.option('--template-dir', type=click.STRING, help='Directory of templates to use - can be used with --template-remote')
@click.option('--var', type=click.STRING, multiple=True, help='Extra variables to render Jinja templates in the form of key=value')
@click.option('--allow-missing-vars', is_flag=True, help='Do not fail on undefined template vars')
@click.option('-v', '--verbose', type=click.BOOL, is_flag=True, help='Verbose output')
def setup(project_name, template_remote, template_dir, var, allow_missing_vars, verbose):
"""Set up Hokusai for the current project"""
set_verbosity(verbose)
hokusai.setup(project_name, template_remote, template_dir, var, allow_missing_vars)
def delete(app_name, verbose):
"""Deletes the Kubernetes based resources defined in ./hokusai/{APP_NAME}.yml"""
set_verbosity(verbose)
hokusai.k8s_delete(KUBE_CONTEXT, namespace=clean_string(app_name), filename=os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % app_name))
def k8s_create(context, tag='latest', namespace=None, filename=None, environment=()):
if filename is None:
kubernetes_yml = os.path.join(CWD, HOKUSAI_CONFIG_DIR, "%s.yml" % context)
else:
kubernetes_yml = filename
if not os.path.isfile(kubernetes_yml):
raise HokusaiError("Yaml file %s does not exist." % kubernetes_yml)
ecr = ECR()
if not ecr.project_repo_exists():
raise HokusaiError("ECR repository %s does not exist... did you run `hokusai setup` for this project?" % config.project_name)
if not ecr.tag_exists(tag):
raise HokusaiError("Image tag %s does not exist... did you run `hokusai registry push`?" % tag)
if tag is 'latest' and not ecr.tag_exists(context):
ecr.retag(tag, context)
print_green("Updated tag 'latest' -> %s" % context)