Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*pip-selfcheck.json
*Python
*__pycache__/
chat-env
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.9
WORKDIR /app
COPY app.py /app/

COPY requirements.txt /app/
RUN pip install -r requirements.txt

CMD cd /app/ && gunicorn --worker-class=gevent -b 0.0.0.0:8000 -t 99999 app:app
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
- [Chat](#chat)
- [Installation](#installation)
- [Running the app](#running-the-app)
- [Container based](#container-based)
- [Dev way](#dev-way)

# Chat
A primitive chat app created to experiment with Flask, Redis, Gevent & Server-Sent Events.

## installation
## Installation
pip install flask redis gevent gunicorn

## running the app
## Running the app
### Container based
docker-compose up
### Dev way
start the redis server
redis-server
gunicorn --debug --worker-class=gevent -t 99999 app:app
REDIS_SERVER_NAME=localhost gunicorn --debug --worker-class=gevent -t 99999 app:app

8 changes: 5 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import flask
import redis

import os

app = flask.Flask(__name__)
app.secret_key = 'asdf'
red = redis.StrictRedis()

app.secret_key = 'docker-powered-chat'
red = redis.StrictRedis(host=os.environ["REDIS_SERVER_NAME"])
print("Connected servers so far", red.get("CONNECTED_SERVERS"))
red.incr("CONNECTED_SERVERS")

def event_stream():
pubsub = red.pubsub()
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '2'

services:
chat_web:
image: redis_chat:0.0.1
build:
context: .
ports:
- 8000:8000
depends_on:
- chat_redis_server
environment:
- REDIS_SERVER_NAME=chat_redis_server
chat_redis_server:
image: redis:5
ports:
- 6379:6379
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
click==7.1.2
Flask==1.1.2
gevent==20.12.1
greenlet==1.0.0
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
redis==3.5.3
Werkzeug==1.0.1
zope.event==4.5.0
zope.interface==5.2.0