]> git.za3k.com Git - mqlg.git/commitdiff
Add Dockerfile
authorZachary Vance <za3k@za3k.com>
Sat, 14 Aug 2021 22:22:58 +0000 (15:22 -0700)
committerZachary Vance <za3k@za3k.com>
Sat, 14 Aug 2021 22:22:58 +0000 (15:22 -0700)
Dockerfile [new file with mode: 0644]
README
run-docker.sh [new file with mode: 0755]

diff --git a/Dockerfile b/Dockerfile
new file mode 100644 (file)
index 0000000..2786a2f
--- /dev/null
@@ -0,0 +1,52 @@
+FROM debian:bullseye
+
+USER root
+
+ENV DEBIAN_FRONTEND noninteractive
+ENV DEBCONF_NONINTERACTIVE_SEEN true
+
+#========================
+# Packages
+#========================
+RUN apt-get update -qqy \
+  && apt-get -qqy --no-install-recommends install \
+    wondershaper \
+    ca-certificates \
+    python3 \
+    python3-pika \
+    python3-tqdm \
+    poppler-utils \
+    unzip \
+    curl \
+    wget \
+    vim-tiny \
+    nano \
+    sudo \
+    tzdata \
+    locales \
+    net-tools \
+    iputils-ping \
+  && rm -rf /var/lib/apt/lists/* \
+  && apt-get clean 
+
+#=====
+# dumb-init trivial PID 1 for Zombie reaping
+#=====
+RUN wget https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_amd64.deb \
+  && dpkg -i dumb-init_*.deb \
+  && rm dumb-init_*.deb
+
+# Get wondershaper
+RUN wget -O /usr/local/sbin/wondershaper "https://raw.githubusercontent.com/magnific0/wondershaper/master/wondershaper" \
+  && chmod +x /usr/local/sbin/wondershaper
+
+# Copy the script into the container
+COPY . /srv/mqlg
+
+#=====
+# Run
+#=====
+ENTRYPOINT ["/usr/bin/dumb-init", "--"]
+#ENV BWLIMIT 100000
+#CMD /bin/bash -c "wondershaper -a eth0 -u $BWLIMIT -d $BWLIMIT && echo $BWLIMIT > /tmp/blah && /srv/mqlg/main.py sm worker"
+CMD /srv/mqlg/main.py sm worker
diff --git a/README b/README
index abd6badd40b8112e9be09acf1e431a37eda51a7b..013501b42011a97e2e0c561c8358d5f31be13f0a 100644 (file)
--- a/README
+++ b/README
@@ -1,14 +1,19 @@
 Requirements on debian:
 
-    apt-get install python3 python3-pika python3-tqdm poppler-utils
+    apt-get install python3 python3-pika python3-tqdm poppler-utils 
 
-To run:
+To run on your machine:
 
     ./main.py sm worker
 
+To run in a docker container:
+
+    1. Edit run-docker.sh. Set a bandwidth limit and working directory
+    2. sudo run-docker.sh
+
 Notes:
 
 - /tmp: Make sure /tmp is an actual tmpfs (fast disk) before running! You can use a custom directory with the TMPDIR variable.
-- Disk required: About 2GB per thread
-- Memory required: About 0.5GB per thread
+- Disk required: About 1-2GB per thread
+- Memory required: Low, maybe 10MB per thread
 - Threads: Defaults to 1 per core, pass `--threads 4` to change.
diff --git a/run-docker.sh b/run-docker.sh
new file mode 100755 (executable)
index 0000000..ddcb944
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/sh
+set -e
+cd $(dirname $0)
+
+# Workdir path is relative to host
+WORKDIR=${WORKDIR:-/tmp}
+
+# Bandwidth limit
+BWLIMIT=${BWLIMIT:-150mbit}
+
+# build and run the container in background
+docker rm mqlg || true
+docker build -t mqlg:latest .
+docker run \
+       --restart=no \
+       --detach \
+       --name=mqlg \
+       --mount type=bind,source=${WORKDIR},destination=/tmp \
+       mqlg:latest
+
+# limit the inbound bandwidth for the container by limiting the outbound bandwidth for its root veth sibling
+targetif=$(ip a | grep $(sudo docker exec mqlg cat /sys/class/net/eth0/iflink): | cut -d' ' -f2 | cut -d@ -f1)
+tc qdisc add dev $targetif root tbf rate $BWLIMIT latency 50ms burst 1540