From 2ec0808c5d96c6f93aea1a60d5ca312c2b395049 Mon Sep 17 00:00:00 2001 From: magnussonl Date: Fri, 1 May 2020 10:43:30 +0200 Subject: [PATCH] PLA build Added missing license header Add PLA to SUBDIRS Dummy modification to retrigger process Resolved docker/Makefile conflict with NG-UI Change-Id: Iaf20208a885a864f3994f2cc76ceeaa0eeb4fb56 Signed-off-by: magnussonl --- docker/PLA/Dockerfile | 59 ++++++++++++++++++++++++++++++ docker/PLA/Makefile | 17 +++++++++ docker/PLA/scripts/start.sh | 71 +++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 docker/PLA/Dockerfile create mode 100644 docker/PLA/Makefile create mode 100644 docker/PLA/scripts/start.sh diff --git a/docker/PLA/Dockerfile b/docker/PLA/Dockerfile new file mode 100644 index 00000000..8bc51371 --- /dev/null +++ b/docker/PLA/Dockerfile @@ -0,0 +1,59 @@ +# Copyright 2020 Arctos Labs Scandinavia AB +# +# 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 ubuntu:18.04 + +LABEL authors="Lars-Göran Magnusson" + +RUN apt-get --yes update \ + && apt-get --yes install git python python-pip python3 python3-pip libmysqlclient-dev libssl-dev libffi-dev \ + && apt-get --yes install mysql-client curl software-properties-common libgl1-mesa-glx \ + && pip3 install pip==9.0.3 + +ARG REPOSITORY_BASE=http://osm-download.etsi.org/repository/osm/debian +ARG RELEASE=ReleaseFOUR-daily +ARG REPOSITORY_KEY=OSM%20ETSI%20Release%20Key.gpg +ARG REPOSITORY=testing + +RUN curl ${REPOSITORY_BASE}/${RELEASE}/${REPOSITORY_KEY} | apt-key add - +RUN add-apt-repository -y "deb ${REPOSITORY_BASE}/${RELEASE} ${REPOSITORY} PLA common" && apt update + +ARG PLA_VERSION +ARG COMMON_VERSION + +RUN apt-get --yes update && apt-get -y install python3-osm-common${COMMON_VERSION} python3-osm-pla${PLA_VERSION} + +COPY scripts/ scripts/ + +ENV OSMPLA_MESSAGE_DRIVER kafka +ENV OSMPLA_MESSAGE_HOST kafka +ENV OSMPLA_MESSAGE_PORT 9092 + +ENV OSMPLA_DATABASE_DRIVER mongo +ENV OSMPLA_DATABASE_URI mongodb://mongo:27017 + +ENV OSMPLA_SQL_DATABASE_URI sqlite:///pla_sqlite.db + +ENV OSMPLA_GLOBAL_LOG_LEVEL INFO + +ENV FZNEXEC "/entry_data/fzn-exec" +ENV PATH "/minizinc/bin:${PATH}" +ENV LD_LIBRARY_PATH "/minizinc/lib:${LD_LIBRARY_PATH}" + +# No healtcheck yet... +#HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \ +# CMD osm-pla-healthcheck || exit 1 + +CMD /bin/bash scripts/start.sh diff --git a/docker/PLA/Makefile b/docker/PLA/Makefile new file mode 100644 index 00000000..8763aad5 --- /dev/null +++ b/docker/PLA/Makefile @@ -0,0 +1,17 @@ +# Copyright 2020 ETSI +# +# 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. +include ../mk/Makefile.include + +MDG=$(shell basename $(CURDIR)) diff --git a/docker/PLA/scripts/start.sh b/docker/PLA/scripts/start.sh new file mode 100644 index 00000000..ae39b57f --- /dev/null +++ b/docker/PLA/scripts/start.sh @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Arctos Labs Scandinavia AB +# +# 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. +DB_EXISTS="" + +max_attempts=120 +function wait_db(){ + db_host=$1 + db_port=$2 + attempt=0 + echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} " + while ! mysqladmin ping -h"$db_host" -P"$db_port" --silent; do + #wait 120 sec + if [ $attempt -ge $max_attempts ]; then + echo + echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec" + return 1 + fi + attempt=$[$attempt+1] + echo -n "." + sleep 1 + done + return 0 +} + +function is_db_created() { + db_host=$1 + db_port=$2 + db_user=$3 + db_pswd=$4 + db_name=$5 + + if mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -q $db_name; then + echo "DB $db_name exists" + return 0 + else + echo "DB $db_name does not exist" + return 1 + fi +} + +if [[ $OSMPLA_SQL_DATABASE_URI == *'mysql'* ]]; then + DB_HOST=$(echo $OSMPLA_SQL_DATABASE_URI | sed -r 's|^\w+://.+:.+@(.+):.*$|\1|') + DB_PORT=$(echo $OSMPLA_SQL_DATABASE_URI | sed -r 's|^\w+://.*:([0-9]+).*$|\1|') + DB_USER=$(echo $OSMPLA_SQL_DATABASE_URI | sed -r 's|^\w+://(.+):.+@.+$|\1|') + DB_PASSWORD=$(echo $OSMPLA_SQL_DATABASE_URI | sed -r 's|^.+://.+:(.+)@.*$|\1|') + DB_NAME=$(echo $OSMPLA_SQL_DATABASE_URI | sed -r 's|^\w+://.+:.+@.+:.*/(.+)$|\1|') + + wait_db "$DB_HOST" "$DB_PORT" || exit 1 + + is_db_created "$DB_HOST" "$DB_PORT" "$DB_USER" "$DB_PASSWORD" "$DB_NAME" && DB_EXISTS="Y" + + if [ -z $DB_EXISTS ]; then + mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASSWORD" --default_character_set utf8 -e "CREATE DATABASE $DB_NAME" + fi +fi + +osm-pla-server -- 2.25.1