Skip to content

Commit ac3f8b9

Browse files
committed
docker-compose, tests, README update
1 parent 27b7c0b commit ac3f8b9

8 files changed

+1722
-50
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,6 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
.vscode
131+
.vscode
132+
dask-worker-space
133+
profile.json

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:20.04
2+
3+
RUN apt update
4+
RUN apt install -y python3-pip
5+
RUN pip3 install poetry
6+
7+
WORKDIR /opt/src/distributed-pyspy
8+
9+
COPY poetry.lock .
10+
COPY pyproject.toml .
11+
12+
RUN poetry config virtualenvs.create false && poetry install --no-dev --no-root -E docker
13+
14+
COPY distributed_pyspy /opt/src/distributed-pyspy/distributed_pyspy
15+
RUN pip3 install --no-deps .

README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ python -m pip install git+https://github.com/gjoseph92/distributed-pyspy.git
3737

3838
## Privileges
3939

40-
You may need to run the scheduler process as root for py-spy to be able to profile it (especially on macOS). See https://github.com/benfred/py-spy#when-do-you-need-to-run-as-sudo
40+
You may need to run the scheduler process as root for py-spy to be able to profile it (especially on macOS). See https://github.com/benfred/py-spy#when-do-you-need-to-run-as-sudo.
4141

42-
In a container, even if the scheduler is running as root, you'll need the `SYS_PTRACE` capability: https://github.com/benfred/py-spy#how-do-i-run-py-spy-in-docker
42+
In a Docker container, `distributed-pyspy` should "just work" as long as your Docker/moby version is >= 20.10.6.
43+
44+
Why that version? [moby/moby#42083](https://github.com/moby/moby/pull/42083/files) recently allowlisted the `process_vm_readv` system call that py-spy uses, which used to be blocked unless you set `--cap-add SYS_PTRACE`. If you're stuck on a very slightly older version of Docker, you _could_ use the [`seccomp.json`](https://github.com/clubby789/moby/blob/d39b075302c27f77b2de413697a5aacb034d8286/profiles/seccomp/default.json) file from 20.10.6 via `--seccomp=moby-20.10.6-seccomp.json`, if you happen to be reluctant to `--cap-add SYS_PTRACE`.
45+
46+
On Ubuntu-based containers, ptrace system calls are [further blocked](https://www.kernel.org/doc/Documentation/admin-guide/LSM/Yama.rst): processes are prohibited from ptracing each other even within the same UID. To work around this, `distributed-pyspy` automatically uses [`prctl(2)`](https://man7.org/linux/man-pages/man2/prctl.2.html) to mark the scheduler process as ptrace-able by itself and any child processes, then launches py-spy as a child process.
47+
48+
If you're using an older Docker version, then https://github.com/benfred/py-spy#how-do-i-run-py-spy-in-docker still applies.
49+
50+
## Development
51+
52+
Install [Poetry](https://python-poetry.org/docs/#installation). To create a virtual environment, install dev dependencies, and install the package for local development:
53+
54+
```
55+
$ poetry install -E test
56+
```
57+
58+
There is one very very basic end-to-end test. Running it requires Docker and docker-compose, though the building and running of the containers is managed by [pytest-docker-compose](https://github.com/pytest-docker-compose/pytest-docker-compose), so all you have to do is:
59+
60+
```
61+
$ pytest tests
62+
```
63+
and wait a long time for the image to build and run.

docker-compose.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
services:
2+
scheduler:
3+
build: .
4+
command: dask-scheduler
5+
ports:
6+
- "8786:8786"
7+
- "8787:8787"
8+
security_opt:
9+
# Remove for docker >= 20.10.6
10+
- seccomp:./moby-20.10.6-seccomp.json
11+
worker-1:
12+
build: .
13+
command: dask-worker tcp://scheduler:8786
14+
depends_on:
15+
- scheduler
16+
worker-2:
17+
build: .
18+
command: dask-worker tcp://scheduler:8786
19+
depends_on:
20+
- scheduler

0 commit comments

Comments
 (0)