Skip to content
Snippets Groups Projects
Commit 10446740 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Dockerize the App!

parent b34b46ae
Branches
Tags
No related merge requests found
### Flask ###
FLASK_APP=opaque.py
data_dev.sqlite
migrations
venv
.env
.env_database
opaque_database_env
opaque_env
__pycache__
FROM python:3.6-alpine
RUN apk add build-base
RUN apk add \
build-base \
postgresql-dev
RUN adduser -D opaque
......@@ -13,10 +15,13 @@ WORKDIR /home/opaque
COPY app app
COPY migrations migrations
COPY opaque.py config.py ./
COPY config.py opaque.py ./
COPY requirements.txt requirements.txt
ENV FLASK_APP=opaque.py
RUN python -m venv venv && \
venv/bin/pip install -r requirements.txt
......
......@@ -28,32 +28,33 @@ class Config:
class DevelopmentConfig(Config):
''' ### Flask ### '''
DEBUG = True
# SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir,
# 'data_dev.sqlite')
SQLALCHEMY_DATABASE_URI = \
'postgresql+psycopg2://{user}:{passwd}@{host}:{port}/{db}'.format(
user=os.environ.get('POSTGRES_USER'),
passwd=os.environ.get('POSTGRES_PASSWORD'),
host=os.environ.get('POSTGRES_HOST'),
port=os.environ.get('POSTGRES_PORT'),
db=os.environ.get('POSTGRES_DB_NAME'))
print(SQLALCHEMY_DATABASE_URI)
''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format(
os.path.join(os.path.dirname(os.path.abspath(__file__)),
'data_dev.sqlite')
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@opaque_database/{}'.format(
os.environ.get('POSTGRES_USER'),
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME')
)
class TestingConfig(Config):
''' ### Flask ### '''
TESTING = True
''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = 'sqlite://'
''' ### Flask-WTF ### '''
WTF_CSRF_ENABLED = False
class ProductionConfig(Config):
''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = os.environ.get('SQLALCHEMY_DATABASE_URI')
SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@opaque_database/{}'.format(
os.environ.get('POSTGRES_USER'),
os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME')
)
config = {
......
#!/bin/bash
#!/bin/sh
# If no argument is given, start Opaque
if [ $# -eq 0 ]
then
# If no argument is given, start Opaque
venv/bin/python opaque.py
else
if [[ $1 == "--create-db" ]]
then
source venv/bin/activate
flask db init
flask db upgrade
flask foo
fi
fi
......@@ -28,5 +28,10 @@ def test():
unittest.TextTestRunner(verbosity=2).run(tests)
@app.cli.command()
def foo():
Role.insert_roles()
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0')
POSTGRES_DB_NAME=opaque
POSTGRES_USER=opaque
POSTGRES_PASSWORD=opaque
......@@ -12,6 +12,3 @@ MAIL_DEFAULT_SENDER=username@example.com
### Opaque ###
OPAQUE_ADMIN=admin.opaque@example.com
### Flask-SQLAlchemy ###
# SQLALCHEMY_DATABASE_URI=
......@@ -8,4 +8,5 @@ Flask-SQLAlchemy
Flask-Table
Flask-WTF
jsonpatch
psycopg2
redis
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment