TravelGraph-AI/docs/DEPLOYMENT_GUIDE.md at main · Hotragn/TravelGraph-AI · GitHub
Skip to content

Latest commit

 

History

History
344 lines (257 loc) · 7.95 KB

DEPLOYMENT_GUIDE.md

File metadata and controls

344 lines (257 loc) · 7.95 KB

Deployment & Setup Guide

🚀 Setting Up TravelGraph-AI on a New Machine

This guide explains how to clone and set up the application on a new computer or deployment environment, including handling private keys and credentials.


📋 Prerequisites

Before starting, ensure you have:

  • Python 3.10 or higher
  • Git installed
  • Access to Neo4j database
  • Access to Snowflake account
  • Your Snowflake RSA private key (from original setup)

🔧 Step-by-Step Setup

1. Clone the Repository

# Clone from GitHub
git clone https://github.com/Hotragn/TravelGraph-AI.git
cd TravelGraph-AI

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

2. Set Up Snowflake Private Key

IMPORTANT: Your Snowflake private key is NOT in the GitHub repository for security reasons.

Option A: Copy from Original Machine (Recommended)

  1. On your original machine, locate your private key:

    C:\Users\hotra\.ssh\rsa_key.p8
    # or wherever you stored it
    
  2. Securely transfer the private key to the new machine:

    • Use a secure method (USB drive, encrypted email, secure file transfer)
    • Never commit this file to Git!
  3. On the new machine, place the key in a secure location:

    # Windows
    mkdir C:\Users\YourUsername\.ssh
    # Copy rsa_key.p8 to this location
    
    # Mac/Linux
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    # Copy rsa_key.p8 to ~/.ssh/
    chmod 600 ~/.ssh/rsa_key.p8

Option B: Generate New Key Pair (Alternative)

If you can't access the original key, generate a new one:

# Windows (PowerShell)
cd config
.\generate_snowflake_keys.ps1

# Mac/Linux
cd config
python generate_keys.py

Then update Snowflake:

  1. Log into Snowflake
  2. Go to your user settings
  3. Update the public key with the new one
  4. Use the new private key in your secrets

3. Create Streamlit Secrets File

Create .streamlit/secrets.toml with your credentials:

# Create .streamlit directory if it doesn't exist
mkdir .streamlit

Create .streamlit/secrets.toml:

# Neo4j Configuration
[neo4j]
uri = "neo4j+s://your-neo4j-instance.databases.neo4j.io"
username = "neo4j"
password = "your-neo4j-password"

# Snowflake Configuration
[snowflake]
account = "your-account.snowflakecomputing.com"
user = "your-username"
warehouse = "COMPUTE_WH"
database = "TRAVEL_DB"
schema = "PUBLIC"
role = "ACCOUNTADMIN"

# Snowflake Private Key Authentication
private_key_path = "C:/Users/YourUsername/.ssh/rsa_key.p8"
# Or for Mac/Linux: "/home/username/.ssh/rsa_key.p8"

# Optional: Private key passphrase (if you set one)
# private_key_passphrase = "your-passphrase"

Security Notes:

  • ✅ .streamlit/secrets.toml is in .gitignore - it won't be pushed to GitHub
  • ✅ Never commit this file
  • ✅ Each team member/deployment needs their own copy

4. Verify Setup

Test your configuration:

# Run the application
streamlit run app.py

If successful, you should see:

  • ✅ Streamlit app starts
  • ✅ No connection errors
  • ✅ Can log in
  • ✅ Pages load correctly

🔐 Security Best Practices

What's in GitHub (Public)

✅ Source code
✅ Documentation
✅ Configuration templates
✅ SQL scripts

What's NOT in GitHub (Private)

❌ .streamlit/secrets.toml - Database credentials
❌ rsa_key.p8 - Snowflake private key
❌ rsa_key.pub - Snowflake public key
❌ .env files - Environment variables
❌ Any passwords or API keys

File Locations

Original Machine:

C:\Users\hotra\.ssh\rsa_key.p8          # Private key
C:\Users\hotra\.ssh\rsa_key.pub         # Public key
Travel Recommend\.streamlit\secrets.toml # Credentials

