Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed shared workspaces to improve compatibility (fixes #517) #518

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/roswire/app/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
__all__ = ("App",)

import os
import tempfile
import typing
from typing import Any, Mapping, Optional, Sequence

Expand Down Expand Up @@ -144,29 +142,20 @@ def launch(
environment = dict(environment) if environment else {}
volumes = dict(volumes) if volumes else {}

# generate a temporary shared directory
dir_containers = os.path.join(self._roswire.workspace, "containers")
os.makedirs(dir_containers, exist_ok=True)
host_workspace = tempfile.mkdtemp(dir=dir_containers)

container = dockerblade.provision(
image=self.image,
command="/bin/sh",
user="root",
name=name,
entrypoint="/bin/sh -c",
environment=environment,
volumes={
host_workspace: {"bind": "/.roswire", "mode": "rw"},
**volumes,
},
volumes=volumes,
ports=ports,
)

instance = AppInstance(
app=self,
dockerblade=container,
host_workspace=host_workspace,
)
return instance

Expand Down Expand Up @@ -202,6 +191,5 @@ def attach(
instance = AppInstance(
app=self,
dockerblade=container,
host_workspace=None
)
return instance
13 changes: 0 additions & 13 deletions src/roswire/app/instance.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
__all__ = ("AppInstance",)

import os
import shutil
import typing
from types import TracebackType
from typing import Optional, Type

import attr
import dockerblade
from docker.models.images import Image as DockerImage
from loguru import logger

from ..common import TypeDatabase
from ..common.catkin import CatkinInterface, CatkinMake, CatkinTools
Expand Down Expand Up @@ -38,9 +35,6 @@ class AppInstance:
Provides access to a bash shell for this container.
files: dockerblade.files.FileSystem
Provides access to the filesystem for this container.
_host_workspace: str, optional
The absolute path to the shared directory, if any, for this container's
workspace on the host machine.
_dockerblade: dockerblade.container.Container
Provides access to the underlying Docker container.
"""
Expand All @@ -51,7 +45,6 @@ class AppInstance:
files: dockerblade.files.FileSystem = attr.ib(
repr=False, init=False, eq=False
)
_host_workspace: Optional[str] = attr.ib(repr=False, default=None)

def __attrs_post_init__(self) -> None:
dockerblade = self._dockerblade
Expand Down Expand Up @@ -145,12 +138,6 @@ def close(self) -> None:
"""Closes this application instance and destroys all resources."""
self._dockerblade.remove()

workspace = self._host_workspace
if workspace and os.path.exists(workspace):
logger.debug(f"destroying app instance directory: {workspace}")
shutil.rmtree(workspace)
logger.debug(f"destroyed app instance directory: {workspace}")

def persist(
self,
repo: Optional[str] = None,
Expand Down
5 changes: 4 additions & 1 deletion src/roswire/ros1/launch/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ def _load_param_tag(
if val is not None:
value = convert_str_to_type(val, typ)
if textfile is not None:
value = self._files.read(textfile)
try:
value = self._files.read(textfile)
except dockerblade.exceptions.ContainerFileNotFound:
value = '' #TODO: FIX ME
if binfile is not None:
value = self._files.read(binfile, binary=True)
if command is not None:
Expand Down
19 changes: 9 additions & 10 deletions src/roswire/ros1/ros1.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,29 @@ class ROS1:

@classmethod
def for_app_instance(cls, instance: "AppInstance", port: int = 11311) -> "ROS1":
return ROS1(description=instance.app.description,
shell=instance.shell,
files=instance.files,
ws_host=instance._host_workspace,
ip_address=instance.ip_address,
instance=instance,
port=port,
)
return ROS1(
description=instance.app.description,
shell=instance.shell,
files=instance.files,
ip_address=instance.ip_address,
instance=instance,
port=port,
)

def __init__(
self,
instance: "AppInstance",
description: "AppDescription",
shell: dockerblade.Shell,
files: dockerblade.FileSystem,
ws_host: Optional[str],
ip_address: str,
port: int = 11311,
) -> None:
self.__instance = instance
self.__description = description
self.__shell = shell
self.__files = files
self.__ws_host = ws_host
self.__ws_host = None
assert port > 1023
self.__port = port
self.__ip_address = ip_address
Expand Down
Loading