Exemple #1
0
def db_configure(container, cfg):
    print("[db] Waiting for db to come up")
    docker_util.exec_safely(container, ["wait-for-db"])
    print("[db] Migrating the database")
    migrate = constellation.ImageReference("mrcide", "hint-db-migrate",
                                           cfg.db_tag)
    args = ["-url=jdbc:postgresql://{}/hint".format(container.name)]
    container.client.containers.run(str(migrate),
                                    args,
                                    network=cfg.network,
                                    auto_remove=True,
                                    detach=False)
Exemple #2
0
def hint_user(cfg, action, email, pull, password=None):
    ref = constellation.ImageReference("mrcide", "hint-user-cli", cfg.hint_tag)
    if pull or not docker_util.image_exists(str(ref)):
        docker_util.image_pull("hint cli", str(ref))
    args = [action, email]
    if action == "add-user":
        res_exists = hint_user_run(ref, ["user-exists", email], cfg)
        if res_exists.endswith("\ntrue"):
            print("Not adding user {} as they already exist".format(email))
            return
        if password:
            args.append(password)
    hint_user_run(ref, args, cfg)
Exemple #3
0
def hint_constellation(cfg):
    # 1. Redis
    redis_ref = constellation.ImageReference("library", "redis", cfg.redis_tag)
    redis_mounts = [constellation.ConstellationMount("redis", "/data")]
    redis_args = ["--appendonly", "yes"]
    redis = constellation.ConstellationContainer("redis",
                                                 redis_ref,
                                                 mounts=redis_mounts,
                                                 args=redis_args,
                                                 configure=redis_configure)

    # 2. The db
    db_ref = constellation.ImageReference("mrcide", "hint-db", cfg.db_tag)
    db_mounts = [constellation.ConstellationMount("db", "/pgdata")]
    db = constellation.ConstellationContainer("db",
                                              db_ref,
                                              mounts=db_mounts,
                                              configure=db_configure)

    # 3. hintr
    hintr_ref = cfg.hintr_ref
    hintr_args = [
        "--workers=0", "--results-dir=/results", "--prerun-dir=/prerun"
    ]
    hintr_mounts = [
        constellation.ConstellationMount("uploads", "/uploads"),
        constellation.ConstellationMount("results", "/results"),
        constellation.ConstellationMount("prerun", "/prerun")
    ]
    hintr_env = {"REDIS_URL": "redis://{}:6379".format(redis.name)}
    if cfg.hintr_use_mock_model:
        hintr_env["USE_MOCK_MODEL"] = "true"
    hintr_ports = [8888] if cfg.hint_expose else None
    hintr = constellation.ConstellationContainer("hintr",
                                                 hintr_ref,
                                                 args=hintr_args,
                                                 mounts=hintr_mounts,
                                                 ports=hintr_ports,
                                                 environment=hintr_env)

    # 4. hint
    hint_ref = constellation.ImageReference("mrcide", "hint", cfg.hint_tag)
    hint_mounts = [
        constellation.ConstellationMount("uploads", "/uploads"),
        constellation.ConstellationMount("config", "/etc/hint")
    ]
    hint_ports = [8080] if cfg.hint_expose else None
    hint = constellation.ConstellationContainer("hint",
                                                hint_ref,
                                                mounts=hint_mounts,
                                                ports=hint_ports,
                                                configure=hint_configure)

    # 5. proxy
    proxy_ref = constellation.ImageReference("reside", "proxy-nginx", "latest")
    proxy_ports = [cfg.proxy_port_http, cfg.proxy_port_https]
    proxy_args = [
        "hint:8080", cfg.proxy_host,
        str(cfg.proxy_port_http),
        str(cfg.proxy_port_https)
    ]
    proxy = constellation.ConstellationContainer("proxy",
                                                 proxy_ref,
                                                 ports=proxy_ports,
                                                 args=proxy_args,
                                                 configure=proxy_configure)

    # 6. calibrate worker
    worker_ref = cfg.hintr_worker_ref
    calibrate_worker_args = ["--calibrate-only"]
    calibrate_worker = constellation.ConstellationService(
        "calibrate_worker",
        worker_ref,
        cfg.hintr_calibrate_workers,
        args=calibrate_worker_args,
        mounts=hintr_mounts,
        environment=hintr_env)

    # 7. hintr workers
    worker = constellation.ConstellationService("worker",
                                                worker_ref,
                                                cfg.hintr_workers,
                                                mounts=hintr_mounts,
                                                environment=hintr_env)

    containers = [db, redis, hintr, hint, proxy, calibrate_worker, worker]

    obj = constellation.Constellation("hint",
                                      cfg.prefix,
                                      containers,
                                      cfg.network,
                                      cfg.volumes,
                                      data=cfg,
                                      vault_config=cfg.vault)

    return obj
