PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://gitlab.com/bplatta/proto-api
Markdown | 106 lines | 82 code | 24 blank | 0 comment | 0 complexity | 4606f4f8d13dc747cf0ee822e9b5197e MD5 | raw file
  1. # Prototyping API - 0.1
  2. The proto-api is a django rest API built for easy prototyping of restful collections
  3. #### Versioning: x.y.z
  4. x - major release;
  5. y - minor release;
  6. z - build number
  7. #### Project Dependencies
  8. - [docker](https://docs.docker.com/engine/understanding-docker/)
  9. - This includes: docker engine, docker machine and docker compose
  10. - disclaimer: only been tested with OSX
  11. - [postgres](https://www.postgresql.org/download/)
  12. - isn't absolutely necessary as db is run in a container
  13. - I installed with homebrew
  14. - using [postgres 9.5.5](https://www.postgresql.org/docs/9.5/static/)
  15. ## Adding new [application settings](api/proto_apps.py)
  16. - Add a new AppSettings object
  17. - Add to applications map in configure_for_app
  18. ## Local development stack - view make commands with command `make`
  19. #### `make build`
  20. Builds local API stack
  21. - builds a postgres db for the api on your machine
  22. - builds django api container image
  23. - builds nginx container image
  24. - spins up postgres container
  25. - migrates postgres DB
  26. - creates admin user: u - root@root.com, p - testpass
  27. #### `make start`
  28. Starts local API stack with docker compose
  29. #### `make logs`
  30. Tail logs of the locally running API container
  31. #### `make restart`
  32. Restarts local API stack with docker compose
  33. #### `make stop`
  34. Stops local API stack with docker compose
  35. #### `make sandbox`
  36. Create and jump into a running API container, with ports open, accompanied by postgres container
  37. #### `make test` and `make test-unit`
  38. Spins up local API container with a DB and runs unit and integration tests.
  39. `test-unit` only runs unit tests. `test` runs both unit and integration tests
  40. #### `make lint`
  41. Spins up local API container and pep8 lints
  42. #### Troubleshooting local dev
  43. - known bugs are in comments - can search project for `_BUG_` string
  44. - rebuilding the DB can sometimes not work because the postgres container
  45. doesnt spin up fast enough, or at all. I have the django manage.py commands wrapped to retry
  46. on account of DB operational failures. It will sometimes take a few seconds. This is because although there is a
  47. docker dependency, docker doesnt do anything like ensure the process is up on postgres before spinning up the api.
  48. Usually I do the following, then rerun:
  49. - `make stop` # stop all containers
  50. - remove all stopped containers (see below for command)
  51. - remove local data `rm -rf pgdata-local/*`
  52. - packer can sometimes fail unexpectedly, if this happens, I suggest just rerunning
  53. - if docker fails due to a port being taken, restart Docker engine
  54. - restarting Docker Engine is a good step with any Docker related problems
  55. #### Useful commands
  56. - `make clean && make build-db` - delete local DB and rebuild fresh DB, adding 1 root user
  57. - `docker ps -a -q | xargs docker rm` - remove all stopped containers
  58. - `docker images -q -a -f dangling=true | xargs docker rmi` - remove dangling docker images
  59. - `dockerbash {container ID or name}` - jump into a running container:
  60. ```
  61. dockerbash () {
  62. docker exec -it $1 /bin/bash
  63. }
  64. ```
  65. ## Repo structure
  66. ### build
  67. Contains dockerfiles for the containers needed to run an API
  68. ### deploy
  69. Contains docker compose configs and any necessary deploy scripts
  70. ## Spec'ing software: ApiaryIO apiblueprint
  71. Markdown tutorial: https://apiblueprint.org/documentation/tutorial.html
  72. Publishing updated versions of the spec is very easy:
  73. 1. Install apiary gem `gem install apiaryio`
  74. 2. Make sure APIARY_API_KEY is set in env
  75. 3. Make updates to specs/yourmarkdown.md
  76. 4. Publish with `apiary publish --api-name=fruitfulforums --path=specs/fruitfulforums.apib`
  77. ## Current Prototypes
  78. #### FruitfulForums
  79. - Forum application that encourages fruitful dialogue
  80. - docs: http://docs.fruitfulforums.apiary.io/
  81. - spec: specs/fruitfulforums.md
  82. - Can create local data by jumping onto box (`make sandbox`) and running `python manage.py ff_populate_local_db`