|
| 1 | +[](https://circleci.com/gh/uktrade/data-hub-leeloo/tree/master) |
| 2 | +[](https://codecov.io/gh/uktrade/data-hub-leeloo) |
| 3 | +[](https://codeclimate.com/github/uktrade/data-hub-leeloo) |
| 4 | +[](https://landscape.io/github/uktrade/data-hub-leeloo/master) |
| 5 | +[](https://pyup.io/repos/github/uktrade/data-hub-leeloo/) |
| 6 | + |
| 7 | +Leeloo provides an API into Data Hub for Data Hub clients. Using Leeloo you can search for entities and manage companies, contacts and interactions. |
| 8 | + |
| 9 | +Installation with Docker |
| 10 | +======================== |
| 11 | + |
| 12 | +Leeloo uses Docker compose to setup and run all the necessary components. The docker-compose.yml file provided is meant to be used for running tests and development. |
| 13 | + |
| 14 | +1. Clone the repository: |
| 15 | + |
| 16 | + ```shell |
| 17 | + git clone https://github.com/uktrade/data-hub-leeloo |
| 18 | + cd data-hub-leeloo |
| 19 | + ``` |
| 20 | + |
| 21 | +2. Build and run the necessary containers for the required environment: |
| 22 | + |
| 23 | + ```shell |
| 24 | + docker-compose build |
| 25 | + ``` |
| 26 | + |
| 27 | +3. Populate the db: |
| 28 | + |
| 29 | + ```shell |
| 30 | + docker-compose run leeloo python manage.py migrate |
| 31 | + docker-compose run leeloo python manage.py loaddata /app/fixtures/metadata.yaml |
| 32 | + docker-compose run leeloo python manage.py loaddata /app/fixtures/datahub_businesstypes.yaml |
| 33 | + docker-compose run leeloo python manage.py createinitialrevisions |
| 34 | + ``` |
| 35 | + |
| 36 | +4. Create a superuser: |
| 37 | + |
| 38 | + ```shell |
| 39 | + docker-compose run leeloo python manage.py createsuperuser |
| 40 | + ``` |
| 41 | + |
| 42 | +5. Run the services: |
| 43 | + |
| 44 | + ```shell |
| 45 | + docker-compose up |
| 46 | + ``` |
| 47 | + |
| 48 | +6. To set up the [data hub frontend app](https://github.com/uktrade/data-hub-fe-beta2), log into the [django admin](http://localhost:8000/admin/oauth2_provider/application/) and add a new oauth application with: |
| 49 | + |
| 50 | + - Client type: Confidential |
| 51 | + - Authorization grant type: Resource owner password-based |
| 52 | + |
| 53 | +7. Add the client id / client secret to the frontend .env file |
| 54 | + |
| 55 | +Local development with Docker |
| 56 | +----------------------------- |
| 57 | + |
| 58 | +To run the tests: |
| 59 | + |
| 60 | +```shell |
| 61 | +docker-compose run leeloo bash tests.sh |
| 62 | +docker-compose run leeloo bash tests-auth.sh |
| 63 | +``` |
| 64 | + |
| 65 | +To run the linter: |
| 66 | + |
| 67 | +```shell |
| 68 | +docker-compose run leeloo flake8 |
| 69 | +``` |
| 70 | + |
| 71 | +Native installation (without Docker) |
| 72 | +==================================== |
| 73 | + |
| 74 | +Dependencies: |
| 75 | + |
| 76 | +- Python 3.6.1 |
| 77 | +- Postgres (tested on 9.5+) |
| 78 | + |
| 79 | +1. Clone the repository: |
| 80 | + |
| 81 | + ```shell |
| 82 | + git clone https://github.com/uktrade/data-hub-leeloo |
| 83 | + cd data-hub-leeloo |
| 84 | + ``` |
| 85 | + |
| 86 | +2. Install `virtualenv` if you don’t have it already: |
| 87 | + |
| 88 | + ```shell |
| 89 | + pip install virtualenv |
| 90 | + ``` |
| 91 | + |
| 92 | +3. Create and activate the virtualenv: |
| 93 | + |
| 94 | + ```shell |
| 95 | + virtualenv --python=python3 env |
| 96 | + source env/bin/activate |
| 97 | + pip install -U pip |
| 98 | + ``` |
| 99 | + |
| 100 | +4. Install the dependencies: |
| 101 | + |
| 102 | + ```shell |
| 103 | + pip install -r requirements.txt |
| 104 | + ``` |
| 105 | + |
| 106 | +5. Create an `.env` settings file (it’s gitignored by default): |
| 107 | + |
| 108 | + ```shell |
| 109 | + cp config/settings/sample.env config/settings/.env |
| 110 | + ``` |
| 111 | + |
| 112 | +6. Set `DOCKER_DEV=False` in `.env` |
| 113 | +7. Create the db. By default, the dev version uses postgres: |
| 114 | + |
| 115 | + ```shell |
| 116 | + psql -p5432 |
| 117 | + create database datahub; |
| 118 | + ``` |
| 119 | + |
| 120 | +8. Configure and populate the db: |
| 121 | + |
| 122 | + ```shell |
| 123 | + ./manage.py migrate |
| 124 | + ./manage.py createsuperuser |
| 125 | + |
| 126 | + ./manage.py loaddata fixtures/metadata.yaml |
| 127 | + ./manage.py loaddata fixtures/datahub_businesstypes.yaml |
| 128 | + ./manage.py createinitialrevisions |
| 129 | + ``` |
| 130 | + |
| 131 | +9. Start the server: |
| 132 | + |
| 133 | + ```shell |
| 134 | + ./manage.py runserver |
| 135 | + ``` |
| 136 | + |
| 137 | +10. To set up the [data hub frontend app](https://github.com/uktrade/data-hub-fe-beta2), log into the [django admin](http://localhost:8000/admin/oauth2_provider/application/) and add a new oauth application with: |
| 138 | + |
| 139 | + - Client type: Confidential |
| 140 | + - Authorization grant type: Resource owner password-based |
| 141 | + |
| 142 | +11. Add the client id / client secret to the frontend .env file |
| 143 | + |
| 144 | +Local development (without Docker) |
| 145 | +---------------------------------- |
| 146 | + |
| 147 | +To run the tests: |
| 148 | + |
| 149 | +```shell |
| 150 | +bash tests.sh |
| 151 | +bash tests-auth.sh |
| 152 | +``` |
| 153 | + |
| 154 | +To run the linter: |
| 155 | + |
| 156 | +```shell |
| 157 | +flake8 |
| 158 | +``` |
| 159 | + |
| 160 | +Heroku |
| 161 | +====== |
| 162 | + |
| 163 | +Leeloo can run on any Heroku style platform. These environment variables MUST be configured: |
| 164 | + |
| 165 | +- DATABASE\_URL |
| 166 | +- DATAHUB\_SECRET |
| 167 | +- DEBUG |
| 168 | +- DJANGO\_SECRET\_KEY |
| 169 | +- DJANGO\_SENTRY\_DSN |
| 170 | +- DJANGO\_SETTINGS\_MODULE |
| 171 | +- BULK\_CREATE\_BATCH\_SIZE (default=5000) |
| 172 | +- ES\_URL |
| 173 | +- ES\_INDEX |
| 174 | +- AWS\_ACCESS\_KEY\_ID |
| 175 | +- AWS\_SECRET\_ACCESS\_KEY |
| 176 | +- DOCUMENTS\_BUCKET |
| 177 | + |
| 178 | +Management commands |
| 179 | +=================== |
| 180 | + |
| 181 | +Enable CDMS login for users (use this to let a CDMS user log in): |
| 182 | + |
| 183 | +```shell |
| 184 | +docker-compose run leeloo python manage.py manageusers test@bar.com foo@bar.com --enable |
| 185 | +``` |
| 186 | + |
| 187 | +Disable CDMS login for users: |
| 188 | + |
| 189 | +```shell |
| 190 | +docker-compose run leeloo python manage.py manageusers test@bar.com foo@bar.com --disable |
| 191 | +``` |
| 192 | + |
| 193 | +Apply migrations: |
| 194 | + |
| 195 | +```shell |
| 196 | +docker-compose run leeloo python manage.py migrate |
| 197 | +``` |
| 198 | + |
| 199 | +If the database is freshly built or a new versioned model is added run: |
| 200 | + |
| 201 | +```shell |
| 202 | +docker-compose run leeloo python manage.py createinitialrevisions |
| 203 | +``` |
| 204 | + |
| 205 | +Load metadata: |
| 206 | + |
| 207 | +```shell |
| 208 | +docker-compose run leeloo python manage.py loaddata /app/fixtures/metadata.yaml |
| 209 | +docker-compose run leeloo python manage.py loaddata /app/fixtures/datahub_businesstypes.yaml |
| 210 | +``` |
| 211 | + |
| 212 | +Dependencies |
| 213 | +============ |
| 214 | + |
| 215 | +Direct dependencies are specified in `requirements.in`. `requirements.txt` is a lock file generated using [pip-compile (from pip-tools)](https://github.com/jazzband/pip-tools) and should not be manually edited. |
| 216 | + |
| 217 | +To update the lock file and indirect dependencies, run: |
| 218 | + |
| 219 | +```shell |
| 220 | +pip-compile --upgrade --output-file requirements.txt requirements.in |
| 221 | +``` |
| 222 | + |
| 223 | +This must be run whenever `requirements.in` is edited. |
| 224 | + |
| 225 | +Dependencies should still be installed using `requirements.txt`. |
0 commit comments