Files
open-terminal/entrypoint.sh
T
Timothy Jaeryang Baek 26090678d4 feat: add Docker secrets support for OPEN_TERMINAL_API_KEY_FILE
Allow loading the API key from a file via OPEN_TERMINAL_API_KEY_FILE,
following the convention used by the official PostgreSQL Docker image.

- Add _resolve_file_env() helper in env.py
- Add file_env shell function in entrypoint.sh
- Add _FILE fallback in cli.py run command
- Update README with Docker Compose example
- Bump version to 0.4.3

Closes #14
2026-03-02 12:17:54 -06:00

38 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -e
# -----------------------------------------------------------------------
# Docker-secrets support: resolve <VAR>_FILE → <VAR>
# Follows the convention used by the official PostgreSQL image.
# -----------------------------------------------------------------------
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
printf >&2 'error: both %s and %s are set (but are exclusive)\n' "$var" "$fileVar"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env 'OPEN_TERMINAL_API_KEY'
# Fix permissions of the home directory if the user doesn't own it
# Find out who owns /home/user
OWNER=$(stat -c '%U' /home/user 2>/dev/null || echo "user")
if [ "$OWNER" != "user" ]; then
# We use sudo because the container runs as 'user' but has passwordless sudo
sudo chown -R user:user /home/user 2>/dev/null || true
fi
exec open-terminal "$@"