Submatter/docker/opencode/entrypoint.sh
Randall Stillwell d90ff11f5b
Some checks are pending
CI / Lint, type-check, test (push) Waiting to run
Deploy homelab (CT 116) / Deploy to CT 116 (push) Waiting to run
feat(opencode): ship tooling image with git, node, and build deps
Extend the Alpine OpenCode base so agent sessions can clone, npm/pnpm
install, and compile native modules; seed Forgejo HTTPS creds at start.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-14 12:16:26 -05:00

49 lines
1.7 KiB
Bash

#!/bin/sh
# Seed OmniRoute auth for headless OpenCode, then start serve/web.
set -eu
CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME:-/data}/.config}"
DATA_HOME="${XDG_DATA_HOME:-${HOME:-/data}/.local/share}"
mkdir -p "$CONFIG_HOME/opencode" "$DATA_HOME/opencode" /data/bin "$HOME"
# Container has no desktop — stub xdg-open so `opencode web` does not exit.
if [ ! -x /data/bin/xdg-open ]; then
printf '#!/bin/sh\nexit 0\n' > /data/bin/xdg-open
chmod +x /data/bin/xdg-open
fi
export PATH="/data/bin:${PATH}"
if [ -f /config/opencode.json ]; then
cp /config/opencode.json "$CONFIG_HOME/opencode/opencode.json"
fi
if [ -n "${OMNIROUTE_API_KEY:-}" ]; then
# Keys must not contain double-quotes; OmniRoute keys are hex/base64-safe.
printf '{"omniroute":{"type":"api","key":"%s"}}\n' "$OMNIROUTE_API_KEY" \
> "$DATA_HOME/opencode/auth.json"
chmod 600 "$DATA_HOME/opencode/auth.json" || true
fi
# Git identity + Forgejo HTTPS auth for clone/push from agent sessions.
if command -v git >/dev/null 2>&1; then
git config --global --add safe.directory '*'
if [ -n "${GIT_AUTHOR_NAME:-}" ]; then
git config --global user.name "$GIT_AUTHOR_NAME"
else
git config --global user.name "${GIT_USER_NAME:-opencode}"
fi
if [ -n "${GIT_AUTHOR_EMAIL:-}" ]; then
git config --global user.email "$GIT_AUTHOR_EMAIL"
else
git config --global user.email "${GIT_USER_EMAIL:-opencode@stillwell.cloud}"
fi
if [ -n "${FORGEJO_TOKEN:-}" ]; then
git config --global credential.helper store
# oauth2:<token> is Forgejo's HTTPS token username convention.
printf 'https://oauth2:%s@forgejo.stillwell.cloud\n' "$FORGEJO_TOKEN" \
> "$HOME/.git-credentials"
chmod 600 "$HOME/.git-credentials"
fi
fi
exec "$@"