diff --git a/apps/wests-blackhole-script/Dockerfile b/apps/wests-blackhole-script/Dockerfile new file mode 100644 index 0000000000..4324ad8880 --- /dev/null +++ b/apps/wests-blackhole-script/Dockerfile @@ -0,0 +1,38 @@ +FROM alpine as cloner +ARG VERSION +RUN apk add --update --no-cache tmux ttyd git && \ + git clone -b $VERSION https://github.com/westsurname/scripts.git /source + +FROM python:3.9-slim + +ARG SERVICE_NAME=blackhole + +# Set working directory +WORKDIR /app + +# Copy only the files needed for pip install to maximize cache utilization +COPY --from=cloner /source/requirements.txt ./ + +# Install Python dependencies +RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt && \ + pip install --no-cache-dir -r service_requirements.txt + +# Copy the rest of the application +COPY --from=cloner /source/. . + +CMD ["python", "blackhole_watcher.py"] + +# Add tmux +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + tmux + +# Add ttyd +ADD --chmod=755 https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 /usr/local/bin/ttyd + +COPY --chown=568:568 apps/wests-blackhole-script/blackhole.sh / +COPY --chown=568:568 apps/wests-blackhole-script/launch-tmux.sh / +COPY --chown=568:568 apps/wests-blackhole-script/entrypoint.sh / +COPY --chown=568:568 apps/wests-blackhole-script/restricted.tmux.conf / + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/apps/wests-blackhole-script/blackhole.sh b/apps/wests-blackhole-script/blackhole.sh new file mode 100755 index 0000000000..48d8cd078b --- /dev/null +++ b/apps/wests-blackhole-script/blackhole.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd /app +python blackhole_watcher.py \ No newline at end of file diff --git a/apps/wests-blackhole-script/ci/goss.yaml b/apps/wests-blackhole-script/ci/goss.yaml new file mode 100644 index 0000000000..5273bcb2a6 --- /dev/null +++ b/apps/wests-blackhole-script/ci/goss.yaml @@ -0,0 +1,5 @@ +--- +# https://github.com/aelsabbahy/goss/blob/master/docs/manual.md#process +process: + python3: + running: true \ No newline at end of file diff --git a/apps/wests-blackhole-script/ci/latest.sh b/apps/wests-blackhole-script/ci/latest.sh new file mode 100755 index 0000000000..6a7c32c87b --- /dev/null +++ b/apps/wests-blackhole-script/ci/latest.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +version=$(curl -sX GET https://api.github.com/repos/westsurname/scripts/releases/latest --header "Authorization: Bearer ${TOKEN}" | jq --raw-output '. | .tag_name') +version="${version#*release-}" +printf "%s" "${version}" diff --git a/apps/wests-blackhole-script/entrypoint.sh b/apps/wests-blackhole-script/entrypoint.sh new file mode 100755 index 0000000000..b07954f0cd --- /dev/null +++ b/apps/wests-blackhole-script/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Start riven in the background +tmux -f /restricted.tmux.conf new-session -x 80 -y 24 -A -d -s blackhole /blackhole.sh + +# Prepare a tmux entry to the already-running process, use solarized dark colors +ttyd -p 3001 -W \ + -t titleFixed='Blackhole | ElfHosted' \ + -t 'theme={"background": "#1c1c1c", "brightGreen": "#585858", "blue": "#0087ff", "black": "#262626", "brightBlack": "#1c1c1c", "brightBlue": "#808080", "brightCyan": "#8a8a8a", "brightMagenta": "#5f5faf", "brightRed": "#d75f00", "brightWhite": "#ffffd7", "brightYellow": "#626262", "cyan": "#00afaf", "green": "#5f8700", "magenta": "#af005f", "red": "#d70000", "white": "#e4e4e4", "yellow": "#af8700"}' \ + -t drawBoldTextInBrightColors=false \ + /launch-tmux.sh diff --git a/apps/wests-blackhole-script/launch-tmux.sh b/apps/wests-blackhole-script/launch-tmux.sh new file mode 100755 index 0000000000..03023f6df6 --- /dev/null +++ b/apps/wests-blackhole-script/launch-tmux.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +tmux -f /restricted.tmux.conf new-session -A -s blackhole /blackhole.sh + diff --git a/apps/wests-blackhole-script/metadata.json b/apps/wests-blackhole-script/metadata.json new file mode 100644 index 0000000000..382103c794 --- /dev/null +++ b/apps/wests-blackhole-script/metadata.json @@ -0,0 +1,17 @@ +{ + "app": "wests-blackhole-script", + "base": false, + "channels": [ + { + "name": "main", + "platforms": [ + "linux/amd64" + ], + "stable": true, + "tests": { + "enabled": false, + "type": "web" + } + } + ] +} diff --git a/apps/wests-blackhole-script/restricted.tmux.conf b/apps/wests-blackhole-script/restricted.tmux.conf new file mode 100644 index 0000000000..1e8d476ef3 --- /dev/null +++ b/apps/wests-blackhole-script/restricted.tmux.conf @@ -0,0 +1,19 @@ +# Always launch PD +set -g default-command "/blackhole.sh" + +# "lock down" tmux +unbind C-b +unbind % +unbind '"' +unbind c +set -g mouse off + +# Disable status bar +set -g status off + +# Disable special characters on scrolling +set -g terminal-overrides 'xterm*:smcup@:rmcup@' + +# resize as requested +# set -g window-size latest +setw -g aggressive-resize on \ No newline at end of file