From 2c15b2a49cc3826c76432693413680140dd019f4 Mon Sep 17 00:00:00 2001 From: sheepmax <guichardmax@gmail.com> Date: Thu, 27 Jul 2023 19:30:39 +0200 Subject: [PATCH] Added docker deployment setup, fixed bugs with directory listing parsing --- Dockerfile | 6 ++++++ book/thebe_lite/_static/sphinx-thebe.js | 4 ++-- build-lite.sh | 2 +- deploy-book.sh | 6 ++++++ docker-compose.yml | 12 ++++++++++++ docker.sh | 5 +++++ stop-deployment.sh | 3 +++ 7 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 Dockerfile create mode 100755 deploy-book.sh create mode 100644 docker-compose.yml create mode 100755 docker.sh create mode 100755 stop-deployment.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4992f6be --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.11-slim-bullseye +WORKDIR /book +RUN apt-get update && apt-get -y install git +COPY requirements.txt requirements.txt +RUN pip install -r requirements.txt +CMD ["./docker.sh"] diff --git a/book/thebe_lite/_static/sphinx-thebe.js b/book/thebe_lite/_static/sphinx-thebe.js index 28a7e08c..fe250c86 100644 --- a/book/thebe_lite/_static/sphinx-thebe.js +++ b/book/thebe_lite/_static/sphinx-thebe.js @@ -311,9 +311,9 @@ function override_pyodide_lookup(fs, server_path) { continue; } - // Find alls all the rows in the html with class="display-name" and a file with a .py extension in the text + // Find alls all the links with .py files in the directory listing // We cannot use DOMParser here since it's running inside a web worker: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API - const regex = /class=\"display-name\".*?\>\<.*?\>(.*?\.py)\<.*?\>/g; + const regex = /\<a href=\"(.*?\.py)\"\>(.*?\.py)\<.*?\>/g; regex.lastIndex = 0; for (const match of request.response.matchAll(regex)) { diff --git a/build-lite.sh b/build-lite.sh index 9ef79264..1111adb3 100755 --- a/build-lite.sh +++ b/build-lite.sh @@ -31,6 +31,6 @@ fi # 7. cp: finally copies all files from the /book folder to /book/_build/html find book/ -exec test -f {} \; -print | grep -v "^book/_.*\|.*\.\(md\|ipynb\)\|thebe_lite" | cut -c 6- | xargs -i sh -c 'echo "book/_build/html/{}" | grep -o "^.*/" | xargs -d "\n" mkdir -p; cp book/"{}" book/_build/html/"{}"' -# Serves the files on port 8000, localhost (127.0.0.1:8000) +# Serves the files on port 8000 $python_command -m http.server 8000 --directory book/_build/html & diff --git a/deploy-book.sh b/deploy-book.sh new file mode 100755 index 00000000..c6fcad45 --- /dev/null +++ b/deploy-book.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +docker compose down +docker compose up -d + +docker logs -f mude-book diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..61f7b71d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +services: + web: + container_name: mude-book + build: . + ports: + - "8000:8000" + volumes: + - type: bind + source: ./ + target: /book + stdin_open: true + tty: true diff --git a/docker.sh b/docker.sh new file mode 100755 index 00000000..4737b791 --- /dev/null +++ b/docker.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +./build-lite.sh + +bash diff --git a/stop-deployment.sh b/stop-deployment.sh new file mode 100755 index 00000000..6a8204fd --- /dev/null +++ b/stop-deployment.sh @@ -0,0 +1,3 @@ +#!/bin/sh +docker compose down + -- GitLab