Closed reginafcompton closed 5 years ago
@loganripplinger - can you pull down these changes, and let me know if you can build an image and launch a container? See the README: https://github.com/brighthive/master-client-index#docker
Other thoughts welcome, too!
By following along with the README: https://github.com/brighthive/master-client-index#docker I was able to run the two provided commands just fine and able to test that the page works by going to the provided URL.
This PR provides some of the re-scaffolding needed to decouple the db from the app and to use the packaged db.
It cooperates with https://github.com/brighthive/mci-database.
Decoupling
I moved the creation of the app inside a function.
wsgi.py
calls this function, andcmd.sh
refers towsgi
, rather the app name.Why this? We need to instantiate the database, independent of the app. So,
db = SQLAlchemy(app)
becomesdb = SQLAlchemy()
and occurs in the database package itself. Then, in the Flask app, we can initialize adb
with migrations and an app context by callingdb.init_db(app)
.I like this pattern, and it follows the factory pattern described in the Flask docs.
Docker adjustments
I had to explicitly assign a user to the psql container. I left a long explanatory note about it. Seems odd, no?
Resource: https://stackoverflow.com/questions/33126391/share-sqlalchemy-models-between-flask-and-other-apps/33127999#33127999