diff --git a/.github/workflows/prod.yaml b/.github/workflows/prod.yaml new file mode 100644 index 0000000..5dc820d --- /dev/null +++ b/.github/workflows/prod.yaml @@ -0,0 +1,48 @@ +name: Deploy to Modal Production + +on: + push: + branches: + - main + pull_request: + types: [closed] + branches: + - main + +jobs: + deploy: + if: github.event.pull_request.merged == true || github.event_name == 'push' + runs-on: ubuntu-latest + env: + DB: PROD + + steps: + - name: Checkout main repo + uses: actions/checkout@v4 + + - name: Checkout workflows repo + uses: actions/checkout@v4 + with: + repository: edenartlab/workflows + path: workflows + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Rye + run: | + curl -sSf https://rye-up.com/get | bash + echo "$HOME/.rye/shims" >> $GITHUB_PATH + + - name: Install dependencies + run: rye sync + + - name: Configure Modal token + run: | + echo "${{ secrets.MODAL_TOKEN_ID }}" > ~/.modal/token-id + echo "${{ secrets.MODAL_TOKEN_SECRET }}" > ~/.modal/token-secret + + - name: Deploy to Modal + run: rye run modal deploy ./eve/api.py diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml new file mode 100644 index 0000000..f4bcf52 --- /dev/null +++ b/.github/workflows/staging.yaml @@ -0,0 +1,48 @@ +name: Deploy to Modal Staging + +on: + push: + branches: + - staging + pull_request: + types: [closed] + branches: + - staging + +jobs: + deploy: + if: github.event.pull_request.merged == true || github.event_name == 'push' + runs-on: ubuntu-latest + env: + DB: STAGE + + steps: + - name: Checkout main repo + uses: actions/checkout@v4 + + - name: Checkout workflows repo + uses: actions/checkout@v4 + with: + repository: edenartlab/workflows + path: workflows + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install Rye + run: | + curl -sSf https://rye-up.com/get | bash + echo "$HOME/.rye/shims" >> $GITHUB_PATH + + - name: Install dependencies + run: rye sync + + - name: Configure Modal token + run: | + echo "${{ secrets.MODAL_TOKEN_ID }}" > ~/.modal/token-id + echo "${{ secrets.MODAL_TOKEN_SECRET }}" > ~/.modal/token-secret + + - name: Deploy to Modal + run: rye run modal deploy ./eve/api.py diff --git a/eve/__init__.py b/eve/__init__.py index 6c035e2..933a064 100644 --- a/eve/__init__.py +++ b/eve/__init__.py @@ -5,14 +5,19 @@ import os home_dir = str(Path.home()) - -# Load env variables from ~/.eve if it exists eve_path = os.path.join(home_dir, ".eve") +env_path = ".env" + +# First try ENV_PATH from environment +env_path_override = os.getenv("ENV_PATH") +if env_path_override and os.path.exists(env_path_override): + load_dotenv(env_path_override) + +# Then try ~/.eve if os.path.exists(eve_path): - load_dotenv(eve_path) + load_dotenv(eve_path, override=True) -# Load env variables from .env file if it exists -env_path = ".env" +# Finally fall back to .env if os.path.exists(env_path): load_dotenv(env_path, override=True) diff --git a/eve/tools/twitter/__init__.py b/eve/tools/twitter/__init__.py index 533d9ab..be2f70b 100644 --- a/eve/tools/twitter/__init__.py +++ b/eve/tools/twitter/__init__.py @@ -1,7 +1,6 @@ import time import logging import requests -from dotenv import load_dotenv from requests_oauthlib import OAuth1Session from ...agent import Agent diff --git a/eve/tools/twitter/tweet/handler.py b/eve/tools/twitter/tweet/handler.py index 3b8c5b5..8f901a4 100644 --- a/eve/tools/twitter/tweet/handler.py +++ b/eve/tools/twitter/tweet/handler.py @@ -1,13 +1,4 @@ -import os -import argparse -import re -import time -import logging -import requests -from dotenv import load_dotenv -from requests_oauthlib import OAuth1Session -from .... import eden_utils from ....agent import Agent from .. import X diff --git a/eve/tools/wallet/send_eth/handler.py b/eve/tools/wallet/send_eth/handler.py index 7f68cfc..7a9a966 100644 --- a/eve/tools/wallet/send_eth/handler.py +++ b/eve/tools/wallet/send_eth/handler.py @@ -1,6 +1,5 @@ import os from web3 import Web3 -from dotenv import load_dotenv async def handler(args: dict, db: str): diff --git a/scripts/test_pubsub.py b/scripts/test_pubsub.py deleted file mode 100644 index 61cd542..0000000 --- a/scripts/test_pubsub.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -import argparse -from ably import AblyRealtime -import asyncio -import time -from dotenv import load_dotenv - -load_dotenv() - - -async def publish_test_messages(channel_name: str): - # Initialize Ably with publisher key - client = AblyRealtime(os.getenv("ABLY_PUBLISHER_KEY")) - channel = client.channels.get(channel_name) - - try: - # Publish a few test messages - for i in range(5): - data = { - "type": "test", - "message": f"Test message {i}", - "timestamp": time.time(), - } - await channel.publish("update", data) - print(f"Published message {i} to channel {channel_name}") - await asyncio.sleep(2) # Wait 2 seconds between messages - - finally: - client.close() - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("channel", help="Channel name to publish to") - args = parser.parse_args() - - asyncio.run(publish_test_messages(args.channel))