Skip to content

Commit

Permalink
Use the more concise 'Entities Service' name throughout (#70)
Browse files Browse the repository at this point in the history
Remove mention of the service pertaining only to DLite.
Remove SOFT mention where not applicable
Rename package folder.

Rename 'entity_service_' -> 'entities_service_'.
This is the environment variable prefix for setting configurations.

Rename all cases 'CasperWA' -> 'SINTEF' where applicable.
  • Loading branch information
CasperWA authored Jan 29, 2024
1 parent 22dae4f commit 5f6aabb
Show file tree
Hide file tree
Showing 34 changed files with 172 additions and 175 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd_onto-ns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
- name: Deploy updated main
run: |
curl -o response.json --silent -m 30 http://api.onto-ns.com/dlite/?service=dlite-entities-service
curl -o response.json --silent -m 30 http://api.onto-ns.com/deploy?service=entities-service
cat << EOF | python
import json
from pathlib import Path
import sys
response = json.loads(Path('response.json').read_bytes())
if response["service"] != "dlite-entities-service":
if response["service"] != "entities-service":
sys.exit(
"ERROR: Did not deploy the correct service\n"
f" service: {response['service']}\n"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd_updated_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
update_docs: false
# update_python_api_ref: true
# update_docs_landing_page: true
# package_dirs: dlite_entities_service
# package_dirs: entities_service
# python_version: "3.10"
# doc_extras: "[doc]"
# changelog_exclude_labels: "skip_changelog,duplicate,question,invalid,wontfix"
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ jobs:
MONGO_INITDB_ROOT_PASSWORD: root

env:
ENTITY_SERVICE_MONGO_URI: mongodb://localhost:27017
ENTITY_SERVICE_MONGO_USER: root
ENTITY_SERVICE_MONGO_PASSWORD: root
ENTITY_SERVICE_HOST: localhost
ENTITY_SERVICE_PORT: 8000
ENTITIES_SERVICE_MONGO_URI: mongodb://localhost:27017
ENTITIES_SERVICE_MONGO_USER: root
ENTITIES_SERVICE_MONGO_PASSWORD: root
ENTITIES_SERVICE_HOST: localhost
ENTITIES_SERVICE_PORT: 8000

steps:
- name: Checkout ${{ github.repository }}
Expand All @@ -68,22 +68,22 @@ jobs:
run: |
docker build \
--pull \
--tag entity-service \
--tag entities-service \
--target ${{ matrix.docker_target }} \
.
- name: Run Docker container
run: |
docker run --rm -d \
--env ENTITY_SERVICE_MONGO_URI \
--env ENTITY_SERVICE_MONGO_USER \
--env ENTITY_SERVICE_MONGO_PASSWORD \
--env PORT=${ENTITY_SERVICE_PORT} \
--name "entity-service" \
--env ENTITIES_SERVICE_MONGO_URI \
--env ENTITIES_SERVICE_MONGO_USER \
--env ENTITIES_SERVICE_MONGO_PASSWORD \
--env PORT=${ENTITIES_SERVICE_PORT} \
--name "entities-service" \
--network "host" \
--volume "${PWD}:/app" \
--user "$(id -u):$(id -g)" \
entity-service
entities-service
sleep 5
- name: Install test dependencies
Expand All @@ -98,10 +98,10 @@ jobs:
pytest -vv --live-backend --cov-report=xml
} || {
echo "Failed! Here's the Docker logs for the service:" &&
docker logs entity-service &&
docker logs entities-service &&
echo -e "\nAnd the service log:" &&
cat logs/dlite_entities_service.log &&
cat logs/entities_service.log &&
exit 1
}
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:3.10-slim as base

WORKDIR /app

COPY dlite_entities_service dlite_entities_service/
COPY entities_service entities_service/
COPY pyproject.toml LICENSE README.md ./

# Install dependencies
Expand All @@ -12,14 +12,14 @@ RUN python -m pip install -U pip && \
pip install -U -e . && \
# Create log directory and file (if not existing already)
mkdir -p logs && \
touch -a logs/dlite_entities_service.log
touch -a logs/entities_service.log

FROM base as development

ENV PORT=80
EXPOSE ${PORT}

ENTRYPOINT uvicorn --host 0.0.0.0 --port ${PORT} --log-level debug --no-server-header --header "Server:DLiteEntitiesService" --reload dlite_entities_service.main:APP
ENTRYPOINT uvicorn --host 0.0.0.0 --port ${PORT} --log-level debug --no-server-header --header "Server:EntitiesService" --reload entities_service.main:APP

FROM base as production

Expand All @@ -28,4 +28,4 @@ RUN pip install gunicorn
ENV PORT=80
EXPOSE ${PORT}

ENTRYPOINT gunicorn --bind "0.0.0.0:${PORT}" --workers 1 --worker-class dlite_entities_service.uvicorn.UvicornWorker dlite_entities_service.main:APP
ENTRYPOINT gunicorn --bind "0.0.0.0:${PORT}" --workers 1 --worker-class entities_service.uvicorn.UvicornWorker entities_service.main:APP
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Service for serving DLite entities
# Service for serving entities

This is a FastAPI-based REST API service running on onto-ns.com.
It's purpose is to serve DLite entities from an underlying database.
It's purpose is to serve entities from an underlying database.

## Run the service

First, download and install the Python package from GitHub:

```shell
# Download (git clone)
git clone https://github.com/CasperWA/dlite-entities-service.git
cd dlite-entities-service
git clone https://github.com/SINTEF/entities-service.git
cd entities-service

# Install (using pip)
python -m pip install -U pip
Expand All @@ -25,24 +25,24 @@ For development, start a local MongoDB server, e.g., through another Docker imag
docker run -d --name "mongodb" -p "27017:27017" mongo:6
```

Then build and run the DLite Entities Service Docker image:
Then build and run the Entities Service Docker image:

```shell
docker build --pull -t entity-service --target development .
docker build --pull -t entities-service --target development .
docker run --rm -d \
--env "entity_service_mongo_uri=mongodb://localhost:27017" \
--name "entity-service" \
--env "entities_service_mongo_uri=mongodb://localhost:27017" \
--name "entities-service" \
-p "8000:80" \
entity-service
entities-service
```

Now, fill up the MongoDB with valid DLite entities at the `dlite` database in the `entities` collection.
Now, fill up the MongoDB with valid entities at the `entities_service` database in the `entities` collection.

Then go to [localhost:8000/docs](http://localhost:8000/docs) and try out retrieving a DLite entity.
Then go to [localhost:8000/docs](http://localhost:8000/docs) and try out retrieving an entity.

---

For production, use a public MongoDB, and follow the same instructions above for building and running the DLite Entities Service Docker image, but exchange the `--target` value with `production`, put in the proper value for the `entity_service_mongo_uri` environment value, possibly add the `entity_service_mongo_user` and `entity_service_mongo_password` environment variables as well, if needed.
For production, use a public MongoDB, and follow the same instructions above for building and running the Entities Service Docker image, but exchange the `--target` value with `production`, put in the proper value for the `entities_service_mongo_uri` environment value, possibly add the `entities_service_mongo_user` and `entities_service_mongo_password` environment variables as well, if needed.

### Using Docker Compose

Expand All @@ -53,10 +53,10 @@ docker compose pull
docker compose up --build
```

By default the `development` target will be built, to change this, set the `entity_service_docker_target` environment variable accordingly, e.g.:
By default the `development` target will be built, to change this, set the `entities_service_docker_target` environment variable accordingly, e.g.:

```shell
entity_service_docker_target=production docker compose up --build
entities_service_docker_target=production docker compose up --build
```

Furthermore, the used `localhost` port can be changed via the `PORT` environment variable.
Expand All @@ -75,10 +75,10 @@ Then run it according to your desires.
For example, in development, it might be nice to have the server reload if any files are changed, as well as the server logging debug messages:

```shell
uvicorn dlite_entities_service.main:APP --reload --host localhost --port 8000 --log-level debug --debug --no-server-header --header "Server:DLiteEntitiesService"
uvicorn entities_service.main:APP --reload --host localhost --port 8000 --log-level debug --debug --no-server-header --header "Server:EntitiesService"
```

Then go to [localhost:8000/docs](http://localhost:8000/docs) and try out retrieving a DLite entity.
Then go to [localhost:8000/docs](http://localhost:8000/docs) and try out retrieving an entity.

### Using a file for environment variables

Expand Down
22 changes: 11 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
version: "3"

services:
dlite_entities_service:
entities_service:
build:
context: "."
target: "${ENTITY_SERVICE_DOCKER_TARGET:-development}"
target: "${ENTITIES_SERVICE_DOCKER_TARGET:-development}"
ports:
- "${ENTITY_SERVICE_PORT:-8000}:80"
- "${ENTITIES_SERVICE_PORT:-8000}:80"
environment:
PORT: ${ENTITY_SERVICE_PORT:-8000}
ENTITY_SERVICE_BASE_URL: "${ENTITY_SERVICE_HOST:-http://onto-ns.com/meta}"
ENTITY_SERVICE_MONGO_URI: "mongodb://mongodb:27017"
ENTITY_SERVICE_MONGO_USER: ${MONGO_USER:-root}
ENTITY_SERVICE_MONGO_PASSWORD: ${MONGO_PASSWORD:-root}
PORT: ${ENTITIES_SERVICE_PORT:-8000}
ENTITIES_SERVICE_BASE_URL: "${ENTITIES_SERVICE_HOST:-http://onto-ns.com/meta}"
ENTITIES_SERVICE_MONGO_URI: "mongodb://mongodb:27017"
ENTITIES_SERVICE_MONGO_USER: ${MONGO_USER:-root}
ENTITIES_SERVICE_MONGO_PASSWORD: ${MONGO_PASSWORD:-root}
depends_on:
- mongodb
networks:
- dlite_entities_net
- entities_service_net
volumes:
- "${PWD}:/app"

Expand All @@ -29,7 +29,7 @@ services:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-root}
networks:
- dlite_entities_net
- entities_service_net

networks:
dlite_entities_net:
entities_service_net:
4 changes: 2 additions & 2 deletions docs/example/dlite_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"It is expected that one has the following:\n",
"\n",
"- Installed:\n",
" - Local `dlite_entities_service` package.\n",
" - Local `entities_service` package.\n",
" - `requests`\n",
" - `DLite-Python`\n",
"- Running DLite Entities service at `http://localhost:8000` setup to connect to SOFT Cluster on MongoDB Atlas."
"- Running Entities Service at `http://localhost:8000` setup to connect to SOFT Cluster on MongoDB Atlas."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""DLite entities service."""
"""Entities Service."""
from __future__ import annotations

__version__ = "0.0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Utility CLI
This module contains a CLI with utilities that may be useful when dealing with the
DLite entities service, it's data (backend), and possibly more.
Entities Service, it's data (backend), and possibly more.
"""
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rich import print as rich_print
except ImportError as exc: # pragma: no cover
raise ImportError(
"Please install the DLite entities service utility CLI with 'pip install "
"Please install the entities service utility CLI with 'pip install "
f"{Path(__file__).resolve().parent.parent.parent.parent.resolve()}[cli]'"
) from exc

Expand All @@ -22,9 +22,9 @@


EXC_MSG_INSTALL_PACKAGE = (
"Please install the DLite entities service utility CLI with "
"Please install the entities service utility CLI with "
f"'pip install {Path(__file__).resolve().parent.parent.parent.parent.resolve()}"
"[cli]' or 'pip install dlite-entities-service[cli]'"
"[cli]' or 'pip install entities-service[cli]'"
)

OUTPUT_CONSOLE = get_console()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import typer
except ImportError as exc: # pragma: no cover
raise ImportError(
"Please install the DLite entities service utility CLI with 'pip install "
"Please install the entities service utility CLI with 'pip install "
f"{Path(__file__).resolve().parent.parent.parent.parent.resolve()}[cli]'"
) from exc

from dlite_entities_service import __version__
from dlite_entities_service.cli._utils.generics import print
from dlite_entities_service.service.config import CONFIG
from entities_service import __version__
from entities_service.cli._utils.generics import print
from entities_service.service.config import CONFIG

if TYPE_CHECKING: # pragma: no cover
from typing import TypedDict
Expand All @@ -38,7 +38,7 @@ class ContextDict(TypedDict):
def print_version(value: bool) -> None:
"""Print version and exit."""
if value:
print(f"dlite-entities-service version: {__version__}")
print(f"entities-service version: {__version__}")
raise typer.Exit()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""config subcommand for dlite-entities-service CLI."""
"""config subcommand for entities-service CLI."""
from __future__ import annotations

import sys
Expand All @@ -17,15 +17,15 @@ class StrEnum(str, Enum):
try:
import typer
except ImportError as exc: # pragma: no cover
from dlite_entities_service.cli._utils.generics import EXC_MSG_INSTALL_PACKAGE
from entities_service.cli._utils.generics import EXC_MSG_INSTALL_PACKAGE

raise ImportError(EXC_MSG_INSTALL_PACKAGE) from exc

from dotenv import dotenv_values, set_key, unset_key

from dlite_entities_service.cli._utils.generics import ERROR_CONSOLE, print
from dlite_entities_service.cli._utils.global_settings import CONTEXT
from dlite_entities_service.service.config import CONFIG
from entities_service.cli._utils.generics import ERROR_CONSOLE, print
from entities_service.cli._utils.global_settings import CONTEXT
from entities_service.service.config import CONFIG

APP = typer.Typer(
name=__file__.rsplit("/", 1)[-1].replace(".py", ""),
Expand Down
Loading

0 comments on commit 5f6aabb

Please sign in to comment.