source setup.envSets environment variablesmakeSets up VEsource ve/bin/activateSource the VEdocker-compose up --build -dBuild the images- Check
localhost 5000 - Upload
test_input.csv - Query
http://localhost:5000/apior checkhttp://localhost:5000/api/people/1to see the input.
To run tests: - make _tests
To start local dev sever:
- source setup.env Sets environment variables
- make Sets up VE
- source ve/bin/activate Source the VE
- python3 run.py You should change the config setting to testing and will
need to change to your local PostgreSQL in routes.py etc.
To start wsgi sever:
- gunicorn -b 0.0.0.0:5000 wsgi:app instead of run.py
Now to migrate, follow this syntax.
docker exec <container-name/id of app> python3 manage.py db migrate <command>
Run these 3 commands:
python3 manage.py db initpython3 manage.py db migratepython3 manage.py db upgrade
Insert test data locally.
docker exec <container-name/id of app> bashcd flask_rest_psql_docker/databasepython3 insert_to_psql.py(Make sure your host machine's psql is off.)
Useful Docker commands:
Check ENVVARS
docker exec -ti <image_id> env | sort
CHECK HOSTS
docker exec -ti <image_id> cat "/etc/hosts"
Kill all containers
docker stop $(docker ps -aq)
https://www.youtube.com/watch?v=aHbE3pTyG-Q
docker exec -it <image_id> psql testdb -U postgres test
psql commands:
\dtShow relations\lList of databases\qQuit
- flask-script/flask-migrate : for DB migrations
- flask-restplus : swagger/api
- flask-marshmallow : serialization (needs marshmallow-sqlalchemy)
- flask-sqlalchemy : db/ORM (needs psycopg2 for psql)
- Better CircleCI testing not just make. (Create actual unit tests)
- Cookiecutter functionality?
- Rename variables and project name to something more descriptive.
- When files are added you can delete the .gitignores in the empty folders. I didn't want to make an additional make target just to create empty directories upon initial pull.