Skip to content

Commit

Permalink
add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
richardr1126 committed Dec 12, 2024
1 parent 3b4cb79 commit 05dcc1c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
```
Expand Down
4 changes: 1 addition & 3 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
PASSWORD="your-password"
8 changes: 3 additions & 5 deletions firehose/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
3 changes: 1 addition & 2 deletions web/database_ro.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down

0 comments on commit 05dcc1c

Please sign in to comment.