-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
300 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SERVING PARAMETERS | ||
SERVICE_MODE=task | ||
MODEL_TYPE=lin | ||
|
||
# SERVICE DISCOVERY | ||
SERVICE_NAME=MY_PUNCTUATION_SERVICE | ||
LANGUAGE= | ||
|
||
# CONCURRENCY | ||
CONCURRENCY=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SERVING PARAMETERS | ||
SERVICE_MODE=task | ||
|
||
# SERVICE PARAMETERS | ||
SERVICES_BROKER=redis://192.168.0.1:6379 | ||
BROKER_PASS=password | ||
|
||
# SERVICE DISCOVERY | ||
SERVICE_NAME=MY_PUNCTUATION_SERVICE | ||
LANGUAGE=en-US/fr-FR/* | ||
QUEUE_NAME=(Optionnal) | ||
MODEL_INFO=This model does something | ||
|
||
# CONCURRENCY | ||
CONCURRENCY=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
FROM python:3.8 | ||
LABEL maintainer="[email protected], [email protected]" | ||
FROM python:3.9 | ||
LABEL maintainer="[email protected]" | ||
ENV PYTHONUNBUFFERED TRUE | ||
ENV IMAGE_NAME linto-platform-diarization | ||
|
||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends -y \ | ||
|
@@ -28,9 +29,12 @@ COPY punctuation /usr/src/app/punctuation | |
RUN mkdir /usr/src/app/model-store | ||
RUN mkdir -p /usr/src/app/tmp | ||
COPY config.properties /usr/src/app/config.properties | ||
|
||
COPY RELEASE.md ./ | ||
COPY docker-entrypoint.sh wait-for-it.sh healthcheck.sh ./ | ||
|
||
# Grep CURRENT VERSION | ||
RUN export VERSION=$(awk -v RS='' '/#/ {print; exit}' RELEASE.md | head -1 | sed 's/#//' | sed 's/ //') | ||
|
||
ENV PYTHONPATH="${PYTHONPATH}:/usr/src/app/punctuation" | ||
HEALTHCHECK CMD ./healthcheck.sh | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
"""The register Module allow registering and unregistering operations within the service stack for service discovery purposes""" | ||
import os | ||
import sys | ||
import uuid | ||
from socket import gethostname | ||
from time import time | ||
|
||
import redis | ||
from redis.commands.json.path import Path | ||
from redis.commands.search.field import NumericField, TextField | ||
from redis.commands.search.indexDefinition import IndexDefinition, IndexType | ||
|
||
SERVICE_DISCOVERY_DB = 0 | ||
SERVICE_TYPE = "punctuation" | ||
|
||
service_name = os.environ.get("SERVICE_NAME", SERVICE_TYPE) | ||
service_lang = os.environ.get("LANGUAGE", "?") | ||
host_name = gethostname() | ||
|
||
|
||
def register(is_heartbeat: bool = False) -> bool: | ||
"""Registers the service and act as heartbeat. | ||
Returns: | ||
bool: registering status | ||
""" | ||
host, port = os.environ.get("SERVICES_BROKER").split("//")[1].split(":") | ||
password = os.environ.get("BROKER_PASS", None) | ||
r = redis.Redis( | ||
host=host, port=int(port), db=SERVICE_DISCOVERY_DB, password=password | ||
) | ||
|
||
res = r.json().set(f"service:{host_name}", Path.root_path(), service_info()) | ||
if is_heartbeat: | ||
return res | ||
else: | ||
print(f"Service registered as service:{host_name}") | ||
schema = ( | ||
TextField("$.service_name", as_name="service_name"), | ||
TextField("$.service_type", as_name="service_type"), | ||
TextField("$.service_language", as_name="service_language"), | ||
TextField("$.queue_name", as_name="queue_name"), | ||
TextField("$.version", as_name="version"), | ||
TextField("$.info", as_name="info"), | ||
NumericField("$.last_alive", as_name="last_alive"), | ||
NumericField("$.concurrency", as_name="concurrency"), | ||
) | ||
try: | ||
r.ft().create_index( | ||
schema, | ||
definition=IndexDefinition(prefix=["service:"], index_type=IndexType.JSON), | ||
) | ||
except Exception as error: | ||
print(f"Index service already exist") | ||
return res | ||
|
||
|
||
def unregister() -> None: | ||
"""Un-register the service""" | ||
try: | ||
host, port = os.environ.get("SERVICES_BROKER").split("//")[1].split(":") | ||
r = redis.Redis( | ||
host=host, port=int(port), db=SERVICE_DISCOVERY_DB, password="password" | ||
) | ||
r.json().delete(f"service:{host_name}") | ||
except Exception as error: | ||
print(f"Failed to unregister: {repr(error)}") | ||
|
||
|
||
def queue() -> str: | ||
return os.environ.get("QUEUE_NAME", f"{SERVICE_TYPE}_{service_lang}_{service_name}") | ||
|
||
|
||
def service_info() -> dict: | ||
return { | ||
"service_name": service_name, | ||
"host_name": host_name, | ||
"service_type": SERVICE_TYPE, | ||
"service_language": service_lang, | ||
"queue_name": queue(), | ||
"version": "1.2.0", | ||
"info": os.environ.get("MODEL_INFO", "unknown"), | ||
"last_alive": int(time()), | ||
"concurrency": int(os.environ.get("CONCURRENCY")), | ||
} | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(register()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '3.7' | ||
|
||
services: | ||
punctuation-service: | ||
image: linto-platform-punctuation:latest | ||
volumes: | ||
- /path/to/your/model.mar/usr/src/app/model-store/punctuation.mar | ||
env_file: .env | ||
deploy: | ||
replicas: 1 | ||
networks: | ||
- your-net | ||
|
||
networks: | ||
your-net: | ||
external: true |
Oops, something went wrong.