Refactor entrypoint script to use Python and streamline environment variable handling
All checks were successful
Publish Twitch Archive Container / publish (push) Successful in 1m24s
All checks were successful
Publish Twitch Archive Container / publish (push) Successful in 1m24s
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
parent
4083fb4d78
commit
708464bd86
2 changed files with 33 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 "$@"
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue