Skip to content

Pv/create docker image for deploy #79

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 3 commits into from
Mar 23, 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
22 changes: 0 additions & 22 deletions Dockerfile

This file was deleted.

18 changes: 18 additions & 0 deletions Dockerfile.deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.8-slim

RUN apt-get update && \
apt-get -y upgrade && \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only dev dependencies need buildessitials and git, so don't install.

apt-get clean && \
rm -rf /var/lib/apt/lists/*

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

WORKDIR /app

COPY . /app

RUN pip install --no-cache-dir ./stac_fastapi/elasticsearch[server]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only install server deps, not dev also


EXPOSE 8080

CMD ["uvicorn", "stac_fastapi.elasticsearch.app:app", "--host", "0.0.0.0", "--port", "8080"]
18 changes: 18 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.8-slim


# update apt pkgs, and install build-essential for ciso8601
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# update certs used by Requests
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

WORKDIR /app

COPY . /app

RUN pip install --no-cache-dir -e ./stac_fastapi/elasticsearch[dev,server]
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ run_es = docker-compose \

.PHONY: image
image:
docker build -f Dockerfile.deploy -t stac-fastapi-elasticsearch:latest .

.PHONY: run
run:
docker run -it -p 8080:8080 \
-e ENVIRONMENT=local \
-e ES_HOST=docker.for.mac.localhost \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this will have to be updated for non-mac. tbd.

-e ES_PORT=9200 \
-e ES_USER=dev \
-e ES_PASS=stac \
stac-fastapi-elasticsearch:latest

.PHONY: image-dev
image-dev:
docker-compose build

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

.PHONY: docker-shell
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pre-commit run --all-files`
docker-compose build
```

## Running API on localhost:8083
## Running API on localhost:8080

```shell
docker-compose up
Expand All @@ -50,7 +50,7 @@ TBD: how to run this with 8.x with a password enabled and TLS.
To create a new Collection:

```shell
curl -X "POST" "http://localhost:8083/collections" \
curl -X "POST" "http://localhost:8080/collections" \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"id": "my_collection"
Expand Down
2 changes: 1 addition & 1 deletion data_loader/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import requests

DATA_DIR = os.path.join(os.path.dirname(__file__), "setup_data/")
STAC_API_BASE_URL = "http://localhost:8083"
STAC_API_BASE_URL = "http://localhost:8080"


def load_data(filename):
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ services:
restart: always
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.dev
environment:
- APP_HOST=0.0.0.0
- APP_PORT=8083
- APP_PORT=8080
- RELOAD=false
- ENVIRONMENT=local
- WEB_CONCURRENCY=10
Expand All @@ -19,7 +19,7 @@ services:
- ES_PORT=9200
- ES_HOST=172.17.0.1
ports:
- "8083:8083"
- "8080:8080"
volumes:
- ./stac_fastapi:/app/stac_fastapi
- ./scripts:/app/scripts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8083/",
"raw": "http://localhost:8080/",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -30,7 +30,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8083/collections",
"raw": "http://localhost:8080/collections",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -49,7 +49,7 @@
"method": "DELETE",
"header": [],
"url": {
"raw": "http://localhost:8083/collections/test-collection",
"raw": "http://localhost:8080/collections/test-collection",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -69,7 +69,7 @@
"method": "DELETE",
"header": [],
"url": {
"raw": "http://localhost:8083/collections/test-collection/items/test-item",
"raw": "http://localhost:8080/collections/test-collection/items/test-item",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -91,7 +91,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8083/collections/test-collection",
"raw": "http://localhost:8080/collections/test-collection",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -111,7 +111,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8083/collections/test-collection/items",
"raw": "http://localhost:8080/collections/test-collection/items",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -132,7 +132,7 @@
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8083/collections/test-collection/items/test-item",
"raw": "http://localhost:8080/collections/test-collection/items/test-item",
"protocol": "http",
"host": [
"localhost"
Expand Down Expand Up @@ -169,7 +169,7 @@
"raw": "{\n \"id\": \"test-collection\",\n \"stac_extensions\": [\"https://stac-extensions.github.io/eo/v1.0.0/schema.json\"],\n \"type\": \"Collection\",\n \"description\": \"Landat 8 imagery radiometrically calibrated and orthorectified using gound points and Digital Elevation Model (DEM) data to correct relief displacement.\",\n \"stac_version\": \"1.0.0\",\n \"summaries\": {\n \"platform\": [\"landsat-8\"],\n \"instruments\": [\"oli\", \"tirs\"],\n \"gsd\": [30]\n },\n \"extent\": {\n \"spatial\": {\n \"bbox\": [\n [\n -180.0,\n -90.0,\n 180.0,\n 90.0\n ]\n ]\n },\n \"temporal\": {\n \"interval\": [\n [\n \"2013-06-01\",\n null\n ]\n ]\n }\n },\n \"links\": [\n {\n \"href\": \"http://localhost:8081/collections/landsat-8-l1\",\n \"rel\": \"self\",\n \"type\": \"application/json\"\n },\n {\n \"href\": \"http://localhost:8081/\",\n \"rel\": \"parent\",\n \"type\": \"application/json\"\n },\n {\n \"href\": \"http://localhost:8081/collections/landsat-8-l1/items\",\n \"rel\": \"item\",\n \"type\": \"application/geo+json\"\n },\n {\n \"href\": \"http://localhost:8081/\",\n \"rel\": \"root\",\n \"type\": \"application/json\"\n }\n ],\n \"title\": \"Landsat 8 L1\",\n \"keywords\": [\n \"landsat\",\n \"earth observation\",\n \"usgs\"\n ]\n}"
},
"url": {
"raw": "http://localhost:8083/collections",
"raw": "http://localhost:8080/collections",
"protocol": "http",
"host": [
"localhost"
Expand Down Expand Up @@ -203,7 +203,7 @@
"raw": "{\n \"type\": \"Feature\",\n \"id\": \"test-item\",\n \"stac_version\": \"1.0.0\",\n \"stac_extensions\": [\n \"https://stac-extensions.github.io/eo/v1.0.0/schema.json\",\n \"https://stac-extensions.github.io/projection/v1.0.0/schema.json\"\n ],\n \"geometry\": {\n \"coordinates\": [\n [\n [\n 152.15052873427666,\n -33.82243006904891\n ],\n [\n 150.1000346138806,\n -34.257132625788756\n ],\n [\n 149.5776607193635,\n -32.514709769700254\n ],\n [\n 151.6262528041627,\n -32.08081674221862\n ],\n [\n 152.15052873427666,\n -33.82243006904891\n ]\n ]\n ],\n \"type\": \"Polygon\"\n },\n \"properties\": {\n \"datetime\": \"2018-02-12T12:30:22Z\",\n \"landsat:scene_id\": \"LC82081612020043LGN00\",\n \"landsat:row\": \"161\",\n \"gsd\": 15,\n \"landsat:revision\": \"00\",\n \"view:sun_azimuth\": -148.83296771,\n \"instrument\": \"OLI_TIRS\",\n \"landsat:product_id\": \"LC08_L1GT_208161_20200212_20200212_01_RT\",\n \"eo:cloud_cover\": 0,\n \"landsat:tier\": \"RT\",\n \"landsat:processing_level\": \"L1GT\",\n \"landsat:column\": \"208\",\n \"platform\": \"landsat-8\",\n \"proj:epsg\": 32756,\n \"view:sun_elevation\": -37.30791534,\n \"view:off_nadir\": 0,\n \"height\": 2500,\n \"width\": 2500\n },\n \"bbox\": [\n 149.57574,\n -34.25796,\n 152.15194,\n -32.07915\n ],\n \"collection\": \"test-collection\",\n \"assets\": {},\n \"links\": [\n {\n \"href\": \"http://localhost:8081/collections/landsat-8-l1/items/LC82081612020043\",\n \"rel\": \"self\",\n \"type\": \"application/geo+json\"\n },\n {\n \"href\": \"http://localhost:8081/collections/landsat-8-l1\",\n \"rel\": \"parent\",\n \"type\": \"application/json\"\n },\n {\n \"href\": \"http://localhost:8081/collections/landsat-8-l1\",\n \"rel\": \"collection\",\n \"type\": \"application/json\"\n },\n {\n \"href\": \"http://localhost:8081/\",\n \"rel\": \"root\",\n \"type\": \"application/json\"\n }\n ]\n}"
},
"url": {
"raw": "http://localhost:8083/collections/test-collection/items",
"raw": "http://localhost:8080/collections/test-collection/items",
"protocol": "http",
"host": [
"localhost"
Expand Down Expand Up @@ -239,7 +239,7 @@
"raw": "{\n \"collections\":[\"test-collection\"],\n \"intersects\":{\"type\": \"Point\", \"coordinates\": [150.04, -33.14]}\n}"
},
"url": {
"raw": "http://localhost:8083/search",
"raw": "http://localhost:8080/search",
"protocol": "http",
"host": [
"localhost"
Expand Down Expand Up @@ -273,7 +273,7 @@
"raw": "{\n \"collections\":[\"sentinel-s2-l2a\"],\n \"bbox\": [-69.433594,-10.660608,-47.285156,3.513421]\n}"
},
"url": {
"raw": "http://localhost:8083/search",
"raw": "http://localhost:8080/search",
"protocol": "http",
"host": [
"localhost"
Expand All @@ -298,7 +298,7 @@
}
],
"url": {
"raw": "http://localhost:8083/search?query={\"gsd\": {\"gt\": 14}}",
"raw": "http://localhost:8080/search?query={\"gsd\": {\"gt\": 14}}",
"protocol": "http",
"host": [
"localhost"
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/elasticsearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"elasticsearch-dsl==7.4.0",
"pystac[validation]",
"uvicorn",
"overrides",
]

extra_reqs = {
Expand All @@ -28,7 +29,6 @@
"pre-commit",
"requests",
"ciso8601",
"overrides",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should have been a core dep rather than an extra. We never ran it without also installing the dev deps, so it didn't surface.

"httpx",
],
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

@app.on_event("startup")
async def _startup_event():
IndexesClient().create_indexes()
await IndexesClient().create_indexes()


def run():
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async def test_app_fields_extension(load_test_data, app_client, txn_client):
resp_json = resp.json()
assert list(resp_json["features"][0]["properties"]) == ["datetime"]

txn_client.delete_item(item["id"], item["collection"], request=MockRequest)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this method doesn't use the request, so removing

txn_client.delete_item(item["id"], item["collection"])


async def test_app_query_extension_gt(app_client, ctx):
Expand Down
10 changes: 5 additions & 5 deletions stac_fastapi/elasticsearch/tests/clients/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_create_collection(app_client, ctx, core_client, txn_client):
await txn_client.create_collection(in_coll, request=MockRequest)
got_coll = await core_client.get_collection(in_coll["id"], request=MockRequest)
assert got_coll["id"] == in_coll["id"]
await txn_client.delete_collection(in_coll["id"], request=MockRequest)
await txn_client.delete_collection(in_coll["id"])


async def test_create_collection_already_exists(app_client, ctx, txn_client):
Expand All @@ -29,7 +29,7 @@ async def test_create_collection_already_exists(app_client, ctx, txn_client):
with pytest.raises(ConflictError):
await txn_client.create_collection(data, request=MockRequest)

await txn_client.delete_collection(data["id"], request=MockRequest)
await txn_client.delete_collection(data["id"])


async def test_update_collection(
Expand All @@ -46,7 +46,7 @@ async def test_update_collection(
coll = await core_client.get_collection(data["id"], request=MockRequest)
assert "new keyword" in coll["keywords"]

await txn_client.delete_collection(data["id"], request=MockRequest)
await txn_client.delete_collection(data["id"])


async def test_delete_collection(
Expand All @@ -57,7 +57,7 @@ async def test_delete_collection(
data = load_test_data("test_collection.json")
await txn_client.create_collection(data, request=MockRequest)

await txn_client.delete_collection(data["id"], request=MockRequest)
await txn_client.delete_collection(data["id"])

with pytest.raises(NotFoundError):
await core_client.get_collection(data["id"], request=MockRequest)
Expand All @@ -73,7 +73,7 @@ async def test_get_collection(
coll = await core_client.get_collection(data["id"], request=MockRequest)
assert coll["id"] == data["id"]

await txn_client.delete_collection(data["id"], request=MockRequest)
await txn_client.delete_collection(data["id"])


async def test_get_item(app_client, ctx, core_client):
Expand Down
Empty file.
75 changes: 0 additions & 75 deletions stac_fastapi/elasticsearch/tests/features/test_custom_models.py

This file was deleted.