Python Docker
mypy Playground
Yusuke Miyazaki @ymyzk
PyCon mini Osaka 2018
2018/5/19 Grand Front Osaka
Development of mypy Playground with Python and Docker
• / @ymyzk
• @ / Indeed
• Python 6 + / PyCon JP / …
• ymyzk.com
• : → (2 ) → ( )
• Python Boot Camp in
• IT CAMPHOR-
( )
Python ? 



Python Docker 

mypy Playground
•
• mypy Playground
• Python + Docker mypy
•
•
mypy Playground
mypy ? 🙋
mypy ? 🙋
mypy
• Python
• PEP 484 / 526
• CLI
def greeting(name: str) -> str:
return f"Hello, {name}!!"
greeting("Taro")
greeting(123) # error: Argument 1 to "greeting" has
# incompatible type "int"; expected "str"
mypy Playground: mypy-play.net
• mypy Web
•
• mypy
•
• Gist
mypy Playground: URL HERE
mypy Playground
• mypy
• /tmp/test1.py
•
• mypy typeshed
:
•
• : The Go Playground / Rust Playground / Scastie (Scala)
•
• : Wandbox
• : ymyzk/awesome-playgrounds
mypy Playground

 



UI





 



UI




Ace Bootstrap Bottle Docker
•
• CPU
•
• …
•
•
• import
•
Python + Docker
mypy
Docker ? "
Docker
•
• : jail / LXC / systemd-nspawn
•
• Linux ( cgroups)
•
Docker
•
•
• Docker Hub
•
• Docker
• Docker
Python Docker
• Docker Engine API HTTP API
• CLI docker API
• Python Docker docker-py
• CLI
• docker-py
Python Docker
$ docker run ubuntu echo Hello Osaka!
import docker
client = docker.from_env()

client.containers.run("ubuntu", "echo Hello Osaka!")
mypy
1. mypy Docker
2. mypy
3.
Docker
# typed-ast manylinux1 

FROM python:3.6
RUN pip install mypy
# root
USER nobody
CMD ["mypy"]
c = client.containers.create(
"ymyzk/mypy-playground:sandbox",
command="mypy main.py",
network_mode="none", #
mem_limit="128m", #
pids_limit=32,
cap_drop="ALL",
security_opt=["no-new-privileges"])
# tar (Docker API )
tarball = create_archive(source)
c.put_archive("/tmp", tarball)#
c.start() # mypy
exit_code = c.wait() #
#
stdout = c.logs(stdout=True, stderr=False).decode("utf-8")
stderr = c.logs(stdout=False, stderr=True).decode("utf-8")
c.remove()
• Docker mypy
•
• ?
• :
Docker in Docker (dind)
• Docker Docker
• Docker 

Docker Docker


Docker in Docker
• Docker
• Docker
• Docker
Docker in Docker
• vfs 

• 

dind
mypy Playground
• I/O
• mypy
• mypy
• WSGI
•
mypy Playground with asyncio
• Bottle Tornado
• Docker asyncio aiodocker
• aiodocker docker-py
• mypy Playground
•
• typeshed / PEP 561
• Facebook Pyre
• : / dmypy
• Python + Docker mypy Playground (mypy-play.net)
• Web Python
• Docker
• Twitter: @mypy_playground / GitHub: ymyzk/mypy-playground
• !!

Python と Docker で mypy Playground を開発した話