containerize this thing

This commit is contained in:
Morgan McMillian 2020-01-28 22:05:49 -08:00
parent b77e105d5c
commit 0fc4482bdf
5 changed files with 61 additions and 9 deletions

11
.dockerignore Normal file
View file

@ -0,0 +1,11 @@
__pycache__/
*.py[cod]
*.yaml
*.db
*.sublime-project
*.sublime-workspace
.vscode/
.git/
.gitignore
Dockerfile
.dockerignore

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
FROM python:alpine3.7
VOLUME /data
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
WORKDIR /data
CMD [ "python", "/usr/src/app/partybot-pnut.py", "-d", "-c", "config.yaml" ]

View file

@ -1,5 +1,7 @@
from sqlalchemy import Column, ForeignKey, Integer, String, Boolean from sqlalchemy import Column, ForeignKey, Integer, String, Boolean
from database import Base from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Optout(Base): class Optout(Base):
__tablename__ = 'optout' __tablename__ = 'optout'

View file

@ -8,10 +8,13 @@ import time
import json import json
import random import random
import re import re
import argparse
from database import db_session, init_db # from database import db_session, init_db
from sqlalchemy import and_ from sqlalchemy import create_engine, and_
from models import Karma, Optout, Queue, Preferences, MdnpRequests from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from models import Base, Karma, Optout, Queue, Preferences, MdnpRequests
_startup = threading.Event() _startup = threading.Event()
_shutdown = threading.Event() _shutdown = threading.Event()
@ -348,12 +351,29 @@ def on_open(ws):
if __name__ == "__main__": if __name__ == "__main__":
logger = logging.getLogger() logger = logging.getLogger()
logging.basicConfig(level=logging.DEBUG) a_parser = argparse.ArgumentParser()
a_parser.add_argument(
'-d', action='store_true', dest='debug',
help="debug logging"
)
a_parser.add_argument(
'-c', '--config', default="config.yaml",
help="configuration file"
)
args = a_parser.parse_args()
with open("config.yaml", "rb") as config_file: if args.debug:
config = yaml.load(config_file) logging.basicConfig(level=logging.DEBUG)
else:
init_db() logging.basicConfig(level=logging.INFO)
with open(args.config, 'rb') as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)
engine = create_engine(config['SERVICE_DB'])
db_session = scoped_session(sessionmaker(bind=engine))
Base.query = db_session.query_property()
Base.metadata.create_all(bind=engine)
pnutpy.api.add_authorization_token(config['ACCESS_TOKEN']) pnutpy.api.add_authorization_token(config['ACCESS_TOKEN'])

5
requirements.txt Normal file
View file

@ -0,0 +1,5 @@
PyYAML
pnutpy
requests
SQLAlchemy
websocket-client