From: tierno Date: Mon, 19 Nov 2018 13:39:33 +0000 (+0100) Subject: fixing package dependencies and generation X-Git-Tag: v5.0.0~13 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=0c01ffa4f8cdd307d15463fb389b7cfe2d500db6;hp=4c57e2e64537d6263c618da58bcd8f8767b8076e fixing package dependencies and generation Change-Id: I89ab7cc0a5cf0c02b1621cd8f1aaad5ba93d724d Signed-off-by: tierno --- diff --git a/Dockerfile b/Dockerfile index 8f664c5..5c0807a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,21 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright 2018 Telefonica S.A. +# +# 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. + # This Dockerfile is intented for devops and deb package generation # # Use Dockerfile.local for running osm/NBI in a docker container from source @@ -6,7 +24,17 @@ FROM ubuntu:16.04 -RUN apt-get update && apt-get -y install git make python python3 \ +RUN apt-get update && apt-get -y install wget git make python python3 python-pip \ libcurl4-gnutls-dev libgnutls-dev tox python-dev python3-dev \ - debhelper python-setuptools python-all python3-all apt-utils + debhelper python-setuptools python-all python3-all apt-utils python-magic \ + python3-pip python-pip && \ + DEBIAN_FRONTEND=noninteractive pip3 install -U stdeb setuptools-version-command && \ + DEBIAN_FRONTEND=noninteractive pip2 install -U stdeb + +# Uncomment this block to generate automatically a debian package and show info +# Set the working directory to /app +WORKDIR /app +# Copy the current directory contents into the container at /app +ADD . /app +CMD /app/devops-stages/stage-build.sh && find -name "*.deb" -exec dpkg -I {} ";" diff --git a/Dockerfile.fromdeb b/Dockerfile.fromdeb index c99e974..120630a 100644 --- a/Dockerfile.fromdeb +++ b/Dockerfile.fromdeb @@ -2,29 +2,23 @@ FROM ubuntu:16.04 +ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian +ARG RELEASE=ReleaseFIVE +ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg +ARG REPOSITORY=testing + +RUN apt-get update && apt-get install -y curl software-properties-common +RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add - +RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} NBI IM common" && apt update + +RUN apt-get -y install python3-osm-nbi + # Set the working directory to /app WORKDIR /app/osm_nbi -# avoid extra information from packages -RUN echo 'path-exclude /usr/share/doc/*\n\ -path-include /usr/share/doc/*/copyright\n\ -path-exclude /usr/share/man/*\n\ -path-exclude /usr/share/groff/*\n\ -path-exclude /usr/share/info/*\n\ -path-exclude /usr/share/lintian/*\n\ -path-exclude /usr/share/linda/*\n'\ -> /etc/dpkg/dpkg.cfg.d/01_nodoc && \ - echo 'APT::Install-Recommends "false";\n\ -APT::AutoRemove::RecommendsImportant "false";\n\ -APT::AutoRemove::SuggestsImportant "false";\n'\ -> /etc/apt/apt.conf.d/99_norecommends - - -RUN apt-get update && apt-get install -y curl software-properties-common \ - && add-apt-repository -y "deb http://osm-download.etsi.org/repository/osm/debian/ReleaseFOUR testing common NBI" \ - && curl "http://osm-download.etsi.org/repository/osm/debian/ReleaseFOUR/OSM%20ETSI%20Release%20Key.gpg" | apt-key add - \ - && apt-get update && apt-get install -y python3-osm-nbi python3-osm-common \ - && rm -rf /var/lib/apt/lists/* +RUN cp -R /usr/lib/python3/dist-packages/osm_nbi/html_public /app/osm_nbi/html_public \ + && cp /usr/lib/python3/dist-packages/osm_nbi/nbi.cfg /app/osm_nbi/ \ + && cp -R /usr/lib/python3/dist-packages/osm_nbi/http /app/osm_nbi/ EXPOSE 9999 @@ -46,18 +40,30 @@ ENV OSMNBI_SOCKET_PORT 9999 ENV OSMNBI_STORAGE_PATH /app/storage # database ENV OSMNBI_DATABASE_DRIVER mongo -ENV OSMNBI_DATABASE_HOST mongo -ENV OSMNBI_DATABASE_PORT 27017 +ENV OSMNBI_DATABASE_URI mongodb://mongo:27017 # web ENV OSMNBI_STATIC_DIR /app/osm_nbi/html_public # logs -ENV OSMNBI_LOG_FILE /app/log +# ENV OSMNBI_LOG_FILE /app/log ENV OSMNBI_LOG_LEVEL DEBUG # message ENV OSMNBI_MESSAGE_DRIVER kafka ENV OSMNBI_MESSAGE_HOST kafka ENV OSMNBI_MESSAGE_PORT 9092 +# authentication +ENV OSMNBI_AUTHENTICATION_BACKEND internal +#ENV OSMNBI_AUTHENTICATION_BACKEND keystone +#ENV OSMNBI_AUTHENTICATION_AUTH_URL keystone +#ENV OSMNBI_AUTHENTICATION_AUTH_PORT 5000 +#ENV OSMNBI_AUTHENTICATION_USER_DOMAIN_NAME default +#ENV OSMNBI_AUTHENTICATION_PROJECT_DOMAIN_NAME default +#ENV OSMNBI_AUTHENTICATION_SERVICE_USERNAME nbi +#ENV OSMNBI_AUTHENTICATION_SERVICE_PASSWORD nbi +#ENV OSMNBI_AUTHENTICATION_SERVICE_PROJECT service # Run app.py when the container launches -CMD ["python3", "nbi.py"] +CMD ["python3", "/usr/lib/python3/dist-packages/osm_nbi/nbi.py"] + +HEALTHCHECK --interval=5s --timeout=2s --retries=12 \ + CMD curl -k https://localhost:9999/osm/ | grep Welcome || exit 1 diff --git a/Dockerfile.local b/Dockerfile.local index 56dbd82..c76bc27 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -57,7 +57,7 @@ ENV OSMNBI_DATABASE_PORT 27017 # web ENV OSMNBI_STATIC_DIR /app/NBI/osm_nbi/html_public # logs -# ENV OSMNBI_LOG_FILE /app/log +# ENV OSMNBI_LOG_FILE /app/log/nbi.log ENV OSMNBI_LOG_LEVEL DEBUG # message ENV OSMNBI_MESSAGE_DRIVER kafka diff --git a/MANIFEST.in b/MANIFEST.in index 53f1515..0553d06 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,24 @@ -#include MANIFEST.in -#include requirements.txt +# Copyright 2018 Whitestack, LLC +# +# 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. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact: bdiaz@whitestack.com or glavado@whitestack.com +## + include README.rst -recursive-include osm_nbi * +recursive-include osm_nbi *.py *.sh *.cfg +recursive-include osm_nbi/html_public * +recursive-include osm_nbi/http * +recursive-include devops-stages * diff --git a/Makefile b/Makefile index 475cbb0..fba5941 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,28 @@ +# Copyright 2018 Telefonica S.A. +# +# 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. + +all: clean package clean: - rm -rf dist deb_dist .build osm_nbi-*.tar.gz osm_nbi.egg-info .eggs + rm -rf dist deb_dist osm_nbi-*.tar.gz osm_nbi.egg-info .eggs package: python3 setup.py --command-packages=stdeb.command sdist_dsc - cp python3-osm-nbi.postinst deb_dist/osm-nbi*/debian - cd deb_dist/osm-nbi*/debian && echo "osm-common python3-osm-common" > py3dist-overrides + cp debian/python3-osm-nbi.postinst deb_dist/osm-nbi*/debian + # cd deb_dist/osm-nbi*/debian && echo "osm-common python3-osm-common" > py3dist-overrides # cd deb_dist/osm-nbi*/debian && echo "pip3 python3-pip" >> py3dist-overrides cd deb_dist/osm-nbi*/ && dpkg-buildpackage -rfakeroot -uc -us - mkdir -p .build - cp deb_dist/python3-osm-nbi*.deb .build/ diff --git a/debian/python3-osm-nbi.postinst b/debian/python3-osm-nbi.postinst new file mode 100755 index 0000000..5ff9ec7 --- /dev/null +++ b/debian/python3-osm-nbi.postinst @@ -0,0 +1,30 @@ +#!/bin/bash + +## +# 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. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: OSM_TECH@list.etsi.org +## + +echo "POST INSTALL OSM-NBI" +echo "Installing python dependencies via pip..." + +pip3 install pip==9.0.3 +pip3 install cherrypy==18.0.0 +pip3 install keystoneauth1 + +#Creation of log folder +mkdir -p /var/log/osm + +# systemctl enable osm-nbi.service diff --git a/devops-stages/stage-build.sh b/devops-stages/stage-build.sh index 58af160..0ce2bb2 100755 --- a/devops-stages/stage-build.sh +++ b/devops-stages/stage-build.sh @@ -1,4 +1,18 @@ #!/bin/sh -rm -rf deb_dist -tox -e build -#make clean package + +# 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. + +make clean +# tox -e build +make package diff --git a/python3-osm-nbi.postinst b/python3-osm-nbi.postinst deleted file mode 100755 index 452f503..0000000 --- a/python3-osm-nbi.postinst +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -## -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact with: OSM_TECH@list.etsi.org -## - -echo "POST INSTALL OSM-NBI" - -#Creation of log folder -mkdir -p /var/log/osm - -systemctl enable osm-nbi.service - diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..469ec46 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,19 @@ +# 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. + +CherryPy==18.0.0 +jsonschema +PyYAML==3.* +python-keystoneclient +git+https://osm.etsi.org/gerrit/osm/common.git#egg=osm-common +git+https://osm.etsi.org/gerrit/osm/IM.git#egg=osm-im + diff --git a/setup.py b/setup.py index 0f3c616..7d8a31d 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright 2018 Telefonica S.A. +# +# 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. import os from setuptools import setup @@ -28,20 +44,20 @@ setup( packages=[_name], include_package_data=True, # exclude_package_data={'': ['osm_nbi/local', 'temp']}, - data_files=[('/etc/osm/', ['osm_nbi/nbi.cfg']), - ('/etc/systemd/system/', ['osm_nbi/osm-nbi.service']), - ], + # data_files=[('/etc/osm/', ['osm_nbi/nbi.cfg']), + # ('/etc/systemd/system/', ['osm_nbi/osm-nbi.service']), + # ], dependency_links=[ - "git+https://osm.etsi.org/gerrit/osm/common.git@master#egg=osm-common-0.1.4" + "git+https://osm.etsi.org/gerrit/osm/IM.git#egg=osm-im", + 'git+https://osm.etsi.org/gerrit/osm/common.git#egg=osm-common' ], install_requires=[ - 'CherryPy', 'pymongo', 'jsonschema', 'PyYAML', 'python-keystoneclient' - # 'osm-common', + 'CherryPy==18.0.0', + 'osm-common', + 'jsonschema', + 'PyYAML', + 'osm-im', + 'python-keystoneclient' ], setup_requires=['setuptools-version-command'], - # test_suite='nose.collector', - # entry_points=''' - # [console_scripts] - # osm=osm_nbi.nbi:nbi - # ''', ) diff --git a/stdeb.cfg b/stdeb.cfg index f7300ed..8da69fe 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,2 +1,3 @@ [DEFAULT] -Depends: python3-cherrypy3, python3-pymongo, python3-yaml, python3-jsonschema, python3-keystoneclient +X-Python3-Version : >= 3.5 +Depends3 : python3-osm-common, python3-osm-im, python3-cherrypy3, python3-yaml, python3-jsonschema, python3-keystoneclient diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..4a6c14d --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,16 @@ +# 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. + +flake8<3.0 +mock + diff --git a/tox.ini b/tox.ini index 3a6de1a..27bc184 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,27 @@ +# Copyright 2018 Telefonica S.A. +# +# 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. + [tox] -envlist = py27,py3,flake8 +envlist = py3 toxworkdir={homedir}/.tox [testenv] -deps=nose - mock -commands=nosetests +basepython = python3 +install_command = python3 -m pip install -r requirements.txt -U {opts} {packages} +deps = -r{toxinidir}/test-requirements.txt +commands=python3 -m unittest discover -v [testenv:flake8] basepython = python3 @@ -18,3 +34,4 @@ basepython = python3 deps = stdeb setuptools-version-command commands = python3 setup.py --command-packages=stdeb.command bdist_deb +