aboutsummaryrefslogtreecommitdiffstats
path: root/vnfs/DAaaS/sample-apps/m3db_promql/build
diff options
context:
space:
mode:
authorRajamohan Raj <rajamohan.raj@intel.com>2019-06-18 22:29:41 +0000
committerGary Wu <gary.wu@futurewei.com>2019-06-19 13:00:00 +0000
commit646446fdd7a37124e4d5d31cf855296cf2ec8024 (patch)
tree8685eec71102cbc31cdcff9379107663f5619ed0 /vnfs/DAaaS/sample-apps/m3db_promql/build
parent9e135c71c10a673e7b13d4a827c01f3477c4cae8 (diff)
Helmize the sample promql_query_app
Release a helm chart and dockerfile for the sample promql_query_app Issue-ID: ONAPARC-508 Signed-off-by: Rajamohan Raj <rajamohan.raj@intel.com> Change-Id: I8fdddd3fe0094c132a485c1d40b524b8a8cb2062
Diffstat (limited to 'vnfs/DAaaS/sample-apps/m3db_promql/build')
-rw-r--r--vnfs/DAaaS/sample-apps/m3db_promql/build/.dockerignore12
-rw-r--r--vnfs/DAaaS/sample-apps/m3db_promql/build/Dockerfile78
-rwxr-xr-xvnfs/DAaaS/sample-apps/m3db_promql/build/entrypoint.sh45
-rw-r--r--vnfs/DAaaS/sample-apps/m3db_promql/build/requirements.txt1
-rw-r--r--vnfs/DAaaS/sample-apps/m3db_promql/build/sample_promql_query.py35
5 files changed, 171 insertions, 0 deletions
diff --git a/vnfs/DAaaS/sample-apps/m3db_promql/build/.dockerignore b/vnfs/DAaaS/sample-apps/m3db_promql/build/.dockerignore
new file mode 100644
index 00000000..98bc4363
--- /dev/null
+++ b/vnfs/DAaaS/sample-apps/m3db_promql/build/.dockerignore
@@ -0,0 +1,12 @@
+.git
+.ipynb_checkpoints/*
+Dockerfile
+.DS_Store
+.gitignore
+README.md
+env.*
+/devops/*
+
+# To prevent storing dev/temporary container data
+*.csv
+/tmp/* \ No newline at end of file
diff --git a/vnfs/DAaaS/sample-apps/m3db_promql/build/Dockerfile b/vnfs/DAaaS/sample-apps/m3db_promql/build/Dockerfile
new file mode 100644
index 00000000..61b15fee
--- /dev/null
+++ b/vnfs/DAaaS/sample-apps/m3db_promql/build/Dockerfile
@@ -0,0 +1,78 @@
+# Copyright (c) 2019 Intel Corporation
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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
+
+RUN apt update -yqq
+
+# Install all the essentials
+RUN apt-get update --fix-missing && \
+ apt-get install -y --no-install-recommends wget curl ca-certificates libglib2.0-0 libxext6 libsm6 libxrender1 \
+ git build-essential openssh-server openssh-client && \
+ mkdir -p /var/run/sshd && \
+ apt-get clean && \
+ rm -rf /var/lib/apt/lists/*
+
+ENV PATH /opt/conda/bin:$PATH
+
+# Install miniconda
+RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
+ /bin/bash ~/miniconda.sh -b -p /opt/conda && \
+ rm ~/miniconda.sh && \
+ ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
+ echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
+ echo "conda activate base" >> ~/.bashrc
+
+# Install python libraries using conda in the virtual_environment:ml_env
+SHELL ["/bin/bash", "-c"]
+RUN conda update -n base -c defaults conda && \
+ conda create -n ml_env
+RUN conda install -n ml_env -y -c anaconda pip
+RUN pwd
+RUN conda install -n ml_env -y -c anaconda h5py
+
+RUN conda install -n ml_env -y -c pytorch pytorch-cpu
+RUN conda install -n ml_env -y -c conda-forge nlopt
+
+RUN echo "conda activate ml_env" >> ~/.bashrc
+RUN source ~/.bashrc
+RUN /opt/conda/envs/ml_env/bin/pip install --no-cache-dir minio
+
+# Install tini
+RUN apt-get install -y --no-install-recommends curl grep sed dpkg && \
+ TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest | grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && echo ${TINI_VERSION} && \
+ curl -L "https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
+ dpkg -i tini.deb && \
+ rm tini.deb && \
+ apt clean
+
+# This is needed to match the original entrypoint.sh file.
+RUN cp /usr/bin/tini /sbin
+RUN echo "export PATH=/opt/conda/envs/ml_env/bin:$PATH" >> ~/.bashrc
+
+COPY . /app
+WORKDIR /app
+
+RUN mkdir promql_api
+RUN wget https://raw.githubusercontent.com/onap/demo/master/vnfs/DAaaS/lib/promql_api/prom_ql_api.py
+RUN mv prom_ql_api.py ./promql_api
+RUN touch ./promql_api/__init__.py
+RUN source ~/.bashrc
+RUN conda install -n ml_env -y --file requirements.txt
+
+ENTRYPOINT [ "/app/entrypoint.sh" ]
diff --git a/vnfs/DAaaS/sample-apps/m3db_promql/build/entrypoint.sh b/vnfs/DAaaS/sample-apps/m3db_promql/build/entrypoint.sh
new file mode 100755
index 00000000..571e03ca
--- /dev/null
+++ b/vnfs/DAaaS/sample-apps/m3db_promql/build/entrypoint.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+# echo commands to the terminal output
+set -ex
+
+# Check whether there is a passwd entry for the container UID
+myuid=$(id -u)
+mygid=$(id -g)
+# turn off -e for getent because it will return error code in anonymous uid case
+set +e
+uidentry=$(getent passwd $myuid)
+set -e
+
+# If there is no passwd entry for the container UID, attempt to create one
+if [ -z "$uidentry" ] ; then
+ if [ -w /etc/passwd ] ; then
+ echo "$myuid:x:$myuid:$mygid:anonymous uid:$SPARK_HOME:/bin/false" >> /etc/passwd
+ else
+ echo "Container ENTRYPOINT failed to add passwd entry for anonymous UID"
+ fi
+fi
+
+# CMD=(
+# /bin/bash -c "source activate ml_env && exec python sample_promql_query.py")
+
+CMD=(/bin/bash -c "source activate ml_env && exec python sample_promql_query.py")
+
+# Execute the container CMD under tini for better hygiene
+exec /sbin/tini -s -- "${CMD[@]}"
diff --git a/vnfs/DAaaS/sample-apps/m3db_promql/build/requirements.txt b/vnfs/DAaaS/sample-apps/m3db_promql/build/requirements.txt
new file mode 100644
index 00000000..663bd1f6
--- /dev/null
+++ b/vnfs/DAaaS/sample-apps/m3db_promql/build/requirements.txt
@@ -0,0 +1 @@
+requests \ No newline at end of file
diff --git a/vnfs/DAaaS/sample-apps/m3db_promql/build/sample_promql_query.py b/vnfs/DAaaS/sample-apps/m3db_promql/build/sample_promql_query.py
new file mode 100644
index 00000000..fbbf497e
--- /dev/null
+++ b/vnfs/DAaaS/sample-apps/m3db_promql/build/sample_promql_query.py
@@ -0,0 +1,35 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2019 Intel Corporation Intellectual Property
+#
+# 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 promql_api.prom_ql_api import query
+import pprint
+
+QUERY_STRING = ['irate(collectd_cpufreq{exported_instance="otconap7",cpufreq="1"}[2m])']
+
+#Other examples
+#QUERY_STRING = [ 'irate(http_requests_total{code="200"}[1m])', 'collectd_cpu_percent{job="collectd", exported_instance="otconap7"}[1m]' ]
+#QUERY_STRING = ['irate(collectd_cpufreq{exported_instance="otconap7",cpufreq="1"}[2m])', 'go_info']
+
+def main():
+ list_of_result_sets = query(QUERY_STRING)
+ if list_of_result_sets:
+ for each_result in list_of_result_sets:
+ pprint.pprint(each_result)
+
+if __name__ == "__main__":
+ main()