Beispiel #1
0
import pg8000  # type: ignore
import pymysql
import yaml

from materialize import spawn
from materialize import ui
from materialize.errors import (
    BadSpec,
    Failed,
    MzRuntimeError,
    UnknownItem,
    error_handler,
)

T = TypeVar("T")
say = ui.speaker("C>")

_BASHLIKE_ENV_VAR_PATTERN = re.compile(
    r"""\$\{
        (?P<var>[^:}]+)
        (?P<default>:-[^}]+)?
        \}""",
    re.VERBOSE,
)


@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
def cli() -> None:
    """Conduct composed docker services"""

Beispiel #2
0
from datetime import datetime, timedelta, timezone
from subprocess import CalledProcessError
from typing import Dict, List, NamedTuple, Optional

import boto3
from mypy_boto3_ec2.service_resource import Instance
from mypy_boto3_ec2.type_defs import (
    InstanceNetworkInterfaceSpecificationTypeDef,
    InstanceTypeDef,
    RunInstancesRequestRequestTypeDef,
)
from prettytable import PrettyTable

from materialize import git, spawn, ssh, ui

SPEAKER = ui.speaker("scratch> ")
ROOT = os.environ["MZ_ROOT"]


def tags(i: Instance) -> Dict[str, str]:
    if not i.tags:
        return {}
    return {t["Key"]: t["Value"] for t in i.tags}


def instance_typedef_tags(i: InstanceTypeDef) -> Dict[str, str]:
    return {t["Key"]: t["Value"] for t in i.get("Tags", [])}


def name(tags: Dict[str, str]) -> Optional[str]:
    return tags.get("Name")
Beispiel #3
0
import os
import re
import shutil
import stat
import subprocess
import sys
import time

import yaml

from materialize import cargo
from materialize import git
from materialize import spawn
from materialize import ui

announce = ui.speaker("==>")


class Fingerprint(bytes):
    """A SHA-1 hash of the inputs to an `Image`.

    The string representation uses base32 encoding to distinguish mzbuild
    fingerprints from Git's hex encoded SHA-1 hashes while still being
    URL safe.
    """
    def __str__(self) -> str:
        return base64.b32encode(self).decode()


class AcquiredFrom(enum.Enum):
    """Where an `Image` was acquired from."""
Beispiel #4
0
from pathlib import Path
from typing import IO, List, Tuple, Text, Optional, Sequence
from typing_extensions import NoReturn
import argparse
import json
import os
import sys
import webbrowser

from materialize import errors
from materialize import mzbuild
from materialize import mzcompose
from materialize import spawn
from materialize import ui

announce = ui.speaker("==> ")
say = ui.speaker("")

MIN_COMPOSE_VERSION = (1, 24, 0)


def main(argv: List[str]) -> int:
    # Lightly parse the arguments so we know what to do.
    args, unknown_args = ArgumentParser().parse_known_args(argv)
    if args.file:
        raise errors.MzConfigurationError("-f/--file option not supported")
    elif args.project_directory:
        raise errors.MzConfigurationError(
            "--project-directory option not supported")

    ui.Verbosity.init_from_env(args.mz_quiet)
Beispiel #5
0
def mzcompose_stop(services: List[str]) -> subprocess.CompletedProcess:
    cmd = ["./mzcompose", "--mz-quiet", "stop"]
    return spawn.runv(cmd + services, capture_output=True)


def mzcompose_down(
        destroy_volumes: bool = False) -> subprocess.CompletedProcess:
    cmd = ["./mzcompose", "--mz-quiet", "down"]
    if destroy_volumes:
        cmd.append("-v")
    return spawn.runv(cmd, capture_output=True)


# Helpers

say = ui.speaker("C")


def print_docker_logs(pattern: str, tail: int = 0) -> None:
    out = spawn.capture(["docker", "ps", "-a", "--format={{.Names}}"],
                        unicode=True).splitlines()
    for line in out:
        if line.startswith(pattern):
            spawn.runv(["docker", "logs", "--tail", str(tail), line])


def now() -> datetime:
    return datetime.now(timezone.utc)


def wait_for_pg(
Beispiel #6
0
    InstanceTypeDef,
    RunInstancesRequestRequestTypeDef,
)
from prettytable import PrettyTable
from pydantic import BaseModel

from materialize import ROOT, git, spawn, ui, util

# Sane defaults for internal Materialize use in the scratch account
DEFAULT_SUBNET_ID = "subnet-00bdfbd2d97eddb86"
DEFAULT_SECURITY_GROUP_ID = "sg-06f780c8e23c0d944"
DEFAULT_INSTANCE_PROFILE_NAME = "admin-instance"

SSH_COMMAND = ["mssh", "-o", "StrictHostKeyChecking=off"]

say = ui.speaker("scratch> ")


def tags(i: Instance) -> Dict[str, str]:
    if not i.tags:
        return {}
    return {t["Key"]: t["Value"] for t in i.tags}


def instance_typedef_tags(i: InstanceTypeDef) -> Dict[str, str]:
    return {t["Key"]: t["Value"] for t in i.get("Tags", [])}


def name(tags: Dict[str, str]) -> Optional[str]:
    return tags.get("Name")
Beispiel #7
0
import sys
from datetime import date, timedelta
from typing import Optional

import click
import semver

from materialize import errors
from materialize import git
from materialize import spawn
from materialize import ui

BIN_CARGO_TOML = "src/materialized/Cargo.toml"
LICENSE = "LICENSE"

say = ui.speaker("")


@click.command()
@click.argument("version")
@click.option(
    "-b",
    "--create-branch",
    default=None,
    help="Create a branch and check it out",
)
@click.option("-c",
              "--checkout",
              default=None,
              help="Commit or branch to check out")
@click.option("--tag/--no-tag", default=True, help="")
Beispiel #8
0
            self.composition,
            "down",
            "-v",
        ]
        try:
            subprocess.check_output(cleanup, stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError, ) as e:
            print(
                f"Failed to cleanup prior state! Output from failed command:\n{e.output.decode()}"
            )
            raise


from materialize import ui

dbg = ui.speaker("DEBUG: ")


def mzbuild_tag(git_ref: str) -> str:
    if not git_ref:
        return git_ref
    try:
        return (subprocess.check_output(
            ["git", "describe", "--exact-match", git_ref],
            stderr=subprocess.STDOUT).strip().decode())
    except subprocess.CalledProcessError:
        unstable_ref = (subprocess.check_output(
            ["git", "rev-parse", "--verify", git_ref]).strip().decode())
        return f"unstable-{unstable_ref}"