Beispiel #1
0
def project(ctx, name, deployer, branches, wait, dryrun, output_location):
    """Create a new repository with CI/CD using a deployer"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")

    name = validate_name(name)
    branches = branches.strip()
    if "service-trigger" not in deployer or "service-role" not in deployer:
        raise click.UsageError(
            "Create a deployer service to be able to create project")

    Compiler.build_template(
        deployer,
        ProjectTemplate.get(name, branches, deployer, config),
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )

    if "projects" not in deployer:
        deployer["projects"] = []
    deployer["projects"].append(name)

    save_deployer(deployer, config)
Beispiel #2
0
def deployer(ctx, name, cloud, artifact_bucket, registry_table, wait, dryrun,
             output_location):
    """Create artifact bucket and registry table. Initialize your deployer"""
    ctx.obj.require_cloud_access()
    cloud = cloud.upper()

    name = validate_name(name)
    artifact_bucket = validate_bucket(name, artifact_bucket)
    registry_table = validate_registry(
        name, registry_table) if cloud == "AWS" else None

    deployer = {
        "name": name,
        "cloud": cloud,
        "artifact": artifact_bucket,
        "registry": registry_table,
    }
    click.echo(json.dumps(deployer))

    config = ctx.obj.config
    Compiler.build_template(
        deployer,
        InitializeDeployerTemplate.get(cloud, deployer, config),
        cloud=cloud,
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )

    save_deployer(deployer, config)
Beispiel #3
0
def subscription(ctx, name, deployer, emails, wait, dryrun, output_location):
    """Create a subscription and subscribe email addresses to it"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    if deployer.get("cloud", "").upper() == "GCP":
        raise RuntimeError("Subscriptions are not available for GCP")

    name = validate_name(name)
    emails = validate_emails(emails)
    if len(emails) == 0:
        raise click.BadParameter("There is no valid email address")

    Compiler.build_template(
        deployer,
        SubscriptionDeployerTemplate.get(name, emails, deployer, config),
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )

    if "subscriptions" not in deployer:
        deployer["subscriptions"] = []
    deployer["subscriptions"].append(f"{deployer['name']}-deployer-{name}")

    save_deployer(deployer, config)
Beispiel #4
0
def test_show_configs(deployer, config):
    os.environ["FREELDEP_CONFIG"] = CONFIG_SAMPLE
    runner = CliRunner()
    result = runner.invoke(cli, ["show", "configs"])
    assert result.exit_code == 0
    save_deployer(deployer, config)
    result = runner.invoke(cli, ["show", "configs"])
    assert "test" in result.output.strip()
    delete_deployer(config, "test")
Beispiel #5
0
def test_show_config(deployer, config):
    os.environ["FREELDEP_CONFIG"] = CONFIG_SAMPLE
    delete_deployer(config, "test")
    runner = CliRunner()
    result = runner.invoke(cli, ["show", "config", "test"])
    assert result.exit_code != 0
    save_deployer(deployer, config)
    result = runner.invoke(cli, ["show", "config", "test"])
    assert result.exit_code == 0
    assert json.loads(result.output)["name"] == "test"
    delete_deployer(config, "test")
Beispiel #6
0
def test_load_deployer(deployer, config, configfile):
    home_folder = configfile["cli"].get("home_folder")
    test_deployer = home_folder + "/test.json"
    assert file_exists(test_deployer) is False
    save_deployer(deployer, config)
    assert file_exists(test_deployer) is True
    saved_deployer = load_deployer(config, "test")
    for key in saved_deployer:
        assert saved_deployer[key] == deployer[key]
    delete_deployer(config, "test")
    assert file_exists(test_deployer) is False
Beispiel #7
0
def repository(ctx, deployer, wait, dryrun):
    """Remove the CICD integration of your deployer repository. Does not delete the repository"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    template = DeployerRepositoryTemplate.get(deployer, config)
    template[0]["template"]["parameters"]["cleanup"] = "true"
    Compiler.cleanup(deployer, template, wait=wait, dryrun=dryrun)
    del deployer["repository"]
    save_deployer(deployer, config)
Beispiel #8
0
def core(ctx, deployer, wait, dryrun):
    """Deploy core step function"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    Compiler.cleanup(deployer,
                     CoreDeployerTemplate.get(deployer, config),
                     wait=wait,
                     dryrun=dryrun)
    del deployer["deployment-workflow"]
    save_deployer(deployer, config)
Beispiel #9
0
def core(ctx, deployer, wait, dryrun, output_location):
    """Deploy core step function"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    Compiler.build_template(
        deployer,
        CoreDeployerTemplate.get(deployer, config),
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )
    deployer["deployment-workflow"] = f"{deployer['name']}-deployer-core"
    deployer["account"] = config.get("aws", "account", None)
    save_deployer(deployer, config)
Beispiel #10
0
def service(ctx, deployer, wait, dryrun):
    """Deploy core step function"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")

    Compiler.cleanup(
        deployer,
        ServiceDeployerTemplate.get(deployer, config),
        wait=wait,
        dryrun=dryrun,
    )
    del deployer["codebuild-service"]
    del deployer["service-trigger"]
    del deployer["service-role"]
    save_deployer(deployer, config)
Beispiel #11
0
def service(ctx, deployer, wait, dryrun, output_location):
    """Create a service for other codecommit repositories"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    Compiler.build_template(
        deployer,
        ServiceDeployerTemplate.get(deployer, config),
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )
    deployer["codebuild-service"] = f"{deployer['name']}-deployer-service"
    deployer["service-trigger"] = f"{deployer['name']}-deployer-service-trigger"
    deployer["service-role"] = f"{deployer['name']}-deployer-service-role"
    save_deployer(deployer, config)
Beispiel #12
0
def subscription(ctx, name, deployer, wait, dryrun):
    """Deploy core step function"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")
    if "subscriptions" not in deployer or name not in deployer["subscriptions"]:
        raise click.BadParameter(f"Subscription {name} does not exists")
    Compiler.cleanup(
        deployer,
        SubscriptionDeployerTemplate.get(name, [], deployer, config),
        wait=wait,
        dryrun=dryrun,
    )
    deployer["subscriptions"] = [
        x for x in deployer["subscriptions"] if x != name
    ]
    save_deployer(deployer, config)
Beispiel #13
0
def repository(ctx, deployer, wait, dryrun, output_location):
    """Create a repository with CI/CD to update core functionalities of your deployer"""
    ctx.obj.require_cloud_access()
    config = ctx.obj.config
    deployer = load_deployer(config, deployer)
    if deployer is None:
        raise click.BadParameter(f"Deployer {deployer} does not exist")

    Compiler.build_template(
        deployer,
        DeployerRepositoryTemplate.get(deployer, config),
        wait=wait,
        dryrun=dryrun,
        output_folder=output_location,
    )

    deployer["repository"] = f"{deployer['name']}-deployer"

    save_deployer(deployer, config)