Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
export ENABLE_SEALIGHTS=true
uvicorn app:APP --host 0.0.0.0 --port 9092 --workers 1 --reload
Expand
titleSample code for dynamic update of files

If you don’t want to update your source code, you may evaluate adding these few script lines (or equivalent) in your CI/CD. Usage: ./myscript.sh mypythonfile.py

Code Block
languagebash
#!/bin/bash

[[ $1 == *.py && -f $1 ]] || { echo "Error: Provide a valid Python file (.py)"; exit 1; }

# Lines to add as an environment variable
LINES_TO_ADD=$(cat <<'EOF'
# Check for an environment variable and import accordingly
if os.getenv('ENABLE_SEALIGHTS', 'false') == 'true':
    import python_agent.init
EOF
)

# Create a backup and modify the file
cp "$1" "$1.bak" && sed -i "/^import\|^from /a\\$LINES_TO_ADD" "$1" && echo "[Sealights] Lines inserted into $1, backup created at $1.bak."

Other servers (Generic solution)

...