Commit a431db9a authored by Manuel Angel Jimenez Quesada's avatar Manuel Angel Jimenez Quesada
Browse files

Add DockerFile to osm_client MicroServices

Solve imports typo
parent 2a85e17a
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.10.16-slim


# Install dependencies
RUN apt-get --yes --quiet --quiet update
RUN apt-get --yes --quiet --quiet install wget g++ git build-essential cmake make git \
    libpcre2-dev python3-dev python3-pip python3-cffi curl software-properties-common && \
    rm -rf /var/lib/apt/lists/*

# Set Python to show logs as they occur
ENV PYTHONUNBUFFERED=0


# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
    chmod +x /bin/grpc_health_probe

# Get generic Python packages
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade setuptools wheel
RUN python3 -m pip install --upgrade pip-tools

# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt

# Add common files into working directory
WORKDIR /var/teraflow/common
COPY src/common/. ./
RUN rm -rf proto

# Create proto sub-folder, copy .proto files, and generate Python code
RUN mkdir -p /var/teraflow/common/proto
WORKDIR /var/teraflow/common/proto
RUN touch __init__.py
COPY proto/*.proto ./
RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto
RUN rm *.proto
RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \;

# Create component sub-folders
RUN mkdir -p /var/teraflow/osm_client
WORKDIR /var/teraflow/osm_client
ENV OSM_CLIENT_VERSION=v16.0
RUN python3 -m pip install -r "https://osm.etsi.org/gitweb/?p=osm/IM.git;a=blob_plain;f=requirements.txt;hb=${OSM_CLIENT_VERSION}"
RUN python3 -m pip install "git+https://osm.etsi.org/gerrit/osm/IM.git@${OSM_CLIENT_VERSION}#egg=osm-im" --upgrade
#Clone OsmCLient code
RUN git clone https://osm.etsi.org/gerrit/osm/osmclient
RUN git -C osmclient checkout ${OSM_CLIENT_VERSION}
# Install osmClient using pip
RUN python3 -m pip install -r osmclient/requirements.txt
RUN python3 -m pip install ./osmclient

# Add component files into working directory
WORKDIR /var/teraflow
COPY src/osm_client/. osm_client/

# Start the service
ENTRYPOINT ["python", "-m", "osm_client.service"]
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.osm_client_pb2_grpc import osmClientServiceStub
from common.proto.osm_client_pb2_grpc import OsmServiceStub
from common.proto.context_pb2 import (Empty)
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string
@@ -43,7 +43,7 @@ class OsmClient:

    def connect(self):
        self.channel = grpc.insecure_channel(self.endpoint)
        self.stub = osmClientServiceStub(self.channel)
        self.stub = OsmServiceStub(self.channel)

    def close(self):
        if self.channel is not None: self.channel.close()
+0 −4
Original line number Diff line number Diff line
@@ -18,10 +18,6 @@ from common.proto.osm_client_pb2_grpc import add_OsmServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService
from osm_client.service.OsmClientServiceServicerImpl import OsmClientServiceServicerImpl

from osmclient import client
from osmclient.common.exceptions import ClientException


class OsmClientService(GenericGrpcService):
    def __init__(self, cls_name: str = __name__) -> None:
        port = get_service_port_grpc(ServiceNameEnum.OSMCLIENT)
+2 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_m
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.proto.context_pb2 import (Empty)
from common.proto.osm_client_pb2 import CreateRequest, CreateResponse, NsiListResponse, GetRequest, GetResponse, DeleteRequest, DeleteResponse
from common.proto.osm_client_pb2_grpc import osmCLientServiceServicer
from common.proto.osm_client_pb2_grpc import OsmServiceServicer
from osmclient import client
from osmclient.common.exceptions import ClientException
from osm_client.Config import OSM_ADDRESS
@@ -26,7 +26,7 @@ LOGGER = logging.getLogger(__name__)

METRICS_POOL = MetricsPool('OSMCLIENT', 'RPC')

class OsmClientServiceServicerImpl(osmCLientServiceServicer):
class OsmClientServiceServicerImpl(OsmServiceServicer):
    def __init__(self):
        LOGGER.info('Creating Servicer...')
        self.myclient = client.Client(host=OSM_ADDRESS, sol005=True)