Beispiel #1
0
def _node_up(image, bindir, logdir, uid, config, dns_servers):
    node_name = config['nodes']['node']['vm.args']['name']
    cookie = config['nodes']['node']['vm.args']['setcookie']
    db_nodes = config['nodes']['node']['sys.config']['db_nodes']

    (gr_name, sep, gr_hostname) = node_name.partition('@')
    gr_dockername = common.format_dockername(gr_name, uid)

    gr_command = '''set -e
cat <<"EOF" > /tmp/gen_dev_args.json
{gen_dev_args}
EOF
escript bamboos/gen_dev/gen_dev.escript /tmp/gen_dev_args.json
/root/bin/node/bin/globalregistry console'''
    gr_command = gr_command.format(
        gen_dev_args=json.dumps({'globalregistry': config}))

    # Start DB node for current GR instance.
    # Currently, only one DB node for GR is allowed, because we are using links.
    # It's impossible to create a bigcouch cluster with docker's links.
    db_node = db_nodes[0]
    (db_name, sep, db_hostname) = db_node.partition('@')
    db_dockername = common.format_dockername(db_name, uid)

    db_command = '''echo '[httpd]' > /opt/bigcouch/etc/local.ini
echo 'bind_address = 0.0.0.0' >> /opt/bigcouch/etc/local.ini
sed -i 's/-name bigcouch/-name {name}@{host}/g' /opt/bigcouch/etc/vm.args
sed -i 's/-setcookie monster/-setcookie {cookie}/g' /opt/bigcouch/etc/vm.args
/opt/bigcouch/bin/bigcouch'''
    db_command = db_command.format(name=db_name,
                                   host=db_hostname,
                                   cookie=cookie)

    bigcouch = docker.run(image='onedata/bigcouch',
                          detach=True,
                          name=db_dockername,
                          hostname=db_hostname,
                          command=db_command)

    logdir = os.path.join(os.path.abspath(logdir), gr_name)
    volumes = [(bindir, '/root/build', 'ro')]
    volumes.extend([(logdir, '/root/bin/node/log', 'rw')] if logdir else [])

    gr = docker.run(image=image,
                    hostname=gr_hostname,
                    detach=True,
                    interactive=True,
                    tty=True,
                    workdir='/root/build',
                    name=gr_dockername,
                    volumes=volumes,
                    dns_list=dns_servers,
                    link={db_dockername: db_hostname},
                    command=gr_command)

    return gr, {
        'docker_ids': [bigcouch, gr],
        'gr_db_nodes': ['{0}@{1}'.format(db_name, db_hostname)],
        'gr_nodes': ['{0}@{1}'.format(gr_name, gr_hostname)]
    }
Beispiel #2
0
def up(uid):
    create_service = '{0}/createService.js'.format(common.get_script_dir())

    skydns = docker.run(
        image='crosbymichael/skydns',
        detach=True,
        name=common.format_dockername('skydns', uid),
        command=['-nameserver', '8.8.8.8:53', '-domain', 'docker'])

    skydock = docker.run(
        image='crosbymichael/skydock',
        detach=True,
        name=common.format_dockername('skydock', uid),
        reflect=[('/var/run/docker.sock', 'rw')],
        volumes=[(create_service, '/createService.js', 'ro')],
        command=['-ttl', '30', '-environment', 'dev', '-s',
                 '/var/run/docker.sock',
                 '-domain', 'docker', '-name', 'skydns_{0}'.format(uid),
                 '-plugins',
                 '/createService.js'])

    skydns_config = docker.inspect(skydns)
    dns = skydns_config['NetworkSettings']['IPAddress']

    return {'dns': dns, 'docker_ids': [skydns, skydock]}
Beispiel #3
0
 def build_image(self, package_url):
     print "Building shykes python app image"
     base_image, args = 'shykes/pybuilder:latest', ['/usr/local/bin/buildapp', package_url]
     print "Building image: %s, %r" % (base_image, args)
     container_id = docker.run(base_image, args)
     docker.wait(container_id)
     image_id = docker.commit(container_id, self.docker_image_tag)
     return image_id
Beispiel #4
0
def _node_up(command, num, maps, dns, image, uid):
    hostname = common.format_hostname(_riak(num), uid)
    node = docker.run(image=image,
                      name=common.format_dockername(_riak(num), uid),
                      hostname=hostname,
                      detach=True,
                      interactive=True,
                      tty=True,
                      dns_list=dns,
                      command=command.format(maps=maps, hostname=hostname))

    return {'docker_ids': [node], 'riak_nodes': [hostname]}
