Files
biz-bud/docker/entrypoint.sh
Travis Vasceannie e0bfb7a2f2 feat: enhance coverage reporting and improve tool configuration (#55)
* feat: enhance coverage reporting and improve tool configuration

- Added support for JSON coverage reports in pyproject.toml.
- Updated .gitignore to include coverage.json and task files for better management.
- Introduced a new Type Safety Audit Report to document findings and recommendations for type safety improvements.
- Created a comprehensive coverage configuration guide to assist in understanding coverage reporting setup.
- Refactored tools configuration to utilize environment variables for concurrent scraping settings.

These changes improve the project's testing and reporting capabilities while enhancing overall code quality and maintainability.

* feat: enhance configuration handling and improve error logging

- Introduced a new utility function `_get_env_int` for robust environment variable integer retrieval with validation.
- Updated `WebToolsConfig` and `ToolsConfigModel` to utilize the new utility for environment variable defaults.
- Enhanced logging in `CircuitBreaker` to provide detailed state transition information.
- Improved URL handling in `url_analyzer.py` for better file extension extraction and normalization.
- Added type validation and logging in `SecureInputMixin` to ensure input sanitization and validation consistency.

These changes improve the reliability and maintainability of configuration management and error handling across the codebase.

* refactor: update imports and enhance .gitignore for improved organization

- Updated import paths in various example scripts to reflect the new structure under `biz_bud`.
- Enhanced .gitignore to include clearer formatting for task files.
- Removed obsolete function calls and improved error handling in several scripts.
- Added public alias for backward compatibility in `upload_r2r.py`.

These changes improve code organization, maintainability, and compatibility across the project.

* refactor: update graph paths in langgraph.json for improved organization

- Changed paths for research, catalog, paperless, and url_to_r2r graphs to reflect new directory structure.
- Added new entries for analysis and scraping graphs to enhance functionality.

These changes improve the organization and maintainability of the graph configurations.

* fix: enhance validation and error handling in date range and scraping functions

- Updated date validation in UserFiltersModel to ensure date values are strings.
- Improved error messages in create_scraped_content_dict to clarify conditions for success and failure.
- Enhanced test coverage for date validation and scraping content creation to ensure robustness.

These changes improve input validation and error handling across the application, enhancing overall reliability.

* refactor: streamline graph creation and enhance type annotations in examples

- Simplified graph creation in `catalog_ingredient_research_example.py` and `catalog_tech_components_example.py` by directly compiling the graph.
- Updated type annotations in `catalog_intel_with_config.py` for improved clarity and consistency.
- Enhanced error handling in catalog data processing to ensure robustness against unexpected data types.

These changes improve code readability, maintainability, and error resilience across example scripts.

* Update src/biz_bud/nodes/extraction/extractors.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update src/biz_bud/core/validation/pydantic_models.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* refactor: migrate Jina and Tavily clients to use ServiceFactory dependency injection

* refactor: migrate URL processing to provider-based architecture with improved error handling

* feat: add FirecrawlApp compatibility classes and mock implementations

* fix: add thread-safe locking to LazyLoader factory management

* feat: implement service restart and refactor cache decorator helpers

* refactor: move r2r_direct_api_call to tools.clients.r2r_utils and improve HTTP service error handling

* chore: update Sonar task IDs in report configuration

---------

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
2025-08-04 00:54:52 -04:00

258 lines
10 KiB
Bash

#!/bin/bash
# Docker container entrypoint script
# This script sets up Git configuration, credentials,
# 1Password SSH agent integration, and development tools
# Exit on error
set -e
# Cleanup function for temporary files and processes
cleanup() {
echo "🧹 Cleaning up temporary files..."
rm -rf /tmp/git-config /tmp/git-tools /tmp/.ssh
if [ -n "$SSH_AGENT_PID" ]; then
ssh-agent -k >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
echo "=== ???? Starting container initialization as user: $(whoami) ==="
# Note: Database initialization scripts in docker/db-init/ are automatically
# executed by PostgreSQL during first container startup via docker-entrypoint-initdb.d
## 1. Set up directories and environment variables
#echo "???? Setting up directories..."
# Create writable directories for Git configuration and tools
mkdir -p /tmp/git-config/git
mkdir -p /tmp/git-tools
# Set Git to use our writable config directory
export XDG_CONFIG_HOME="/tmp/git-config"
export GIT_CONFIG_GLOBAL="${XDG_CONFIG_HOME}/git/config"
# Initialize empty Git config
mkdir -p "$(dirname "$GIT_CONFIG_GLOBAL")"
touch "$GIT_CONFIG_GLOBAL"
chmod 600 "$GIT_CONFIG_GLOBAL"
# If /root/.gitconfig does not exist and /root/.gitconfig.host exists, copy it
if [ ! -f /root/.gitconfig ] && [ -f /root/.gitconfig.host ]; then
echo "???? Copying /root/.gitconfig.host to /root/.gitconfig for writable config..."
cp /root/.gitconfig.host /root/.gitconfig
chmod 600 /root/.gitconfig
fi
# 2. Git configuration setup
## Check for mounted Git configuration and copy contents if available
if [ -f /home/dev/.gitconfig ]; then
echo "🔧 Importing existing Git configuration..."
cat /home/dev/.gitconfig >> "$GIT_CONFIG_GLOBAL"
echo "✅ Git configuration imported successfully"
else
echo "⚠️ No Git configuration found at /home/dev/.gitconfig"
fi
## 3. Git credentials setup
## First check the tmp location
if [ -f /tmp/git-source/.git-credentials ]; then
echo "???? Setting up Git credentials from /tmp/git-source/.git-credentials..."
git config --global --replace-all credential.helper store
# Create a writable credentials file
mkdir -p "${HOME}"
# Only copy if different
if [ "/tmp/git-source/.git-credentials" != "${HOME}/.git-credentials" ]; then
cp /tmp/git-source/.git-credentials "${HOME}/.git-credentials"
fi
chmod 600 "${HOME}/.git-credentials"
echo "??? Git credentials configured successfully"
# Check alternative location
elif [ -f /home/dev/.git-credentials ]; then
echo "🔧 Setting up Git credentials from /home/dev/.git-credentials..."
git config --global --replace-all credential.helper store
# Create a writable credentials file
mkdir -p "${HOME}"
# Only copy if source and destination are different
if [ "/home/dev/.git-credentials" != "${HOME}/.git-credentials" ]; then
cp /home/dev/.git-credentials "${HOME}/.git-credentials"
chmod 600 "${HOME}/.git-credentials"
else
echo "Credentials file already in correct location"
chmod 600 "${HOME}/.git-credentials"
fi
echo "✅ Git credentials configured successfully"
else
echo "?????? No Git credentials found"
fi
## 4. 1Password SSH signing integration
## Check for 1Password SSH bridge in various possible locations
if [ -f /usr/local/bin/op-ssh-bridge.sh ]; then
OP_SSH_BRIDGE_PATH="/usr/local/bin/op-ssh-bridge.sh"
elif [ -f /tmp/op-ssh-scripts/op-ssh-sign-bridge ]; then
OP_SSH_BRIDGE_PATH="/tmp/op-ssh-scripts/op-ssh-sign-bridge"
else
OP_SSH_BRIDGE_PATH=""
fi
# Fix SSH configuration for container environment
if [ -d /home/dev/.ssh ]; then
echo "🔐 Setting up SSH configuration..."
# Copy SSH files to writable location to avoid permission issues with mounted volumes
echo "📋 Copying SSH configuration to writable location..."
mkdir -p /tmp/.ssh
# Copy files individually since glob expansion can fail with permission issues
sudo find /home/dev/.ssh -type f -exec cp {} /tmp/.ssh/ \; 2>/dev/null || echo "⚠️ Some SSH files may not be accessible"
sudo chown -R dev:dev /tmp/.ssh 2>/dev/null || true
# Fix permissions on copied files
chmod 700 /tmp/.ssh
find /tmp/.ssh -name "id_*" -type f -exec chmod 600 {} \; 2>/dev/null || true
find /tmp/.ssh -name "*.pub" -type f -exec chmod 644 {} \; 2>/dev/null || true
find /tmp/.ssh -name "config" -type f -exec chmod 600 {} \; 2>/dev/null || true
find /tmp/.ssh -name "known_hosts" -type f -exec chmod 644 {} \; 2>/dev/null || true
# Set SSH to use our writable directory
export SSH_AUTH_SOCK=""
export SSH_CONFIG_DIR="/tmp/.ssh"
# Start SSH agent
eval "$(ssh-agent -s)"
# Add SSH keys to agent
for key in /tmp/.ssh/id_* /tmp/.ssh/*_ed25519; do
if [ -f "$key" ] && [ ! -f "$key.pub" ]; then
ssh-add "$key" 2>/dev/null || echo "⚠️ Could not add key: $key"
fi
done
# Create SSH config to use our directory and the correct GitHub key
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/tmp/.ssh/known_hosts -o IdentitiesOnly=yes -i /tmp/.ssh/git_ed25519"
echo "✅ SSH configuration completed"
else
echo "⚠️ No SSH directory found"
fi
# Configure Git for container environment (disable signing for simplicity)
git config --global --unset-all commit.gpgsign || true
git config --global commit.gpgsign false
git config --global --unset gpg.program || true
git config --global --unset gpg.format || true
git config --global --unset core.sshcommand || true
echo "✅ Git commit signing disabled for container use"
if [ -n "$OP_SSH_BRIDGE_PATH" ]; then
echo "???? Setting up 1Password SSH bridge from $OP_SSH_BRIDGE_PATH..."
# Copy to writable location
cp "$OP_SSH_BRIDGE_PATH" /tmp/git-tools/op-ssh-bridge
chmod +x /tmp/git-tools/op-ssh-bridge
# Do not configure Git to use the SSH bridge for signing
# since we've disabled commit signing above
echo "??? 1Password SSH bridge available but not used for commit signing"
else
echo "?????? 1Password SSH bridge not found, signing is disabled"
fi
## 5. Fix container-specific file permissions (preserve host compatibility)
echo "🔧 Fixing container-specific permissions..."
# Get current user info
CURRENT_UID=$(id -u)
CURRENT_GID=$(id -g)
CURRENT_USER=$(id -un)
echo "Running as: $CURRENT_USER (UID: $CURRENT_UID, GID: $CURRENT_GID)"
# Only fix permissions for directories that are container-specific
# and won't affect host file access
# Fix Claude directory permissions (mounted from host but needs container access)
if [ -d /home/dev/.claude ]; then
echo "🤖 Setting up Claude Code directory permissions..."
# Only fix ownership of files that are safe to change
if ! find /home/dev/.claude -type d -exec chmod 755 {} \; 2>/dev/null; then
echo "⚠️ Warning: Some Claude directories may have permission issues"
fi
if ! find /home/dev/.claude -name "*.jsonl" -exec chown $CURRENT_UID:$CURRENT_GID {} \; 2>/dev/null; then
echo "⚠️ Warning: Some Claude log files may have permission issues"
fi
mkdir -p /home/dev/.claude/projects 2>/dev/null || true
echo "✅ Claude Code permissions configured"
# Setup Claude CLI from task-master-ai installation
if [ -f /usr/lib/node_modules/task-master-ai/node_modules/.bin/claude ]; then
echo "🔧 Setting up Claude CLI from task-master-ai installation..."
sudo ln -sf /usr/lib/node_modules/task-master-ai/node_modules/.bin/claude /usr/local/bin/claude 2>/dev/null || true
echo "✅ Claude Code CLI configured from global task-master-ai installation"
elif command -v claude >/dev/null 2>&1; then
echo "✅ Claude Code CLI is available globally"
else
echo "⚠️ Claude Code CLI not found, may need container rebuild"
fi
fi
# Fix permissions on any root-owned files in the workspace that shouldn't be
echo "🔧 Fixing workspace file permissions..."
# Only change ownership of files that were created by root and shouldn't be
if [ -w /app ]; then
# Fix common files that get created as root
find /app -name "*.pyc" -user root -exec chown $CURRENT_UID:$CURRENT_GID {} \; 2>/dev/null || true
find /app -name "__pycache__" -user root -exec chown -R $CURRENT_UID:$CURRENT_GID {} \; 2>/dev/null || true
find /app -name ".pytest_cache" -user root -exec chown -R $CURRENT_UID:$CURRENT_GID {} \; 2>/dev/null || true
# Fix any dotfiles that got created as root (but preserve git objects)
find /app -maxdepth 1 -name ".*" -user root ! -path "*/.git/objects*" -exec chown $CURRENT_UID:$CURRENT_GID {} \; 2>/dev/null || true
echo "✅ Workspace permissions fixed"
fi
## 6. Fix profile environment issues
echo "🔧 Setting up shell environment..."
# Create missing environment files to prevent profile errors
mkdir -p /home/dev/.local/bin /home/dev/.cargo
# Create empty env files if they don't exist to prevent profile errors
if [ ! -f /home/dev/.local/bin/env ]; then
touch /home/dev/.local/bin/env
echo "✅ Created empty /home/dev/.local/bin/env"
fi
if [ ! -f /home/dev/.cargo/env ]; then
touch /home/dev/.cargo/env
echo "✅ Created empty /home/dev/.cargo/env"
fi
## 7. Python environment configuration
#echo "???? Setting up Python environment..."
# Set PYTHONPATH to include /app and /app/src if not already set
# This helps avoid circular path references in case PYTHONPATH is already set
if [ -z "$PYTHONPATH" ]; then
export PYTHONPATH="/app:/app/src"
else
# Only add paths if they're not already in PYTHONPATH
if [[ ":$PYTHONPATH:" != *":/app:"* ]]; then
export PYTHONPATH="/app:$PYTHONPATH"
fi
if [[ ":$PYTHONPATH:" != *":/app/src:"* ]]; then
export PYTHONPATH="$PYTHONPATH:/app/src"
fi
fi
echo "???? PYTHONPATH set to: $PYTHONPATH"
## 8. Print configurations and versions for debugging
#echo "???? Current Git configuration:"
git config --list
echo "???? Installed tool versions:"
echo "Node.js: $(node --version 2>/dev/null || echo 'not found')"
echo "npm: $(npm --version 2>/dev/null || echo 'not found')"
echo "uv: $(uv --version 2>/dev/null || echo 'not found')"
echo "Python: $(python3 --version 2>/dev/null || python --version 2>/dev/null || echo 'not found')"
echo "pip: $(pip --version 2>/dev/null || echo 'not found')"
echo "repomix: $(repomix --version 2>/dev/null || echo 'not found')"
echo "langgraph: $(langgraph --version 2>/dev/null || echo 'not found')"
echo "tree: $(tree --version 2>/dev/null || echo 'not found')"
echo "=== ??? Container initialization completed ==="
## 9. Execute the command passed to the container
if [ $# -eq 0 ]; then
# If no arguments are provided, sleep infinity (default behavior)
echo "?????? No command specified, running sleep infinity..."
exec sleep infinity
else
# Otherwise, execute the provided command
echo "?????? Executing command: $@"
exec "$@"
fi