Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Sets up docker images and host containers for running the STs.
"""
containers = docker.ps("-qa").split()
for container in containers:
DockerHost.delete_container(container)
print "Host containers removed."
# Pull and save each image, so we can use them inside the host containers.
print sh.bash("./build_node.sh").stdout
docker.save("--output", "calico-node.tar", "calico/node")
if not os.path.isfile("busybox.tar"):
docker.pull("busybox:latest")
docker.save("--output", "busybox.tar", "busybox:latest")
if not os.path.isfile("nsenter.tar"):
docker.pull("jpetazzo/nsenter:latest")
docker.save("--output", "nsenter.tar", "jpetazzo/nsenter:latest")
if not os.path.isfile("etcd.tar"):
docker.pull("quay.io/coreos/etcd:v2.0.10")
docker.save("--output", "etcd.tar", "quay.io/coreos/etcd:v2.0.10")
# Create the calicoctl binary here so it will be in the volume mounted on the hosts.
print sh.bash("./create_binary.sh")
print "Calicoctl binary created."
host1 = DockerHost('host1')
DockerHost('host2')
host1.start_etcd()
def execute(self, command, **kwargs):
"""
Pass a command into a host container.
"""
return docker("exec", "-t", self.name, "bash", c=command, **kwargs)
def execute(self, command, **kwargs):
"""
Pass a command into a host container.
"""
return docker("exec", "-t", self.name, "bash", c=command, **kwargs)
def test_multi_host(self):
"""
Run a mainline multi-host test. Almost identical in function to the vagrant coreOS demo.
"""
host1 = DockerHost('host1')
host2 = DockerHost('host2')
host1.start_etcd()
host1_ip = docker.inspect("--format", "'{{ .NetworkSettings.IPAddress }}'", host1.name).stdout.rstrip()
host2_ip = docker.inspect("--format", "'{{ .NetworkSettings.IPAddress }}'", host2.name).stdout.rstrip()
etcd_port = "ETCD_AUTHORITY=%s:2379" % host1_ip
calicoctl = etcd_port + " /code/dist/calicoctl %s"
host1.listen(calicoctl % "reset || true")
host1.listen(calicoctl % ("node --ip=%s" % host1_ip))
host2.listen(calicoctl % ("node --ip=%s" % host2_ip))
calico_port = "DOCKER_HOST=localhost:2377"
# Wait for the Calico nodes to be created.
sleep(1)
host1.listen("%s docker run -e CALICO_IP=192.168.1.1 --name workload-A -tid busybox" % (calico_port))
host1.listen("%s docker run -e CALICO_IP=192.168.1.2 --name workload-B -tid busybox" % (calico_port))
def __init__(self, name):
"""
Create a container using an image made for docker-in-docker. Load saved images into it.
"""
self.name = name
pwd = sh.pwd().stdout.rstrip()
docker.run("--privileged", "-v", pwd+":/code", "--name", self.name, "-tid", "jpetazzo/dind")
self.execute("while ! docker ps; do sleep 1; done && "
"docker load --input /code/calico-node.tar && "
def run(self, *args, **kwargs):
if self.run_can_be_waited(*args, **kwargs):
process: sh.RunningCommand = sh.docker(*args, _env=self.sh_env, _bg=True, **kwargs)
try:
process.wait()
except KeyboardInterrupt as e:
logger.info("Stopping running command...")
process.signal(signal.SIGINT)
raise e
else:
process: sh.RunningCommand = sh.docker(*args, _env=self.sh_env, **kwargs)
return process
def run(self, *args, **kwargs):
if self.run_can_be_waited(*args, **kwargs):
process: sh.RunningCommand = sh.docker(*args, _env=self.sh_env, _bg=True, **kwargs)
try:
process.wait()
except KeyboardInterrupt as e:
logger.info("Stopping running command...")
process.signal(signal.SIGINT)
raise e
else:
process: sh.RunningCommand = sh.docker(*args, _env=self.sh_env, **kwargs)
return process
def run_docker_sh(docker_cmd, docker_args=None, **kwargs):
_docker_args = docker_args if docker_args is not None else []
_docker_args.insert(0, docker_cmd)
log.debug("Running 'docker {}' with args {}".format(docker_cmd, _docker_args[1:]))
return sh.docker(_docker_args, **kwargs)
docker_image_id = sh.docker("images", "-q", image_name)
if not docker_image_id:
six.print_("Build caffe docker")
sh.docker("build", "-t", image_name,
dockerfile_path)
container_id = sh.docker("ps", "-qa", "-f",
"name=%s" % container_name)
if container_id and not sh.docker("ps", "-qa", "--filter",
"status=running", "-f",
"name=%s" % container_name):
sh.docker("rm", "-f", container_name)
container_id = ""
if not container_id:
six.print_("Run caffe container")
sh.docker(
"run",
"-d",
"-it",
"--name",
container_name,
image_name,
"/bin/bash")
for input_name in input_nodes:
formatted_input_name = common.formatted_file_name(
input_file_name, input_name)
sh.docker(
"cp",
"%s/%s" % (model_output_dir, formatted_input_name),
"%s:/mace" % container_name)
def update_generic(self):
sh.docker(
'run', '--rm', '-i',
'-u', '{}:{}'.format(self.uid, self.gid),
'-e', 'CUSTOM_COMPILE_COMMAND="kubeyard update_requirements"',
'-e', 'HOME=/tmp',
*self.volumes,
self.image,
'bash', '-c', 'freeze_requirements',
_err=sys.stdout.buffer,
)