From 708464bd865caedd89ec0f6f1bb00674fb278f4a Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sat, 25 Apr 2026 17:12:39 +0200 Subject: [PATCH] Refactor entrypoint script to use Python and streamline environment variable handling Co-authored-by: Copilot --- docker-compose.yml | 8 ++++++-- docker/entrypoint.sh | 44 ++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index afc45a1..de56f80 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,8 +27,12 @@ services: - ${TWITCH_ARCHIVE_CONFIG_BIND:-./config}:/app/config healthcheck: test: - - CMD-SHELL - - python twitch-archive.py --healthcheck -u ${TWITCH_ARCHIVE_HEALTHCHECK_STREAMER:-vinesauce} + - CMD + - python + - twitch-archive.py + - --healthcheck + - -u + - ${TWITCH_ARCHIVE_HEALTHCHECK_STREAMER:-vinesauce} interval: 30s timeout: 10s retries: 3 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b378a45..fe404da 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,27 +1,27 @@ -#!/bin/sh -set -eu +#!/usr/bin/env python3 +import os +import sys +from pathlib import Path -mkdir -p /app/archive /app/config /app/bin/temp -if [ -z "${CLIENT_ID:-}" ]; then - client_id_from_hyphenated="$(printenv 'CLIENT-ID' 2>/dev/null || true)" - if [ -n "$client_id_from_hyphenated" ]; then - export CLIENT_ID="$client_id_from_hyphenated" - fi -fi +for path in ('/app/archive', '/app/config', '/app/bin/temp'): + Path(path).mkdir(parents=True, exist_ok=True) -if [ -z "${CLIENT_SECRET:-}" ]; then - client_secret_from_hyphenated="$(printenv 'CLIENT-SECRET' 2>/dev/null || true)" - if [ -n "$client_secret_from_hyphenated" ]; then - export CLIENT_SECRET="$client_secret_from_hyphenated" - fi -fi -if [ -z "${OAUTH_PRIVATE_TOKEN:-}" ]; then - oauth_token_from_hyphenated="$(printenv 'OAUTH-PRIVATE-TOKEN' 2>/dev/null || true)" - if [ -n "$oauth_token_from_hyphenated" ]; then - export OAUTH_PRIVATE_TOKEN="$oauth_token_from_hyphenated" - fi -fi +env_aliases = { + 'CLIENT-ID': 'CLIENT_ID', + 'CLIENT-SECRET': 'CLIENT_SECRET', + 'OAUTH-PRIVATE-TOKEN': 'OAUTH_PRIVATE_TOKEN', +} -exec "$@" \ No newline at end of file +for source_name, target_name in env_aliases.items(): + source_value = os.environ.get(source_name) + if source_value and not os.environ.get(target_name): + os.environ[target_name] = source_value + + +if len(sys.argv) < 2: + raise SystemExit('twitch-archive-entrypoint requires a command to run') + + +os.execvpe(sys.argv[1], sys.argv[1:], os.environ) \ No newline at end of file