mirror of
https://github.com/aljazceru/IngestRSS.git
synced 2025-12-18 14:34:26 +01:00
Merge pull request #7 from aljazceru/codex/add-local-deployment-option-to-launch.py
Add local launch option and env template
This commit is contained in:
84
launch.py
84
launch.py
@@ -4,17 +4,65 @@ import json
|
|||||||
import boto3
|
import boto3
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import logging
|
import logging
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
from src.infra.lambdas.RSSQueueFiller.deploy_sqs_filler_lambda import deploy_sqs_filler
|
from src.infra.lambdas.RSSQueueFiller.deploy_sqs_filler_lambda import deploy_sqs_filler
|
||||||
|
|
||||||
from src.utils.check_env import check_env
|
from src.utils.check_env import check_env
|
||||||
|
|
||||||
|
|
||||||
|
def check_local_env() -> None:
|
||||||
|
"""Ensure required environment variables for local mode are set."""
|
||||||
|
required_vars = [
|
||||||
|
"MONGODB_URL",
|
||||||
|
"MONGODB_DB_NAME",
|
||||||
|
"MONGODB_COLLECTION_NAME",
|
||||||
|
"REDIS_URL",
|
||||||
|
"REDIS_QUEUE_NAME",
|
||||||
|
"MINIO_ENDPOINT",
|
||||||
|
"MINIO_ACCESS_KEY",
|
||||||
|
"MINIO_SECRET_KEY",
|
||||||
|
"MINIO_BUCKET",
|
||||||
|
]
|
||||||
|
|
||||||
|
missing = [var for var in required_vars if not os.getenv(var)]
|
||||||
|
if missing:
|
||||||
|
raise EnvironmentError(
|
||||||
|
f"Missing required environment variables for local mode: {', '.join(missing)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def start_docker_containers() -> None:
|
||||||
|
"""Start required Docker containers for local development."""
|
||||||
|
try:
|
||||||
|
subprocess.check_call(["docker-compose", "up", "-d"])
|
||||||
|
except FileNotFoundError:
|
||||||
|
# fallback to `docker compose` if docker-compose command not found
|
||||||
|
subprocess.check_call(["docker", "compose", "up", "-d"])
|
||||||
|
except Exception as exc:
|
||||||
|
logging.error(f"Failed to start Docker containers: {exc}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
print("🗞️ 💵 ⚖️ IngestRSS⚖️ 💵 🗞️".center(100, "-"))
|
print("🗞️ 💵 ⚖️ IngestRSS⚖️ 💵 🗞️".center(100, "-"))
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Launch IngestRSS")
|
||||||
|
parser.add_argument(
|
||||||
|
"--local",
|
||||||
|
action="store_true",
|
||||||
|
help="Run locally using Docker instead of deploying to AWS",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
load_dotenv(override=True)
|
load_dotenv(override=True)
|
||||||
check_env()
|
|
||||||
|
if args.local:
|
||||||
|
check_local_env()
|
||||||
|
else:
|
||||||
|
check_env()
|
||||||
|
|
||||||
# Set up logging
|
# Set up logging
|
||||||
logging.basicConfig(level=os.getenv('LOG_LEVEL'))
|
logging.basicConfig(level=os.getenv("LOG_LEVEL"))
|
||||||
|
|
||||||
lambda_client = boto3.client("lambda")
|
lambda_client = boto3.client("lambda")
|
||||||
|
|
||||||
@@ -27,21 +75,25 @@ from src.infra.lambdas.RSSFeedProcessorLambda.deploy_rss_feed_lambda import depl
|
|||||||
from src.infra.lambdas.lambda_utils.update_lambda_env_vars import update_env_vars
|
from src.infra.lambdas.lambda_utils.update_lambda_env_vars import update_env_vars
|
||||||
from src.feed_management.upload_rss_feeds import upload_rss_feeds
|
from src.feed_management.upload_rss_feeds import upload_rss_feeds
|
||||||
|
|
||||||
def main():
|
|
||||||
# Deploy infrastructure
|
|
||||||
deploy_infrastructure()
|
|
||||||
logging.info("Finished Deploying Infrastructure")
|
|
||||||
|
|
||||||
# Deploy Lambda function
|
|
||||||
deploy_lambda()
|
|
||||||
logging.info("Finished Deploying Lambda")
|
|
||||||
|
|
||||||
deploy_sqs_filler()
|
def main(local: bool = False) -> None:
|
||||||
logging.info("Finished Deploying Queue Filler Lambda")
|
if local:
|
||||||
|
start_docker_containers()
|
||||||
|
else:
|
||||||
|
# Deploy infrastructure
|
||||||
|
deploy_infrastructure()
|
||||||
|
logging.info("Finished Deploying Infrastructure")
|
||||||
|
|
||||||
# Update Lambda environment variables
|
# Deploy Lambda function
|
||||||
update_env_vars(os.getenv("LAMBDA_FUNCTION_NAME"))
|
deploy_lambda()
|
||||||
print("Finished Environment Variable Updates")
|
logging.info("Finished Deploying Lambda")
|
||||||
|
|
||||||
|
deploy_sqs_filler()
|
||||||
|
logging.info("Finished Deploying Queue Filler Lambda")
|
||||||
|
|
||||||
|
# Update Lambda environment variables
|
||||||
|
update_env_vars(os.getenv("LAMBDA_FUNCTION_NAME"))
|
||||||
|
print("Finished Environment Variable Updates")
|
||||||
|
|
||||||
# Upload RSS feeds
|
# Upload RSS feeds
|
||||||
rss_feeds_file = os.path.join(current_dir, "rss_feeds.json")
|
rss_feeds_file = os.path.join(current_dir, "rss_feeds.json")
|
||||||
@@ -61,4 +113,4 @@ def main():
|
|||||||
print("RSS Feed Processor launched successfully!")
|
print("RSS Feed Processor launched successfully!")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main(args.local)
|
||||||
|
|||||||
25
local.env.template
Normal file
25
local.env.template
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Local environment configuration for IngestRSS
|
||||||
|
|
||||||
|
# Redis configuration
|
||||||
|
REDIS_URL=redis://localhost:6379
|
||||||
|
REDIS_QUEUE_NAME=rss-feed-queue
|
||||||
|
|
||||||
|
# MinIO configuration
|
||||||
|
MINIO_ENDPOINT=***
|
||||||
|
MINIO_ACCESS_KEY=***
|
||||||
|
MINIO_SECRET_KEY=***
|
||||||
|
MINIO_BUCKET=***
|
||||||
|
|
||||||
|
# MongoDB settings
|
||||||
|
MONGODB_URL=mongodb://localhost:27017
|
||||||
|
MONGODB_DB_NAME=ingestrss
|
||||||
|
MONGODB_COLLECTION_NAME=rss_feeds
|
||||||
|
|
||||||
|
# Logging Configuration
|
||||||
|
LOG_LEVEL=INFO
|
||||||
|
|
||||||
|
# Other Application Settings
|
||||||
|
APP_NAME=RSS Feed Processor
|
||||||
|
VERSION=1.0.0
|
||||||
|
|
||||||
|
STORAGE_STRATEGY=s3
|
||||||
Reference in New Issue
Block a user