Beispiel #5
0
def _node_up(image, bindir, uid, config, config_path, dns_servers):
    node = config['nodes']['node']
    node_name = node['name']
    (name, sep, hostname) = node_name.partition('@')

    cert_file_path = node['user_cert']
    key_file_path = node['user_key']
    # cert_file_path and key_file_path can both be an absolute path
    # or relative to gen_dev_args.json
    cert_file_path = os.path.join(common.get_file_dir(config_path),
                                  cert_file_path)
    key_file_path = os.path.join(common.get_file_dir(config_path),
                                 key_file_path)

    node['user_cert'] = '/tmp/cert'
    node['user_key'] = '/tmp/key'

    envs = {
        'X509_USER_CERT': node['user_cert'],
        'X509_USER_KEY': node['user_key'],
        'PROVIDER_HOSTNAME': node['op_hostname'],
        'GLOBAL_REGISTRY_URL': node['gr_hostname']
    }

    command = '''set -e
cp /root/build/release/oneclient /root/bin/oneclient
cat <<"EOF" > /tmp/cert
{cert_file}
EOF
cat <<"EOF" > /tmp/key
{key_file}
EOF
bash'''
    command = command.format(cert_file=open(cert_file_path, 'r').read(),
                             key_file=open(key_file_path, 'r').read())

    container = docker.run(image=image,
                           hostname=hostname,
                           detach=True,
                           envs=envs,
                           interactive=True,
                           tty=True,
                           workdir='/root/bin',
                           name=common.format_dockername(name, uid),
                           volumes=[(bindir, '/root/build', 'ro')],
                           dns_list=dns_servers,
                           command=command)

    return {'docker_ids': [container], 'client_nodes': [hostname]}
Beispiel #6
0
def _node_up(image, bindir, logdir, uid, config, dns_servers,
             db_node_mappings):
    node_type = config['nodes']['node']['sys.config']['node_type']
    node_name = config['nodes']['node']['vm.args']['name']
    db_nodes = config['nodes']['node']['sys.config']['db_nodes']
    for i in range(len(db_nodes)):
        db_nodes[i] = db_node_mappings[db_nodes[i]]

    (name, sep, hostname) = node_name.partition('@')

    command = \
        '''set -e
cat <<"EOF" > /tmp/gen_dev_args.json
{gen_dev_args}
EOF
escript bamboos/gen_dev/gen_dev.escript /tmp/gen_dev_args.json
/root/bin/node/bin/oneprovider_node console'''
    command = command.format(gen_dev_args=json.dumps(
        {'oneprovider_node': config}),
                             uid=os.geteuid(),
                             gid=os.getegid())

    logdir = os.path.join(os.path.abspath(logdir), name) if logdir else None
    volumes = [(bindir, '/root/build', 'ro')]
    volumes.extend([(logdir, '/root/bin/node/log', 'rw')] if logdir else [])

    container = docker.run(image=image,
                           hostname=hostname,
                           detach=True,
                           interactive=True,
                           tty=True,
                           workdir='/root/build',
                           name=common.format_dockername(name, uid),
                           volumes=volumes,
                           dns_list=dns_servers,
                           command=command)

    return ([container] if node_type == 'ccm' else [],
            [container] if node_type == 'worker' else [], {
                'docker_ids': [container],
                'op_{0}_nodes'.format(node_type): [node_name]
            })
