Dockerize the App!

This commit is contained in:
Patrick Jentsch 2019-09-05 16:39:50 +02:00
parent b34b46ae5d
commit 1044674074
9 changed files with 37 additions and 27 deletions

View File

@ -1,2 +0,0 @@
### Flask ###
FLASK_APP=opaque.py

6
.gitignore vendored
View File

@ -1,6 +1,4 @@
data_dev.sqlite
migrations migrations
venv opaque_database_env
.env opaque_env
.env_database
__pycache__ __pycache__

View File

@ -1,7 +1,9 @@
FROM python:3.6-alpine FROM python:3.6-alpine
RUN apk add build-base RUN apk add \
build-base \
postgresql-dev
RUN adduser -D opaque RUN adduser -D opaque
@ -13,10 +15,13 @@ WORKDIR /home/opaque
COPY app app COPY app app
COPY migrations migrations COPY migrations migrations
COPY opaque.py config.py ./ COPY config.py opaque.py ./
COPY requirements.txt requirements.txt COPY requirements.txt requirements.txt
ENV FLASK_APP=opaque.py
RUN python -m venv venv && \ RUN python -m venv venv && \
venv/bin/pip install -r requirements.txt venv/bin/pip install -r requirements.txt

View File

@ -28,32 +28,33 @@ class Config:
class DevelopmentConfig(Config): class DevelopmentConfig(Config):
''' ### Flask ### ''' ''' ### Flask ### '''
DEBUG = True 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 ### ''' ''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = 'sqlite:///{}'.format( SQLALCHEMY_DATABASE_URI = 'postgresql://{}:{}@opaque_database/{}'.format(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.environ.get('POSTGRES_USER'),
'data_dev.sqlite') os.environ.get('POSTGRES_PASSWORD'),
os.environ.get('POSTGRES_DB_NAME')
) )
class TestingConfig(Config): class TestingConfig(Config):
''' ### Flask ### '''
TESTING = True
''' ### Flask-SQLAlchemy ### ''' ''' ### Flask-SQLAlchemy ### '''
SQLALCHEMY_DATABASE_URI = 'sqlite://' SQLALCHEMY_DATABASE_URI = 'sqlite://'
''' ### Flask-WTF ### '''
WTF_CSRF_ENABLED = False
class ProductionConfig(Config): class ProductionConfig(Config):
''' ### Flask-SQLAlchemy ### ''' ''' ### 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 = { config = {

View File

@ -1,13 +1,15 @@
#!/bin/bash #!/bin/sh
# If no argument is given, start Opaque
if [ $# -eq 0 ] if [ $# -eq 0 ]
then then
# If no argument is given, start Opaque
venv/bin/python opaque.py venv/bin/python opaque.py
else else
if [[ $1 == "--create-db" ]] if [[ $1 == "--create-db" ]]
then then
source venv/bin/activate
flask db init flask db init
flask db upgrade flask db upgrade
flask foo
fi fi
fi fi

View File

@ -28,5 +28,10 @@ def test():
unittest.TextTestRunner(verbosity=2).run(tests) unittest.TextTestRunner(verbosity=2).run(tests)
@app.cli.command()
def foo():
Role.insert_roles()
if __name__ == '__main__': if __name__ == '__main__':
socketio.run(app, host='0.0.0.0') socketio.run(app, host='0.0.0.0')

View File

@ -0,0 +1,3 @@
POSTGRES_DB_NAME=opaque
POSTGRES_USER=opaque
POSTGRES_PASSWORD=opaque

View File

@ -12,6 +12,3 @@ MAIL_DEFAULT_SENDER=username@example.com
### Opaque ### ### Opaque ###
OPAQUE_ADMIN=admin.opaque@example.com OPAQUE_ADMIN=admin.opaque@example.com
### Flask-SQLAlchemy ###
# SQLALCHEMY_DATABASE_URI=

View File

@ -8,4 +8,5 @@ Flask-SQLAlchemy
Flask-Table Flask-Table
Flask-WTF Flask-WTF
jsonpatch jsonpatch
psycopg2
redis redis