brighthive / master-client-index

BrightHive's Master Client Index framework.
MIT License
2 stars 2 forks source link

Package it #4

Closed reginafcompton closed 5 years ago

reginafcompton commented 5 years ago

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, and cmd.sh refers to wsgi, rather the app name.

Why this? We need to instantiate the database, independent of the app. So, db = SQLAlchemy(app) becomes db = SQLAlchemy() and occurs in the database package itself. Then, in the Flask app, we can initialize a db with migrations and an app context by calling db.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

reginafcompton commented 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!

loganripplinger commented 5 years ago

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.