How to use the aiodocker.Docker function in aiodocker

To help you get started, we’ve selected a few aiodocker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hail-is / hail / batch / batch / worker.py View on Github external
PROJECT = os.environ['PROJECT']
WORKER_TYPE = os.environ['WORKER_TYPE']

log.info(f'CORES {CORES}')
log.info(f'NAME {NAME}')
log.info(f'NAMESPACE {NAMESPACE}')
# ACTIVATION_TOKEN
log.info(f'IP_ADDRESS {IP_ADDRESS}')
log.info(f'WORKER_TYPE {WORKER_TYPE}')
log.info(f'BUCKET_NAME {BUCKET_NAME}')
log.info(f'INSTANCE_ID {INSTANCE_ID}')
log.info(f'PROJECT {PROJECT}')

deploy_config = DeployConfig('gce', NAMESPACE, {})

docker = aiodocker.Docker()

port_allocator = None

worker = None


class PortAllocator:
    def __init__(self):
        self.ports = asyncio.Queue()
        port_base = 46572
        for port in range(port_base, port_base + 10):
            self.ports.put_nowait(port)

    async def allocate(self):
        return await self.ports.get()
github sphericalpm / lektorium / src / lektorium / repo / local / server.py View on Github external
async def stop(self, path, finalizer=None):
        if path in self.serves:
            return await super().stop(path, finalizer)
        session_id = path.name
        container_name = f'{self.lektor_image}-{session_id}'
        for container in await aiodocker.Docker().containers.list():
            info = await container.show()
            if info['Name'] == f'/{container_name}':
                await container.kill()
        callable(finalizer) and finalizer()
github sphericalpm / lektorium / src / lektorium / repo / local / server.py View on Github external
container, stream = None, None
        try:
            try:
                session_id = pathlib.Path(path).name
                container_name = f'{self.lektor_image}-{session_id}'
                session_address = self.session_address(session_id, container_name)
                labels = flatten_options(self.lektor_labels(session_id), 'traefik')
                session = {
                    **session,
                    'edit_url': session_address,
                }
                if 'creation_time' in session:
                    session['creation_time'] = str(session['creation_time'].timestamp())
                session.pop('parked_time', None)
                labels.update(flatten_options(session, self.LABEL_PREFIX))
                docker = aiodocker.Docker()
                container = await docker.containers.run(
                    name=container_name,
                    config=dict(
                        HostConfig=dict(
                            AutoRemove=self.auto_remove,
                            NetworkMode=await self.network_mode,
                            VolumesFrom=[
                                self.server_container,
                            ],
                        ),
                        Cmd=[
                            '--project', f'{path}',
                            'server',
                            '--host', '0.0.0.0',
                        ],
                        Labels=labels,
github sphericalpm / lektorium / src / lektorium / schema.py View on Github external
async def resolve_logs(self, info, permissions, container='lektorium'):
        import aiodocker
        if container not in ('lektorium', 'lektorium-proxy', 'traefik'):
            raise PermissionError()
        docker = aiodocker.Docker()
        lektorium = [
            c for c in await docker.containers.list()
            if (await c.show())['Name'] == f'/{container}'
        ]
        log = await lektorium[0].log(stdout=True, stderr=True, tail=200)
        return ''.join(log)
github ymyzk / mypy-playground / app / mypy_playground / sandbox.py View on Github external
def __init__(self) -> None:
        self.client = aiodocker.Docker()
        self.source_file_path = Path("/tmp/main.py")
github ymyzk / mypy-playground / app / mypy_playground / sandbox.py View on Github external
    @abstractmethod
    def __init__(self) -> None:
        pass

    @abstractmethod
    async def run_typecheck(self,
                            source: str,
                            *,
                            mypy_version: str,
                            python_version: Optional[str] = None,
                            **kwargs: Any) -> Optional[Result]:
        pass


class DockerSandbox(AbstractSandbox):
    client: aiodocker.Docker
    source_file_path: Path

    def __init__(self) -> None:
        self.client = aiodocker.Docker()
        self.source_file_path = Path("/tmp/main.py")

    def create_archive(self, source: str) -> BytesIO:
        stream = BytesIO()
        with tarfile.TarFile(fileobj=stream, mode="w") as tar:
            data = source.encode("utf-8")
            tarinfo = tarfile.TarInfo(name=self.source_file_path.name)
            tarinfo.size = len(data)
            tarinfo.mtime = int(time.time())
            tar.addfile(tarinfo, BytesIO(data))
        stream.seek(0)
        return stream
github rockstat / band-framework / band / director / dock_async.py View on Github external
def __init__(self, images_path, images, container_params, container_env, **kwargs):
        self.dc = aiodocker.Docker()
        self.initial_ports = list(range(8900, 8999))
        self.available_ports = list(self.initial_ports)
        self.images_path = images_path
        self.images = Prodict.from_dict(images)
        self.container_env = Prodict.from_dict(container_env)
        self.container_params = Prodict.from_dict(container_params)
github mushorg / tanner / tanner / utils / aiodocker_helper.py View on Github external
def __init__(self):

        self.logger = logging.getLogger('tanner.aiodocker_helper.AIODockerHelper')

        self.docker_client = aiodocker.Docker()
        self.host_image = TannerConfig.get('DOCKER', 'host_image')