in sandboxed run scripts, allow .env to be an in any ancestor directory, same as in findEnvFile; also prep for sanboxing with global command (#147)
This commit is contained in:
parent
fb1c67219d
commit
30bdef9bf5
|
@ -21,6 +21,11 @@ async function main() {
|
||||||
const config = loadCliConfig();
|
const config = loadCliConfig();
|
||||||
let input = config.getQuestion();
|
let input = config.getQuestion();
|
||||||
|
|
||||||
|
if (process.env.GEMINI_CODE_SANDBOX && !process.env.SANDBOX) {
|
||||||
|
console.log('WARNING: sandboxing is enabled, but still OUTSIDE sandbox');
|
||||||
|
// TODO: get inside sandbox
|
||||||
|
}
|
||||||
|
|
||||||
// Render UI, passing necessary config values. Check that there is no command line question.
|
// Render UI, passing necessary config values. Check that there is no command line question.
|
||||||
if (process.stdin.isTTY && input?.length === 0) {
|
if (process.stdin.isTTY && input?.length === 0) {
|
||||||
const readUpResult = await readPackageUp({ cwd: __dirname });
|
const readUpResult = await readPackageUp({ cwd: __dirname });
|
||||||
|
|
|
@ -32,7 +32,17 @@ shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
# if GEMINI_CODE_SANDBOX is not set, try to source .env in case set there
|
# if GEMINI_CODE_SANDBOX is not set, try to source .env in case set there
|
||||||
if [ -z "${GEMINI_CODE_SANDBOX:-}" ] && [ -f .env ]; then source .env; fi
|
# allow .env to be in any ancestor directory (same as findEnvFile in config.ts)
|
||||||
|
if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then
|
||||||
|
current_dir=$(pwd)
|
||||||
|
while [ "$current_dir" != "/" ]; do
|
||||||
|
if [ -f "$current_dir/.env" ]; then
|
||||||
|
source "$current_dir/.env"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
current_dir=$(dirname "$current_dir")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# if GEMINI_CODE_SANDBOX is still not set, then exit immediately w/ code 1
|
# if GEMINI_CODE_SANDBOX is still not set, then exit immediately w/ code 1
|
||||||
if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then exit 1; fi
|
if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then exit 1; fi
|
||||||
|
@ -40,6 +50,7 @@ if [ -z "${GEMINI_CODE_SANDBOX:-}" ]; then exit 1; fi
|
||||||
# lowercase GEMINI_CODE_SANDBOX
|
# lowercase GEMINI_CODE_SANDBOX
|
||||||
GEMINI_CODE_SANDBOX=$(echo "${GEMINI_CODE_SANDBOX:-}" | tr '[:upper:]' '[:lower:]')
|
GEMINI_CODE_SANDBOX=$(echo "${GEMINI_CODE_SANDBOX:-}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
# if GEMINI_CODE_SANDBOX is set to 0 or false, then exit immediately w/ code 1
|
||||||
if [[ "${GEMINI_CODE_SANDBOX:-}" =~ ^(0|false)$ ]]; then
|
if [[ "${GEMINI_CODE_SANDBOX:-}" =~ ^(0|false)$ ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -42,16 +42,27 @@ while $CMD ps -a --format "{{.Names}}" | grep -q "$IMAGE-$INDEX"; do
|
||||||
done
|
done
|
||||||
run_args+=(--name "$IMAGE-$INDEX" --hostname "$IMAGE-$INDEX")
|
run_args+=(--name "$IMAGE-$INDEX" --hostname "$IMAGE-$INDEX")
|
||||||
|
|
||||||
# also set SANDBOX environment variable as container name
|
# if .env exists, source it before variable existence checks below
|
||||||
run_args+=(--env "SANDBOX=$IMAGE-$INDEX")
|
# allow .env to be in any ancestor directory (same as findEnvFile in config.ts)
|
||||||
|
current_dir=$(pwd)
|
||||||
|
while [ "$current_dir" != "/" ]; do
|
||||||
|
if [ -f "$current_dir/.env" ]; then
|
||||||
|
source "$current_dir/.env"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
current_dir=$(dirname "$current_dir")
|
||||||
|
done
|
||||||
|
|
||||||
|
# if GEMINI_API_KEY is set, copy into container
|
||||||
|
if [ -n "${GEMINI_API_KEY:-}" ]; then run_args+=(--env GEMINI_API_KEY="$GEMINI_API_KEY"); fi
|
||||||
|
|
||||||
# pass TERM and COLORTERM to container to maintain terminal colors
|
# pass TERM and COLORTERM to container to maintain terminal colors
|
||||||
run_args+=(--env TERM --env COLORTERM)
|
if [ -n "${TERM:-}" ]; then run_args+=(--env TERM="$TERM"); fi
|
||||||
|
if [ -n "${COLORTERM:-}" ]; then run_args+=(--env COLORTERM="$COLORTERM"); fi
|
||||||
|
|
||||||
# set GEMINI_API_KEY environment variable if it exists
|
# set SANDBOX environment variable as container name
|
||||||
if [ -n "${GEMINI_API_KEY:-}" ]; then
|
# this is the preferred mechanism to detect if inside container/sandbox
|
||||||
run_args+=(--env GEMINI_API_KEY)
|
run_args+=(--env "SANDBOX=$IMAGE-$INDEX")
|
||||||
fi
|
|
||||||
|
|
||||||
# enable debugging via node --inspect-brk (and $DEBUG_PORT) if DEBUG is set
|
# enable debugging via node --inspect-brk (and $DEBUG_PORT) if DEBUG is set
|
||||||
node_args=()
|
node_args=()
|
||||||
|
|
Loading…
Reference in New Issue