Exemple #4
0
def pull_migrate_image(db_tag):
    migrate = constellation.ImageReference("mrcide", "hint-db-migrate", db_tag)
    docker_util.image_pull("db-migrate", str(migrate))
Exemple #5
0
    def __init__(self, path, config_name=None, options=None):
        dat = config.read_yaml("{}/hint.yml".format(path))
        dat = config.config_build(path, dat, config_name, options=options)
        self.network = config.config_string(dat, ["docker", "network"])
        self.prefix = config.config_string(dat, ["docker", "prefix"])
        default_tag = config.config_string(dat, ["docker", "default_tag"],
                                           True, "master")
        self.redis_tag = config.config_string(dat, ["redis", "tag"], True,
                                              default_tag)
        self.db_tag = config.config_string(dat, ["db", "tag"], True,
                                           default_tag)
        self.hint_tag = config.config_string(dat, ["hint", "tag"], True,
                                             default_tag)
        self.hint_expose = config.config_boolean(dat, ["hint", "expose"], True,
                                                 False)
        self.hintr_tag = config.config_string(dat, ["hintr", "tag"], True,
                                              default_tag)
        self.hintr_workers = config.config_integer(dat, ["hintr", "workers"])
        self.hintr_calibrate_workers = config.config_integer(
            dat, ["hintr", "calibrate_workers"])
        self.hintr_use_mock_model = config.config_boolean(
            dat, ["hintr", "use_mock_model"], True, False)

        self.hintr_ref = constellation.ImageReference("mrcide", "hintr",
                                                      self.hintr_tag)
        self.hintr_worker_ref = constellation.ImageReference(
            "mrcide", "hintr-worker", self.hintr_tag)

        self.hint_email_password = config.config_string(
            dat, ["hint", "email", "password"], True, "")

        self.hint_issue_report_url = config.config_string(
            dat, ["hint", "issue_report_url"], True, "")

        self.hint_email_mode = "real" if self.hint_email_password else "disk"
        self.hint_adr_url = config.config_string(dat, ["hint", "adr_url"],
                                                 True)

        self.proxy_host = config.config_string(dat, ["proxy", "host"])
        self.proxy_port_http = config.config_integer(dat,
                                                     ["proxy", "port_http"],
                                                     True, 80)
        self.proxy_port_https = config.config_integer(dat,
                                                      ["proxy", "port_https"],
                                                      True, 443)
        self.proxy_url = proxy_url(self.proxy_host, self.proxy_port_https)

        self.proxy_ssl_certificate = config.config_string(
            dat, ["proxy", "ssl", "certificate"], True)
        self.proxy_ssl_key = config.config_string(dat, ["proxy", "ssl", "key"],
                                                  True)
        self.volumes = {
            "db": config.config_string(dat, ["db", "volume"]),
            "redis": config.config_string(dat, ["redis", "volume"]),
            "uploads": config.config_string(dat,
                                            ["hint", "volumes", "uploads"]),
            "config": config.config_string(dat, ["hint", "volumes", "config"]),
            "results": config.config_string(dat,
                                            ["hintr", "volumes", "results"]),
            "prerun": config.config_string(dat, ["hintr", "volumes", "prerun"])
        }
        self.vault = config.config_vault(dat, ["vault"])
        self.add_test_user = config.config_boolean(dat,
                                                   ["users", "add_test_user"],
                                                   True, False)

        self.protect_data = config.config_boolean(dat,
                                                  ["deploy", "protect_data"],
                                                  True, False)