From 40413480f22247baa1a3593a468eb2a5023bf183 Mon Sep 17 00:00:00 2001 From: Liam Jones Date: Sat, 25 Feb 2017 20:42:00 +0000 Subject: [PATCH] Allow 's_size' parameter to be changed via an environment variable --- Dockerfile | 17 +++++++++++------ README.md | 8 ++++---- apply-dockerize-template.patch | 13 +++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 apply-dockerize-template.patch diff --git a/Dockerfile b/Dockerfile index aae99e6..7c434e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,9 @@ RUN apt-get update && \ ENV PAINTSCHAINER_MODEL=original \ PAINTSCHAINER_GPU=0 \ + PAINTSCHAINER_S_SIZE=128 \ TINI_VERSION=0.14.0 \ + DOCKERIZE_VERSION=0.3.0 \ PATH=/opt/conda/bin:$PATH \ CFLAGS=-I/usr/local/cuda-8.0/targets/x86_64-linux/include/:$CFLAGS \ LDFLAGS=-L/usr/local/cuda-8.0/targets/x86_64-linux/lib/:$LDFLAGS \ @@ -21,7 +23,10 @@ ENV PAINTSCHAINER_MODEL=original \ RUN curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/unet_128_standard" > unet_128_standard && \ curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/unet_512_standard" > unet_512_standard && \ curl --location "https://github.com/liamjones/PaintsChainer-Models/releases/download/{$PAINTSCHAINER_MODEL}/License.txt" > Licence.txt && \ - curl --location "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini" > /tini + curl --location "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini" > /usr/local/bin/tini && \ + curl --location "https://github.com/jwilder/dockerize/releases/download/v$DOCKERIZE_VERSION/dockerize-linux-amd64-v$DOCKERIZE_VERSION.tar.gz" > /dockerize.tar.gz && \ + tar -C /usr/local/bin -zxvf /dockerize.tar.gz && \ + rm /dockerize.tar.gz # Re-running apt-get update because we're hoping to cache the Anaconda layer for a while RUN mkdir --parents /opt/conda/var/lib/dbus/ & \ @@ -34,10 +39,9 @@ RUN mkdir --parents /opt/conda/var/lib/dbus/ & \ tmpreaper && \ apt-get clean && \ rm --recursive --force /var/lib/apt/lists/* && \ - chmod +x /tini && \ + chmod +x /usr/local/bin/tini && \ conda install --yes --channel menpo opencv3 && \ conda clean --all && \ - pip --no-cache-dir install --upgrade pip && \ pip --no-cache-dir install chainer ENV PAINTSCHAINER_REPO=https://github.com/pfnet/PaintsChainer.git \ @@ -59,10 +63,11 @@ COPY *.patch ./ RUN git checkout $PAINTSCHAINER_COMMIT && \ git apply *.patch && \ - rm *.patch + rm *.patch && \ + mv server.py server.py.template EXPOSE 8000 -ENTRYPOINT [ "/tini", "-g", "--" ] +ENTRYPOINT [ "tini", "-g", "--" ] -CMD [ "sh", "-c", "cron && python -u server.py --host 0.0.0.0 --gpu $PAINTSCHAINER_GPU"] +CMD [ "sh", "-c", "cron && dockerize --template server.py.template:server.py && python -u server.py --host 0.0.0.0 --gpu $PAINTSCHAINER_GPU"] diff --git a/README.md b/README.md index c241d62..644f606 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,19 @@ If you want to run this on Windows and have no familiarity with Docker, etc you Ensure you have [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) installed for GPU passthrough to containers. To run with the default GPU: ```console -$ nvidia-docker run --rm -p 8000:8000 liamjones/paintschainer-docker +$ nvidia-docker run --name paintschainer --rm -p 8000:8000 liamjones/paintschainer-docker ``` If you have multiple GPUs and want to specify an alternate one you can specify GPU number via an environment variable: ```console -$ nvidia-docker run --rm -p 8000:8000 -e PAINTSCHAINER_GPU=1 liamjones/paintschainer-docker +$ nvidia-docker run --name paintschainer --rm -p 8000:8000 -e PAINTSCHAINER_GPU=1 liamjones/paintschainer-docker ``` GPU numbers can be verified by running: ```console -$ docker run liamjones/paintschainer-docker nvidia-smi +$ docker run --rm liamjones/paintschainer-docker nvidia-smi ``` ## Processing via CPU @@ -35,7 +35,7 @@ This will be slower than GPU processing but has some advantages; * Can potentially process larger images (assuming you have more RAM than VRAM) ```console -$ docker run --rm -p 8000:8000 -e PAINTSCHAINER_GPU=-1 liamjones/paintschainer-docker +$ docker run --name paintschainer --rm -p 8000:8000 -e PAINTSCHAINER_GPU=-1 liamjones/paintschainer-docker ``` ## Access the web interface diff --git a/apply-dockerize-template.patch b/apply-dockerize-template.patch new file mode 100644 index 0000000..98ee856 --- /dev/null +++ b/apply-dockerize-template.patch @@ -0,0 +1,13 @@ +diff --git a/server.py b/server.py +index 3ddc1a9..f1c914d 100755 +--- a/server.py ++++ b/server.py +@@ -114,7 +114,7 @@ class MyHandler(http.server.CGIHTTPRequestHandler): + blur = 0 + + self.log_t() +- painter.colorize(id_str, form["step"][0].decode() if "step" in form else "C", blur=blur) ++ painter.colorize(id_str, form["step"][0].decode() if "step" in form else "C", blur=blur, s_size={{ .Env.PAINTSCHAINER_S_SIZE }}) + + self.log_t() + self.ret_result(True)