Beispiel #1
0
    def run(self) -> None:
        """Method to run Docker up on the generated docker-compose file

        Returns:
            None
        """
        if self._docker_compose_exists():
            # Make sure you are configured for "shell" debugging
            self._verify_shell_config()

            # Make sure the container-container share volume exists
            share_volume = DockerVolume("labmanager_share_vol")
            if not share_volume.exists():
                share_volume.create()

            print("Running docker up. CTRL+C to exit.")
            docker_cmd = 'docker-compose -f {} run -T --service-ports labmanager'.format(
                                                                                   os.path.join(self._build_dir,
                                                                                  'docker-compose.yml'))

            # get the nvidia driver if available on the host
            nvidia_driver_version = get_nvidia_driver_version()
            if nvidia_driver_version:
                docker_cmd = f'bash -c "export NVIDIA_DRIVER_VERSION={nvidia_driver_version}; {docker_cmd}"'

            try:
                process = subprocess.run(shlex.split(docker_cmd, posix=not platform.system() == 'Windows'),
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.PIPE)
                print(process)
            except KeyboardInterrupt:
                print("\ndocker-compose exited")
Beispiel #2
0
    def launch(self):
        """Launch the docker container. """
        working_dir = os.path.join(os.path.expanduser("~"), "gigantum")
        port_mapping = {
            '10000/tcp': 10000,
            '10001/tcp': 10001,
            '10002/tcp': 10002
        }

        # Make sure the container-container share volume exists
        share_volume = DockerVolume("labmanager_share_vol")
        if not share_volume.exists():
            share_volume.create()

        volume_mapping = dict()
        volume_mapping['labmanager_share_vol'] = {
            'bind': '/mnt/share',
            'mode': 'rw'
        }
        volume_mapping['/var/run/docker.sock'] = {
            'bind': '/var/run/docker.sock',
            'mode': 'rw'
        }

        environment_mapping = dict()
        if platform.system() == 'Windows':
            # HOST_WORK_DIR will be used to mount inside labbook.
            environment_mapping['HOST_WORK_DIR'] = dockerize_windows_path(
                working_dir)
            environment_mapping['WINDOWS_HOST'] = 1
            # Windows does not support cached, but this is silently ignored (as of late Jan 2018)
            # We convert \ to /
            volume_mapping[dockerize_windows_path(working_dir)] = {
                'bind': '/mnt/gigantum',
                'mode': 'cached'
            }
        else:
            environment_mapping['HOST_WORK_DIR'] = working_dir
            environment_mapping['LOCAL_USER_ID'] = os.getuid()
            volume_mapping[working_dir] = {
                'bind': '/mnt/gigantum',
                'mode': 'cached'
            }

        # get the nvidia driver if available on the host
        nvidia_driver_version = get_nvidia_driver_version()
        if nvidia_driver_version:
            environment_mapping[
                'NVIDIA_DRIVER_VERSION'] = nvidia_driver_version

        self.docker_client.containers.run(image=self.docker_image,
                                          detach=True,
                                          name=self.container_name,
                                          init=True,
                                          ports=port_mapping,
                                          volumes=volume_mapping,
                                          environment=environment_mapping)
    def test_remove(self, cleanup_docker_vol):
        """Test checking for a docker volume that does exist"""
        dv = DockerVolume(cleanup_docker_vol)

        assert dv.exists() is False

        dv.create()

        assert dv.exists() is True

        dv.remove()

        assert dv.exists() is False
    def test_does_exist(self, setup_docker_vol):
        """Test checking for a docker volume that does exist"""
        dv = DockerVolume(setup_docker_vol[0], client=setup_docker_vol[1])

        assert dv.exists() is True
    def test_does_not_exist(self):
        """Test checking for a docker volume that does not exist"""
        dv = DockerVolume("adfdsfgdfsglsdflgdsflgj")

        assert dv.exists() is False