Skip to content

Commit

Permalink
Merge pull request #229 from OpenUpSA/sys/elasticsearch-url
Browse files Browse the repository at this point in the history
Sys/elasticsearch url
  • Loading branch information
paulmwatson authored Aug 21, 2024
2 parents 18a8bb5 + 5e11be5 commit 49a099c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
30 changes: 15 additions & 15 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Pombola is mostly a standard Django project.

We use docker to make development, test and production as similar as possible.

In development, we use docker-compose.
In development, we use docker compose.

In production, we use dokku. Dokku manages environment variables for
configuration and secrets, and proxies requests to the container IP.

If you'd like to run this in another way, use the docker-compose.yml file as the
If you'd like to run this in another way, use the docker compose.yml file as the
entrypoint to understand the environment and dependencies of this app.

## Where to put the code and data
Expand All @@ -32,28 +32,28 @@ git clone https://github.com/OpenUpSA/pombola.git
Run migrations

```
docker-compose run --rm app python manage.py migrate
docker compose run --rm app python manage.py migrate
```

Load [demo data](#demo-data) for easy dev setup. (See also [loading a production database dump](#production-data-dumps).)

```
docker-compose run --rm app python manage.py loaddata demodata.json
docker compose run --rm app python manage.py loaddata demodata.json
```

Load WriteInPublic fixtures - these will let you draft messages but not send them, just to enable trying out the write-to flows locally. Change the slugs and keys to the sandbox ones to send actual messages from your dev environment.

docker-compose run --rm app python manage.py loaddata writeinpublic.json
docker compose run --rm app python manage.py loaddata writeinpublic.json
Start the app, DB and search index:

```
docker-compose up
docker compose up
```

Build the search index:

```
docker-compose run --rm app python manage.py rebuild_index
docker compose run --rm app python manage.py rebuild_index
```

Now you can visit the site at [http://localhost:8000](http://localhost:8000)
Expand All @@ -63,13 +63,13 @@ Now you can visit the site at [http://localhost:8000](http://localhost:8000)
Delete the DB, media files and search index to start afresh:

```
docker-compose down --volumes
docker compose down --volumes
```

To enable [Django debug toolbar](https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#getting-the-code), set the `DJANGO_DEBUG_TOOLBAR` environment variable to `true`. For example, run `docker-compose` with:
To enable [Django debug toolbar](https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#getting-the-code), set the `DJANGO_DEBUG_TOOLBAR` environment variable to `true`. For example, run `docker compose` with:

```
DJANGO_DEBUG_TOOLBAR=true docker-compose up
DJANGO_DEBUG_TOOLBAR=true docker compose up
```

### Demo data
Expand All @@ -84,10 +84,10 @@ Remember to create or update fixtures when:

### How to add demodata

- Delete all data in the database `docker-compose run --rm app python manage.py flush`
- Load demodata `docker-compose run --rm app python manage.py loaddata demodata.json`
- Delete all data in the database `docker compose run --rm app python manage.py flush`
- Load demodata `docker compose run --rm app python manage.py loaddata demodata.json`
- Edit the data in the admin dashboard
- Dump the data into demodata.json ` docker-compose run --rm app python manage.py dumpdata --indent 2 > pombola/core/fixtures/demodata.json`
- Dump the data into demodata.json ` docker compose run --rm app python manage.py dumpdata --indent 2 > pombola/core/fixtures/demodata.json`
- Git diff - do the changes look sensible?

### Production data dumps
Expand All @@ -99,8 +99,8 @@ download a production database dump and load it locally using the following:
Load the schema and data:

```
zcat pg-dump_schema.sql.gz | docker-compose run --rm db psql postgres://pombola:pombola@db/pombola
zcat pg-dump_data.sql.gz | docker-compose run --rm db psql postgres://pombola:pombola@db/pombola
zcat pg-dump_schema.sql.gz | docker compose run --rm db psql postgres://pombola:pombola@db/pombola
zcat pg-dump_data.sql.gz | docker compose run --rm db psql postgres://pombola:pombola@db/pombola
```


Expand Down
8 changes: 4 additions & 4 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Running the Pombola tests

## Running the tests for South Africa using docker-compose
## Running the tests for South Africa using docker compose

docker-compose run app bin/wait-for-deps.sh coverage run -a --source=pombola,pombola_sayit,wordcloud ./manage.py test --settings=pombola.settings.tests_south_africa
docker compose run app bin/wait-for-deps.sh coverage run -a --source=pombola,pombola_sayit,wordcloud ./manage.py test --settings=pombola.settings.tests_south_africa


## Running tests selectively

Sometimes you want to just try one test method and don't want to recreate the
test database. You can do this for a generic test, for example, with:

docker-compose run app bin/wait-for-deps.sh ./manage.py test --settings=pombola.settings.tests_south_africa --keepdb pombola/south_africa/tests.py:SAHansardIndexViewTest
docker compose run app bin/wait-for-deps.sh ./manage.py test --settings=pombola.settings.tests_south_africa --keepdb pombola/south_africa/tests.py:SAHansardIndexViewTest

Note that there must be a colon separating the module from the
class name.
Expand All @@ -20,7 +20,7 @@ class name.
You can dramatically speed up the second and subsequent test
runs by supplying the `--keepdb` option to `test`, like:

docker-compose run --rm app ./manage.py test --keepdb \
docker compose run --rm app ./manage.py test --keepdb \
pombola.core.tests.test_models:PositionCurrencyTest.test_from_past_still_current

... because much of the time in running the tests is taken up
Expand Down
6 changes: 3 additions & 3 deletions docs/WriteInPublic.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ This WriteInPublic instance used to get contacts from EveryPolitician but EveryP
## Using a local instance of WriteInPublic

- Clone https://github.com/mysociety/writeinpublic
- If you're running PA on port 8000, change the port on which WriteInPublic will run in the `docker-compose.yml` file.
- Run `docker-compose up`
- If you're running PA on port 8000, change the port on which WriteInPublic will run in the `docker compose.yml` file.
- Run `docker compose up`
- Enable your PA container to connect to your localhost by following one of the answers in [this question](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) or:
- Run `export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)`
- Add the following under the `app` service in your PA `docker-compose.yml` file:
- Add the following under the `app` service in your PA `docker compose.yml` file:
```
extra_hosts:
- "dockerhost:$DOCKERHOST"
Expand Down
4 changes: 3 additions & 1 deletion pombola/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

from urlparse import urlparse

IN_TEST_MODE = False

# Work out where we are to set up the paths correctly and load config
Expand Down Expand Up @@ -294,7 +296,6 @@
PAGINATION_DEFAULT_ORPHANS = 2
PAGINATION_INVALID_PAGE_RAISES_404 = True


# haystack config - interface to search engine
HAYSTACK_CONNECTIONS = {
# 'default': {
Expand All @@ -305,6 +306,7 @@
"default": {
"ENGINE": "haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine",
"URL": os.environ.get("ELASTICSEARCH_URL"),
"PORT": urlparse(os.environ.get("ELASTICSEARCH_URL")).port,
"INDEX_NAME": os.environ.get("ELASTICSEARCH_INDEX", "pombola"),
"EXCLUDED_INDEXES": [],
"TIMEOUT": int(os.environ.get("ELASTICSEARCH_TIMEOUT", 10)),
Expand Down

0 comments on commit 49a099c

Please sign in to comment.