From 01df9cc6dca984bf577518382b88ede09527539e Mon Sep 17 00:00:00 2001 From: askiiart Date: Tue, 2 Jan 2024 23:26:36 -0500 Subject: [PATCH] Actually works decently now --- Dockerfile | 2 +- README.md | 13 ++++++++++++- dd-progress-to-file.py | 25 ------------------------- dd-progress-to-html.py | 15 +++++++++++++++ docker-compose.yml | 1 + run.sh | 3 +-- site-files/tmp.html | 4 ++-- 7 files changed, 32 insertions(+), 31 deletions(-) delete mode 100755 dd-progress-to-file.py create mode 100755 dd-progress-to-html.py diff --git a/Dockerfile b/Dockerfile index 80c39d3..6561ae0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ -FROM python:slim-bookworm +FROM python:3.12-slim-bookworm RUN apt update && apt install -y pandoc CMD ["/data/run.sh"] \ No newline at end of file diff --git a/README.md b/README.md index 00459e5..dfcb7ec 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,18 @@ This puts the output of `dd` into a file, which is then read and made into a web `docker run`: ```sh -docker run -it --rm --restart unless-stopped -v .:/data registry.askiiart.net/askiiart/feed-the-void +docker run -d --restart unless-stopped -v .:/data --cpus 0.25 registry.askiiart.net/askiiart/feed-the-void +docker run -d --restart unless-stopped -v ./site-files:/usr/share/nginx/html -p 8080:80 nginx:alpine-slim ``` `docker-compose.yml`: See [docker-compose.yml](docker-compose.yml) + +## Running it manually + +Requirements: + +- Python 3.12 or later +- `pandoc` +- `sed` +- `dd` +- `/dev/zero` and `/dev/null` diff --git a/dd-progress-to-file.py b/dd-progress-to-file.py deleted file mode 100755 index 96d6bfe..0000000 --- a/dd-progress-to-file.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -# From https://stackoverflow.com/a/25755038 -from subprocess import Popen, PIPE, STDOUT -from os import remove - -shell = Popen(['dd', 'if=/dev/zero', 'of=/dev/null', 'status=progress'], - stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=1) - -try: - remove('output') -except FileNotFoundError: - pass - -try: - for line in iter(shell.stdout.readline, b''): - f = open('output', 'w') - if (line.strip() != ''): # Ignore empty lines (always 1 at the start) - line = line.rstrip() - #print(line) - f.write(line) - f.close() - -except KeyboardInterrupt: - f.close() - exit() diff --git a/dd-progress-to-html.py b/dd-progress-to-html.py new file mode 100755 index 0000000..94a6b79 --- /dev/null +++ b/dd-progress-to-html.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# From https://stackoverflow.com/a/25755038 +from subprocess import Popen, PIPE, STDOUT +from os import remove, system + +BASE_DIR = '/data' +SITE_FILES_DIR = f'{BASE_DIR}/site-files' +system(f'pandoc -f markdown-smart --data-dir . --template {SITE_FILES_DIR}/template.html -t html -o {SITE_FILES_DIR}/tmp.html {SITE_FILES_DIR}/index.md --metadata title="$(grep -m 1 -oP \'(?<=^# ).*\' {SITE_FILES_DIR}/index.md | cat)"') +system(f'sed -i "s/sourceCode /language-/g" {SITE_FILES_DIR}/tmp.html') + +shell = Popen(['dd', 'if=/dev/zero', 'of=/dev/null', 'status=progress'], + stdout=PIPE, stderr=STDOUT, universal_newlines=True, bufsize=1) + +for line in iter(shell.stdout.readline, b''): + system(f'sed "s/output here/{line.strip().replace("/", "\\/")}/g" {SITE_FILES_DIR}/tmp.html >{SITE_FILES_DIR}/index.html') diff --git a/docker-compose.yml b/docker-compose.yml index 130c16b..66b8aa1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: volumes: - .:/data restart: unless-stopped + cpus: 0.25 # will use 25% of a single core, can be lowered if needed. if you don't set a CPU limit, it'll probably pin a single core the entire time it runs nginx: image: nginx:alpine-slim diff --git a/run.sh b/run.sh index 3fcdbb9..fa68611 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,3 @@ #!/usr/bin/env bash dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) -$dir/dd-progress-to-file.py & -$dir/site-files/make-page.sh +$dir/dd-progress-to-html.py \ No newline at end of file diff --git a/site-files/tmp.html b/site-files/tmp.html index 04cdf64..c35da0d 100644 --- a/site-files/tmp.html +++ b/site-files/tmp.html @@ -3,7 +3,7 @@ - + F E E D ​ ​ T H E ​ ​ V O I D @@ -29,6 +29,6 @@