Skip to content

Commit

Permalink
Lots of prod fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hndrewaall committed May 2, 2020
1 parent 968a42a commit e2eb3c6
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 39 deletions.
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
FROM tiangolo/uwsgi-nginx-flask:python3.7
FROM python:3.7.7-stretch

COPY ./app /app
COPY uwsgi.ini /app/
ADD requirements.txt .
CMD ["./start.sh"]
WORKDIR /app

RUN apt-get update && apt-get install -y libpq-dev

RUN pip install --upgrade pip && pip install -r requirements.txt
ADD start.sh .

ADD requirements ./requirements
RUN pip install --upgrade pip && pip install -r requirements/prod.txt

COPY ./app /app
4 changes: 2 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class DevelopmentConfig(Config):
class ProductionConfig(Config):
# These URIs are the same for now. If we ever introduce tests we'll want to have
# a test config that has its own db that doesn't interfere with these.
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'db.sqlite')
SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://waa:woo@jitsi-party-db:5432/jitsi'
# We use multiple workers in production, so we need a message queue to coordinate
# websocket broadcasting
MESSAGE_QUEUE = 'amqp://'
MESSAGE_QUEUE = None

config = {
'development': DevelopmentConfig,
Expand Down
5 changes: 4 additions & 1 deletion app/jitsi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
staticdir = os.path.join(basedir, 'client/js')

db = SQLAlchemy()
socketio = SocketIO()
socketio = SocketIO(async_mode="eventlet")

# Register socket events with SocketIO instance
from . import events
Expand All @@ -35,3 +35,6 @@ def create_app(config_name):
socketio.init_app(app, cors_allowed_origins='*', message_queue=queue)

return app

def run_prod(app):
socketio.run(app, host='0.0.0.0', port=80)
6 changes: 5 additions & 1 deletion app/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import json
from jitsi import create_app, db
from jitsi import create_app, db, run_prod
from jitsi.models import Room, User

# Create the application context
Expand All @@ -16,6 +16,10 @@ def make_shell_context():
return dict(db=db, Room=Room, User=User)


@app.cli.command('run-prod')
def run_prod_cmd():
run_prod(app)

@app.cli.command('create-db')
def create_db():
'''Usage: flask create-db
Expand Down
2 changes: 0 additions & 2 deletions app/prestart.sh

This file was deleted.

24 changes: 24 additions & 0 deletions build_head.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash


SCRIPT=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "$SCRIPT")

pushd "$SCRIPT_DIR"

DOCKER_REPO="localhost:5000/gbre/jitsi-party"

QUERY='{ repository(owner: \"morganecf\", name: \"jitsi-party\") { releases(last: 1, orderBy: {field: CREATED_AT, direction: ASC}) {edges { node { tagName }}}}}'

pushd app/client

npm install
node_modules/.bin/webpack
rm -rf node_modules

popd

docker build . --tag "$DOCKER_REPO":latest
docker push "$DOCKER_REPO":latest

popd
File renamed without changes.
20 changes: 1 addition & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
click==7.1.2
dnspython==1.16.0
eventlet==0.25.2
Flask==1.1.1
Flask-Cors==3.0.8
Flask-SocketIO==4.3.0
Flask-SQLAlchemy==2.4.1
greenlet==0.4.15
itsdangerous==1.1.0
Jinja2==2.11.2
kombu==4.6.8
MarkupSafe==1.1.1
monotonic==1.5
python-engineio==3.12.1
python-socketio==4.5.1
six==1.14.0
SQLAlchemy==1.3.15
SQLAlchemy-serializer==1.3.4.2
Werkzeug==1.0.1
-r requirements/dev.txt
18 changes: 18 additions & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
click==7.1.2
dnspython==1.16.0
eventlet==0.25.2
Flask==1.1.1
Flask-Cors==3.0.8
Flask-SocketIO==4.3.0
Flask-SQLAlchemy==2.4.1
itsdangerous==1.1.0
Jinja2==2.11.2
kombu==4.6.8
MarkupSafe==1.1.1
monotonic==1.5
python-engineio==3.12.1
python-socketio==4.5.1
six==1.14.0
SQLAlchemy==1.3.15
SQLAlchemy-serializer==1.3.4.2
Werkzeug==1.0.1
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-r common.txt
2 changes: 2 additions & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r common.txt
psycopg2==2.8.0
5 changes: 1 addition & 4 deletions app/start.sh → start.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#! /bin/bash

pushd /app

rm db.sqlite
source setup_prod.sh
flask create-db
FLASK_DEBUG=1 PYTHONUNBUFFERED=1 flask run-prod

popd
5 changes: 0 additions & 5 deletions uwsgi.ini

This file was deleted.

0 comments on commit e2eb3c6

Please sign in to comment.