Ejemplo n.º 1
0
from takeoff.azure.credentials.keyvault import KeyVaultClient
from takeoff.azure.credentials.subscription_id import SubscriptionId
from takeoff.azure.util import get_resource_group_name, get_azure_credentials_object
from takeoff.credentials.secret import Secret
from takeoff.schemas import TAKEOFF_BASE_SCHEMA
from takeoff.step import Step

logger = logging.getLogger(__name__)

SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"):
        "create_application_insights",
        vol.Required("kind"):
        vol.Any("web", "ios", "other", "store", "java", "phone"),
        vol.Required("application_type"):
        vol.Any("web", "other"),
        vol.Optional("create_databricks_secret", default=False):
        bool,
    },
    extra=vol.ALLOW_EXTRA,
)


class CreateApplicationInsights(Step):
    """Create an Application Insights service

    Credentials for an AAD user (username, password) must be available
    in your cloud vault.

    Optionally propagate the instrumentation key to Databricks as secret.
Ejemplo n.º 2
0
IP_ADDRESS_MATCH = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
DEPLOY_SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"): "deploy_to_kubernetes",
        vol.Optional("credentials", default="environment_variables"): vol.All(
            str, vol.In(["environment_variables", "azure_keyvault"])
        ),
        vol.Required("kubernetes_config_path"): str,
        vol.Optional(
            "image_pull_secret",
            default={"create": True, "secret_name": "registry-auth", "namespace": "default"},
        ): {
            vol.Optional("create", default=True): bool,
            vol.Optional("secret_name", default="registry-auth"): str,
            vol.Optional("namespace", default="default"): str,
        },
        vol.Optional("custom_values", default={}): {},
        vol.Optional("restart_unchanged_resources", default=False): bool,
        "azure": {
            vol.Required(
                "kubernetes_naming",
                description=(
                    "Naming convention for the resource."
                    "This should include the {env} parameter. For example"
                    "aks_{env}"
                ),
            ): str
        },
    },
    extra=vol.ALLOW_EXTRA,
)
Ejemplo n.º 3
0
SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"): "build_docker_image",
        vol.Optional("credentials", default="environment_variables"): vol.All(
            str, vol.In(["environment_variables", "azure_keyvault"])
        ),
        vol.Optional(
            "dockerfiles",
            default=[
                {
                    "file": "Dockerfile",
                    "postfix": None,
                    "prefix": None,
                    "custom_image_name": None,
                    "tag_release_as_latest": True,
                }
            ],
        ): [
            {
                vol.Optional("file", default="Dockerfile", description="Alternative docker file name"): str,
                vol.Optional(
                    "postfix",
                    default=None,
                    description="Postfix for the image name, will be added `before` the tag",
                ): vol.Any(None, str),
                vol.Optional(
                    "prefix",
                    default=None,
                    description=(
                        "Prefix for the image name, will be added `between` the image name"
                        "and repository (e.g. myreg.io/prefix/my-app:tag"
                    ),
                ): vol.Any(None, str),
                vol.Optional(
                    "custom_image_name", default=None, description="A custom name for the image to be used."
                ): vol.Any(None, str),
                vol.Optional(
                    "tag_release_as_latest", default=True, description="Tag a release also as 'latest' image."
                ): vol.Any(None, bool),
            }
        ],
    },
    extra=vol.ALLOW_EXTRA,
)
Ejemplo n.º 4
0
    instance: dict
    endpoint: str


@dataclass(frozen=True)
class CosmosCredentials(object):
    uri: str
    key: str


SCHEMA = TAKEOFF_BASE_SCHEMA.extend({
    "azure": {
        vol.Required(
            "cosmos_naming",
            description=("Naming convention for the resource."
                         "This should include the {env} parameter. For example"
                         "cosmos_{env}"),
        ):
        str
    }
})


class Cosmos(object):
    def __init__(self, env: ApplicationVersion, config: dict):
        self.env = env
        self.config = SCHEMA.validate(config)

    def _get_cosmos_management_client(self) -> CosmosDB:
        vault, client = KeyVaultClient.vault_and_client(self.config, self.env)
        credentials = ActiveDirectoryUserCredentials(
Ejemplo n.º 5
0
SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"):
        "configure_eventhub",
        vol.Optional("credentials_type", default="active_directory_user"):
        vol.All(str, vol.In(["active_directory_user", "service_principal"])),
        vol.Optional("credentials", default="azure_keyvault"):
        vol.All(str, vol.In(["azure_keyvault"])),
        vol.Optional("create_consumer_groups"):
        vol.All(
            vol.Length(min=1),
            [{
                vol.Required("eventhub_entity_naming"):
                str,
                vol.Required("consumer_group"):
                str,
                vol.Optional("create_databricks_secret", default=False):
                bool,
                vol.Optional("append_env_to_databricks_secret_name",
                             default=False):
                bool,
            }],
        ),
        vol.Optional("create_producer_policies"):
        vol.All(
            vol.Length(min=1),
            [{
                vol.Required("eventhub_entity_naming"): str,
                vol.Optional("create_databricks_secret", default=False): bool,
            }],
        ),
        "azure": {
            vol.Required(
                "eventhub_naming",
                description=("Naming convention for the resource."
                             "This should include the {env} parameter. For example"
                             "myeventhub{env}"),
            ):
            str
        },
    },
    extra=vol.ALLOW_EXTRA,
)
Ejemplo n.º 6
0
SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"):
        "configure_eventhub",
        vol.Optional("create_consumer_groups"):
        vol.All(
            vol.Length(min=1),
            [{
                vol.Required("eventhub_entity_naming"): str,
                vol.Required("consumer_group"): str,
                vol.Optional("create_databricks_secret", default=False): bool,
            }],
        ),
        vol.Optional("create_producer_policies"):
        vol.All(
            vol.Length(min=1),
            [{
                vol.Required("eventhub_entity_naming"): str,
                vol.Optional("create_databricks_secret", default=False): bool,
            }],
        ),
        "azure": {
            vol.Required(
                "eventhub_naming",
                description=("Naming convention for the resource."
                             "This should include the {env} parameter. For example"
                             "myeventhub{env}"),
            ):
            str
        },
    },
    extra=vol.ALLOW_EXTRA,
)
Ejemplo n.º 7
0
logger = logging.getLogger(__name__)

SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"): "deploy_to_databricks",
        vol.Required("jobs"): vol.All(
            [
                {
                    vol.Required("main_name"): str,
                    vol.Optional("config_file", default="databricks.json.j2"): str,
                    vol.Optional("name", default=""): str,
                    vol.Optional("lang", default="python"): vol.All(str, vol.In(["python", "scala"])),
                    vol.Optional("run_stream_job_immediately", default=True): bool,
                    vol.Optional("is_batch", default=False): bool,
                    vol.Optional("arguments", default=[{}]): [{}],
                    vol.Optional("schedule"): {
                        vol.Required("quartz_cron_expression"): str,
                        vol.Required("timezone_id"): str,
                    },
                }
            ],
            vol.Length(min=1),
        ),
        "common": {vol.Optional("databricks_fs_libraries_mount_path"): str},
    },
    extra=vol.ALLOW_EXTRA,
)


@dataclass(frozen=True)
Ejemplo n.º 8
0
DEPLOY_SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"):
        "deploy_to_kubernetes",
        vol.Optional("credentials_type", default="active_directory_user"):
        vol.All(str, vol.In(["active_directory_user", "service_principal"])),
        vol.Optional("credentials", default="azure_keyvault"):
        vol.All(str, vol.In(["azure_keyvault"])),
        vol.Required("kubernetes_config_path"):
        str,
        vol.Optional(
            "image_pull_secret",
            default={
                "create": True,
                "secret_name": "registry-auth",
                "namespace": "default"
            },
        ): {
            vol.Optional("create", default=True): bool,
            vol.Optional("secret_name", default="registry-auth"): str,
            vol.Optional("namespace", default="default"): str,
        },
        vol.Optional("custom_values", default={}): {},
        vol.Optional("restart_unchanged_resources", default=False):
        bool,
        vol.Optional("wait_for_rollout"): {
            vol.Optional("resource_name", default="foo/bar"):
            vol.All(str, vol.Match("^.*/.*$")),
            vol.Optional("resource_namespace", default=""):
            str,
        },
        "azure": {
            vol.Required(
                "kubernetes_naming",
                description=("Naming convention for the resource."
                             "This should include the {env} parameter. For example"
                             "aks_{env}"),
            ):
            str
        },
    },
    extra=vol.ALLOW_EXTRA,
)
Ejemplo n.º 9
0
import logging
import shutil

import voluptuous as vol

from takeoff.application_version import ApplicationVersion
from takeoff.schemas import TAKEOFF_BASE_SCHEMA
from takeoff.step import Step
from takeoff.util import run_shell_command

logger = logging.getLogger(__name__)

SCHEMA = TAKEOFF_BASE_SCHEMA.extend(
    {
        vol.Required("task"): "build_artifact",
        vol.Required("build_tool"): vol.All(str, vol.In(["python", "sbt"])),
    },
    extra=vol.ALLOW_EXTRA,
)


class BuildArtifact(Step):
    def __init__(self, env: ApplicationVersion, config: dict):
        """Build an artifact"""
        super().__init__(env, config)

    def run(self):
        if self.config["build_tool"] == "python":
            self.build_python_wheel()
        elif self.config["build_tool"] == "sbt":
            self.build_sbt_assembly_jar()