Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run API using remote Elastic Search #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM python:3.8
FROM docker.io/python:3.8

WORKDIR /mnt/code
ENV PYTHONPATH=/mnt/code

RUN adduser --system gazette && apt-get update && apt-get install -y wait-for-it jq

COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt && rm requirements.txt

RUN mkdir /mnt/code
COPY . /mnt/code
WORKDIR /mnt/code
ENV PYTHONPATH=/mnt/code

ADD https://querido-diario.nyc3.cdn.digitaloceanspaces.com/censo/censo.csv censo.csv
RUN chmod 644 censo.csv

USER gazette

COPY . /mnt/code
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,20 @@ start-elasticsearch:
--name $(ELASTICSEARCH_CONTAINER_NAME) \
--pod $(POD_NAME) \
--env discovery.type=single-node \
elasticsearch:7.9.1
docker.io/elasticsearch:7.9.1

stop-elasticsearch:
podman rm --force --ignore $(ELASTICSEARCH_CONTAINER_NAME)

wait-elasticsearch:
$(call wait-for, localhost:9200)

run-standalone: build
podman run --rm \
--env QUERIDO_DIARIO_ELASTICSEARCH_INDEX=$(REMOTE_ELASTICSEARCH_INDEX) \
--env QUERIDO_DIARIO_ELASTICSEARCH_HOST=$(REMOTE_ELASTICSEARCH_HOST) \
--env QUERIDO_DIARIO_DATABASE_CSV=$(QUERIDO_DIARIO_DATABASE_CSV) \
--publish $(API_PORT):$(API_PORT) \
--user=$(UID):$(UID) \
$(IMAGE_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) \
python main
Comment on lines +149 to +157
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this working in your env? I'm not sure if this will work. With this command, it will run the process inside a container/namespace which is not guarantee to has the Elasticsearch running.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is to use with another Elasticsearch, e.g., when you setup with real data using data processing to create a real scenery.

The problem here is do a make run and try to create another Elasticsearch when you are running Elasticsearch with querido-diario-data-processing. Because of that, you need to run with 2 parameters as you can see at README:

REMOTE_ELASTICSEARCH_INDEX="querido-diario" REMOTE_ELASTICSEARCH_HOST="my.ip" make run-standalone

I think another option is to create all environment in one place. But I don't know if is a good idea.

What you think about this @jvanz ?

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@ need to insert data into the database. There is another make target, `make apisq
which open the `psql` and connect to the database. Thus, you can insert data
using some `INSERT INTO ...` statements and test the API. ;)


### Using suggestion endpoint

You need to create a token at [Mailjet](www.mailjet.com) to run
application and send email (put on `config/current.env`).
### Running with a remote Elastic Search

If you want use a remote Elastic Search run application with this:
```shell
REMOTE_ELASTICSEARCH_INDEX="index_name" REMOTE_ELASTICSEARCH_HOST="es_host" make run-standalone
```

## Tests

Expand Down