Skip to content

Elasticsearch #1

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

Merged
merged 19 commits into from
Jan 30, 2022
Merged
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: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
**Related Issue(s):** #


**Description:**


**PR Checklist:**

- [ ] Code is formatted and linted (run `pre-commit run --all-files`)
- [ ] Tests pass (run `make test`)
- [ ] Documentation has been updated to reflect changes, if applicable, and docs build successfully (run `make docs`)
- [ ] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac/blob/master/CHANGES.md).
77 changes: 77 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: stac-fastapi-nosql
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10

services:
mongo_db_service:
image: mongo:3.6
env:
MONGO_INITDB_ROOT_USERNAME: dev
MONGO_INITDB_ROOT_PASSWORD: stac
ports:
- 27018:27017

elasticsearch_db_service:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.2
env:
node.name: es01
cluster.name: stac-cluster
discovery.type: single-node
network.host: 0.0.0.0
http.port: 9200
ES_JAVA_OPTS: -Xms512m -Xmx512m
ports:
- 9200:9200

steps:
- name: Check out repository code
uses: actions/checkout@v2

# Setup Python (faster than using Python container)
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Lint code
uses: pre-commit/action@v2.0.0

- name: Install pipenv
run: |
python -m pip install --upgrade pipenv wheel

- name: Install mongo stac-fastapi
run: |
pip install ./stac_fastapi/mongo[dev,server]

- name: Install elasticsearch stac-fastapi
run: |
pip install ./stac_fastapi/elasticsearch[dev,server]

- name: Run test suite
run: |
cd stac_fastapi/mongo && pipenv run pytest -svvv
env:
ENVIRONMENT: testing
MONGO_USER: dev
MONGO_PASS: stac
MONGO_PORT: 27018
MONGO_HOST: localhost

- name: Run test suite
run: |
cd stac_fastapi/elasticsearch && pipenv run pytest -svvv
env:
ENVIRONMENT: testing
ES_USER: dev
ES_PASS: stac
ES_PORT: 9200
ES_HOST: 172.17.0.1
20 changes: 20 additions & 0 deletions Dockerfile.elasticsearch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.8-slim as base

FROM base as builder
# Any python libraries that require system libraries to be installed will likely
# need the following packages in order to build
RUN apt-get update && apt-get install -y build-essential git

ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

ARG install_dev_dependencies=true

WORKDIR /app

# Install stac_fastapi.types
COPY . /app

ENV PATH=$PATH:/install/bin

RUN mkdir -p /install && \
pip install -e ./stac_fastapi/elasticsearch[dev,server]
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
APP_HOST ?= 0.0.0.0
APP_PORT ?= 8080
EXTERNAL_APP_PORT ?= ${APP_PORT}

run_es = docker-compose -f docker-compose.elasticsearch.yml \
run \
-p ${EXTERNAL_APP_PORT}:${APP_PORT} \
-e PY_IGNORE_IMPORTMISMATCH=1 \
-e APP_HOST=${APP_HOST} \
-e APP_PORT=${APP_PORT} \
app-elasticsearch

run_mongo = docker-compose -f docker-compose.mongo.yml \
run \
-p ${EXTERNAL_APP_PORT}:${APP_PORT} \
Expand All @@ -10,28 +19,48 @@ run_mongo = docker-compose -f docker-compose.mongo.yml \
-e APP_PORT=${APP_PORT} \
app-mongo

.PHONY: es-image
es-image:
docker-compose -f docker-compose.elasticsearch.yml build

.PHONY: mongo-image
mongo-image:
docker-compose -f docker-compose.mongo.yml build

.PHONY: docker-run-es
docker-run-es: es-image
$(run_es)

.PHONY: docker-run-mongo
docker-run-mongo: mongo-image
$(run_mongo)

.PHONY: docker-shell-es
docker-shell-es:
$(run_es) /bin/bash

.PHONY: docker-shell-mongo
docker-shell-mongo:
$(run_mongo) /bin/bash

.PHONY: test-es
test-es:
$(run_es) /bin/bash -c 'export && ./scripts/wait-for-it.sh elasticsearch:9200 && cd /app/stac_fastapi/elasticsearch/tests/ && pytest'

.PHONY: test-mongo
test-mongo:
$(run_mongo) /bin/bash -c 'export && cd /app/stac_fastapi/mongo/tests/ && pytest'

.PHONY: run-es-database
run-es-database:
docker-compose -f docker-compose.elasticsearch.yml run --rm elasticsearch

.PHONY: run-mongo-database
run-mongo-database:
docker-compose -f docker-compose.mongo.yml run --rm mongo_db

.PHONY: test
test: test-sqlalchemy test-pgstac test-mongo
test: test-elasticsearch test-mongo

.PHONY: pybase-install
pybase-install:
Expand All @@ -40,6 +69,10 @@ pybase-install:
pip install -e ./stac_fastapi/types[dev] && \
pip install -e ./stac_fastapi/extensions[dev]

.PHONY: es-install
es-install: pybase-install
pip install -e ./stac_fastapi/elasticsearch[dev,server]

.PHONY: mongo-install
mongo-install: pybase-install
pip install -e ./stac_fastapi/mongo[dev,server]
Expand Down
47 changes: 47 additions & 0 deletions docker-compose.elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3'

services:
app-elasticsearch:
container_name: stac-fastapi-es
image: stac-utils/stac-fastapi
restart: always
build:
context: .
dockerfile: Dockerfile.elasticsearch
platform: linux/amd64
environment:
- APP_HOST=0.0.0.0
- APP_PORT=8083
- RELOAD=false
- ENVIRONMENT=local
- WEB_CONCURRENCY=10
- ES_USER=dev
- ES_PASS=stac
- ES_PORT=9200
- ES_HOST=172.17.0.1
ports:
- "8083:8083"
volumes:
- ./stac_fastapi:/app/stac_fastapi
- ./scripts:/app/scripts
depends_on:
- elasticsearch
command:
bash -c "./scripts/wait-for-it-es.sh es-container:9200 && python -m stac_fastapi.elasticsearch.app"

elasticsearch:
container_name: es-container
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.2
environment:
node.name: es01
cluster.name: stac-cluster
discovery.type: single-node
network.host: 0.0.0.0
http.port: 9200
ES_JAVA_OPTS: -Xms512m -Xmx512m
ports:
- 9200:9200

networks:
default:
name: stac-fastapi-network
Loading