New Machine (example):

C:\Users\NewUser\.ssh\rsa_key.p8        # Copy private key here
Travel Recommend\.streamlit\secrets.toml # Create new file

🌐 Deployment Scenarios

Scenario 1: Team Member Setup

Team member clones repo:

  1. Clone repository
  2. Get private key from team lead (secure transfer)
  3. Create their own .streamlit/secrets.toml
  4. Use same Snowflake account credentials
  5. Run application

Scenario 2: Production Deployment (Streamlit Cloud)

For Streamlit Cloud deployment:

  1. Push code to GitHub (already done ✅)

  2. In Streamlit Cloud dashboard:

    • Connect to GitHub repository
    • Select TravelGraph-AI
    • Set main file: app.py
  3. Add secrets in Streamlit Cloud:

    • Go to App Settings → Secrets
    • Paste your secrets.toml content
    • For private key: Convert to base64 or use environment variable
  4. Handle Private Key:

    # Option 1: Base64 encode the key
    [snowflake]
    private_key_base64 = "LS0tLS1CRUdJTi..."
    
    # Option 2: Use Streamlit secrets directly
    [snowflake]
    private_key = """
    -----BEGIN PRIVATE KEY-----
    MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC...
    -----END PRIVATE KEY-----
    """
  5. Update connections.py to read from secrets:

    # Read private key from Streamlit secrets
    if 'private_key_base64' in st.secrets['snowflake']:
        import base64
        private_key_bytes = base64.b64decode(
            st.secrets['snowflake']['private_key_base64']
        )
    elif 'private_key' in st.secrets['snowflake']:
        private_key_bytes = st.secrets['snowflake']['private_key'].encode()

Scenario 3: Local Development (Another Computer)

Your laptop → Desktop computer:

  1. Clone repository
  2. Copy .ssh/rsa_key.p8 from laptop to desktop
  3. Create new .streamlit/secrets.toml on desktop
  4. Update private_key_path to match desktop location
  5. Run application

📝 Quick Setup Checklist

For setting up on a new machine:

  • Clone repository from GitHub
  • Create virtual environment
  • Install dependencies (pip install -r requirements.txt)
  • Create .streamlit/ directory
  • Copy or generate Snowflake private key
  • Create .streamlit/secrets.toml with credentials
  • Update private_key_path in secrets.toml
  • Test Neo4j connection
  • Test Snowflake connection
  • Run streamlit run app.py
  • Verify all pages work

🔄 Updating Credentials

If You Need to Change Snowflake Key

  1. Generate new key pair:

    cd config
    python generate_keys.py
  2. Update Snowflake:

    -- In Snowflake, run:
    ALTER USER your_username SET RSA_PUBLIC_KEY='MIIBIjANBg...';
  3. Update secrets.toml:

    private_key_path = "path/to/new/rsa_key.p8"

If You Need to Change Neo4j Password

  1. Update in Neo4j console
  2. Update secrets.toml:
    [neo4j]
    password = "new-password"

🆘 Troubleshooting

Error: "Private key file not found"

Solution: Check private_key_path in secrets.toml matches actual file location

Error: "Invalid private key"

Solution: Ensure you copied the entire key file, including header/footer

Error: "Snowflake authentication failed"

Solution:

  1. Verify public key is set in Snowflake user settings
  2. Check private key matches the public key
  3. Ensure no extra spaces in key file

Error: "Neo4j connection failed"

Solution:

  1. Check URI, username, password in secrets.toml
  2. Verify Neo4j instance is running
  3. Check network connectivity

📧 Getting Help

If you encounter issues:

  1. Check this guide first
  2. Review docs/MANUAL_KEY_SETUP.md
  3. Review docs/SNOWFLAKE_KEYPAIR_SETUP.md
  4. Contact team: Hotragn, Tirdesh, Amantha

🔒 Security Reminders

  1. Never commit secrets to Git
  2. Use secure transfer for private keys (encrypted email, secure USB)
  3. Set proper file permissions on private keys (chmod 600 on Linux/Mac)
  4. Rotate keys periodically for production environments
  5. Use different credentials for dev/staging/production

Last Updated: December 2024
Version: 1.0.0