Skip to content

Commit

Permalink
Add west's blackhole script
Browse files Browse the repository at this point in the history
Signed-off-by: David Young <[email protected]>
  • Loading branch information
funkypenguin committed Aug 23, 2024
1 parent a96fc52 commit 877bb69
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/wests-blackhole-script/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 4 additions & 0 deletions apps/wests-blackhole-script/blackhole.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

cd /app
python blackhole_watcher.py
5 changes: 5 additions & 0 deletions apps/wests-blackhole-script/ci/goss.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# https://github.com/aelsabbahy/goss/blob/master/docs/manual.md#process
process:
python3:
running: true
4 changes: 4 additions & 0 deletions apps/wests-blackhole-script/ci/latest.sh
Original file line number Diff line number Diff line change
@@ -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}"
11 changes: 11 additions & 0 deletions apps/wests-blackhole-script/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions apps/wests-blackhole-script/launch-tmux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

tmux -f /restricted.tmux.conf new-session -A -s blackhole /blackhole.sh

17 changes: 17 additions & 0 deletions apps/wests-blackhole-script/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"app": "wests-blackhole-script",
"base": false,
"channels": [
{
"name": "main",
"platforms": [
"linux/amd64"
],
"stable": true,
"tests": {
"enabled": false,
"type": "web"
}
}
]
}
19 changes: 19 additions & 0 deletions apps/wests-blackhole-script/restricted.tmux.conf
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 877bb69

Please sign in to comment.