diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a5fde3c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.12.8-slim-bookworm + +# create a volume for the sqlite database, so that it persists between container restarts +# need persistent storage attached to server +VOLUME /var/data/ +WORKDIR /usr/src/app + +# Copy package files and install dependencies +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code +COPY . . +EXPOSE 8000 + +# Runs when the container is started +CMD honcho start diff --git a/README.md b/README.md index f1165ab..58d4770 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Cosmere ATProto Feed Generator Flask Server +![Docker](https://img.shields.io/docker/image-size/richardr1126/cosmere-feed-bsky/latest) ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg) ![Python Version](https://img.shields.io/badge/Python-3.7%2B-blue.svg) ![Flask](https://img.shields.io/badge/Flask-2.3.2-blue.svg) @@ -79,7 +80,7 @@ To create your own feed, install dependencies, configure environment variables, 1. **Update files:** - Update `publish_feed.py` with your details. **(REQUIRED)** - Modify filters in `firehose/data_filter.py`. **(OPTIONAL)** - - Change database routes in `firehose/database.py` and `web/database_ro.py`. **(REQUIRED for production)** + - Change database names/routes in `firehose/database.py` and `web/database_ro.py`. **(REQUIRED)** - Change `DID_TO_PRIORITIZE` in `algos/chrono_trending.py` with a bsky DID which will show it's posts at the top of the feed **(REQUIRED)** > **Note:** Because current DB folder for production `/var/data` might not be accessible in your environment. @@ -99,6 +100,13 @@ To update your feed's display data, modify the relevant variables and rerun the The server operates two main processes: the web server and the firehose data stream. Use `honcho` to manage these processes as defined in the `Procfile`: +Build and run Docker image: +```shell +docker build -t myfeed . +docker run --rm -it -p 8000:8000 -v feeddata:/var/data/ myfeed +``` + +Manually run the server: ```shell honcho start ``` diff --git a/example.env b/example.env index a021a11..cf26d14 100644 --- a/example.env +++ b/example.env @@ -10,6 +10,4 @@ CHRONOLOGICAL_TRENDING_URI="at://did:plc:abcde..." # YOUR bluesky password, or preferably an App Password (found in your client settings) HANDLE="your-handle" -PASSWORD="your-password" - -DEV_MODE="true" \ No newline at end of file +PASSWORD="your-password" \ No newline at end of file diff --git a/firehose/database.py b/firehose/database.py index 8c44147..d4104b7 100644 --- a/firehose/database.py +++ b/firehose/database.py @@ -2,25 +2,23 @@ from typing import Optional import logging import shutil -import signal -import sys from utils.logger import logger # Ensure this is correctly implemented -from utils.config import DEV_MODE, HANDLE, PASSWORD # Ensure these are set in your config +from utils.config import HANDLE, PASSWORD # Ensure these are set in your config import peewee from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.jobstores.base import JobLookupError from apscheduler.triggers.date import DateTrigger from apscheduler.triggers.interval import IntervalTrigger from apscheduler.events import EVENT_JOB_EXECUTED, EVENT_JOB_ERROR -from atproto import Client, IdResolver, SessionEvent, Session, exceptions +from atproto import Client, SessionEvent, Session, exceptions # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Database setup -file = '/var/data/new_cosmere_feed.db' if not DEV_MODE else 'new_cosmere_feed.db' +file = '/var/data/new_cosmere_feed.db' db = peewee.SqliteDatabase(file, timeout=60, pragmas={ 'journal_mode': 'wal', 'cache_size': -1024 * 256, diff --git a/utils/config.py b/utils/config.py index a688565..07b5900 100644 --- a/utils/config.py +++ b/utils/config.py @@ -4,7 +4,6 @@ HOSTNAME = os.environ.get('HOSTNAME', None) HANDLE = os.environ.get('HANDLE', None) PASSWORD = os.environ.get('PASSWORD', None) -DEV_MODE = os.environ.get('DEV_MODE', 'false').lower() == 'true' if HOSTNAME is None: raise RuntimeError('You should set "HOSTNAME" environment variable first.') diff --git a/web/database_ro.py b/web/database_ro.py index b69b709..bd11e47 100644 --- a/web/database_ro.py +++ b/web/database_ro.py @@ -1,9 +1,8 @@ from datetime import datetime, timedelta, timezone from utils.logger import logger -from utils.config import DEV_MODE import peewee -file = 'file:/var/data/new_cosmere_feed.db?mode=ro' if not DEV_MODE else 'file:./new_cosmere_feed.db?mode=ro' +file = 'file:/var/data/new_cosmere_feed.db?mode=ro' # Configure the read-only SQLite database connection using URI db = peewee.SqliteDatabase(