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
venv
.env
.env_database
opaque_database_env
opaque_env
__pycache__

View File

@ -1,7 +1,9 @@
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

View File

@ -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 = {

View File

@ -1,13 +1,15 @@
#!/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

View File

@ -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')

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_ADMIN=admin.opaque@example.com
### Flask-SQLAlchemy ###
# SQLALCHEMY_DATABASE_URI=

View File

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