Beispiel #7
0
def _node_up(image, bindir, uid, config, config_path, dns_servers):
    node_name = config['nodes']['node']['vm.args']['name']
    (name, sep, hostname) = node_name.partition('@')

    sys_config = config['nodes']['node']['sys.config']
    # can be an absolute path or relative to gen_dev_args.json
    app_desc_file_path = sys_config['app_description_file']
    app_desc_file_name = os.path.basename(app_desc_file_path)
    app_desc_file_path = os.path.join(common.get_file_dir(config_path),
                                      app_desc_file_path)

    # file_name must be preserved as it must match the Erlang module name
    sys_config['app_description_file'] = '/tmp/' + app_desc_file_name

    command = '''set -e
cat <<"EOF" > /tmp/{app_desc_file_name}
{app_desc_file}
EOF
cat <<"EOF" > /tmp/gen_dev_args.json
{gen_dev_args}
EOF
escript bamboos/gen_dev/gen_dev.escript /tmp/gen_dev_args.json
/root/bin/node/bin/appmock console'''
    command = command.format(app_desc_file_name=app_desc_file_name,
                             app_desc_file=open(app_desc_file_path,
                                                'r').read(),
                             gen_dev_args=json.dumps({'appmock': config}))

    container = docker.run(image=image,
                           hostname=hostname,
                           detach=True,
                           interactive=True,
                           tty=True,
                           workdir='/root/build',
                           name=common.format_dockername(name, uid),
                           volumes=[(bindir, '/root/build', 'ro')],
                           dns_list=dns_servers,
                           command=command)

    return {'docker_ids': [container], 'appmock_nodes': [node_name]}
Beispiel #8
0
def _node_up(image, bindir, uid, config, dns_servers, release_path,
             storage_paths):
    node_name = config['nodes']['node']['vm.args']['name']

    (name, sep, hostname) = node_name.partition('@')

    command = \
        '''set -e
cp -R /root/release /tmp/release
cat <<"EOF" > /tmp/gen_dev_args.json
{gen_dev_args}
EOF
escript bamboos/gen_dev/gen_dev.escript /tmp/gen_dev_args.json
/root/bin/node/bin/onepanel console'''
    command = command.format(gen_dev_args=json.dumps({'onepanel': config}),
                             uid=os.geteuid(),
                             gid=os.getegid())

    volumes = [(bindir, '/root/build', 'ro'),
               (release_path, '/root/release', 'ro')]

    for storage_path in storage_paths:
        volumes.append((storage_path, storage_path, 'rw'))

    container = docker.run(image=image,
                           hostname=hostname,
                           detach=True,
                           interactive=True,
                           tty=True,
                           workdir='/root/build',
                           name=common.format_dockername(node_name, uid),
                           volumes=volumes,
                           dns_list=dns_servers,
                           command=command)

    return ({'docker_ids': [container], 'onepanel_nodes': [node_name]})
Beispiel #9
0
    # Create network to be shared among the instances.
    # The host running this will be gateway on that network, retrieve that
    # address to be able to start services on the network that the driver
    # connects to (stub server and TLS server).
    subprocess.run([
        "docker", "network", "create", "the-bridge"
    ])

    # Bootstrap the driver docker image by running a bootstrap script in the image.
    # The driver docker image only contains the tools needed to build, not the built driver.
    driverContainer = docker.run(driverImage, "driver",
        command=["python3", "/testkit/driver/bootstrap.py"],
        mountMap={
            thisPath: "/testkit", 
            driverRepo: "/driver", 
            artifactsPath: "/artifacts"
        },
        portMap={ 9876: 9876, }, # For convenience when debugging
        network="the-bridge",
        workingFolder="/driver")

    # Setup environment variables for driver container
    driverEnv = {}
    # Copy TEST_ variables that might have been set explicit
    for varName in os.environ:
        if varName.startswith("TEST_"):
            driverEnv[varName] = os.environ[varName]

    # Clean up artifacts
    driverContainer.exec(["python3", "/testkit/driver/clean_artifacts.py"], envMap=driverEnv)
Beispiel #10
0
        for container in self.list_containers():
            if stop_all and "vonsago/psp" not in container.image.tags[0]:
                container.stop()
                LOG.info("stop one of all container")
            elif image_meta in container.image.tags or image_meta == container.short_id:
                container.stop()
                LOG.info("stop {} success".format(image_meta))
                return True
        return False

    def restart(self, short_id):
        for container in self.list_containers():
            if short_id == container.short_id:
                container.restart()
        return True


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')

    with DockerClient() as docker:
        s = docker.run("mysql:5.7.19", ports={"3306/tcp": 3306},volumes=["mysqldata:/var/lib/mysql"])
        print(s.short_id)

        #print(docker_client.list_containers()[0].status)
        print(docker.list_containers())

        docker.stop("mysql:5.7.19")

Beispiel #11
0
 def run(self, app_id, docker_image_id):
     return docker.run(docker_image_id, ['/usr/local/bin/runapp'], ports=[self.exposed_port])
Beispiel #12
0
 def run(self, app_id, docker_image_id):
     return docker.run(docker_image_id, ports=[self.exposed_port])