Add docker dev scripts expose mongo port 15/102015/2
authorMarcus G K Williams <marcus.williams@intel.com>
Wed, 19 Feb 2020 18:47:12 +0000 (10:47 -0800)
committerMarcus G K Williams <marcus.williams@intel.com>
Wed, 19 Feb 2020 20:20:56 +0000 (12:20 -0800)
Add docker file and scripts, modify
docker-compose.yml to allow for developement
using docker container. Expose mongo port
for developement purposes.

Issue-ID: MULTICLOUD-871
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Change-Id: If17fac27247b3cee3ad2718b6d06ea188ea53733

src/orchestrator/scripts/Dockerfile [new file with mode: 0644]
src/orchestrator/scripts/_functions.sh
src/orchestrator/scripts/build.sh [new file with mode: 0755]
src/orchestrator/scripts/docker-compose.yml
src/orchestrator/scripts/start-docker.sh [new file with mode: 0755]

diff --git a/src/orchestrator/scripts/Dockerfile b/src/orchestrator/scripts/Dockerfile
new file mode 100644 (file)
index 0000000..b894f47
--- /dev/null
@@ -0,0 +1,30 @@
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2020
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+FROM ubuntu:18.04
+
+ARG HTTP_PROXY=${HTTP_PROXY}
+ARG HTTPS_PROXY=${HTTPS_PROXY}
+
+ENV http_proxy $HTTP_PROXY
+ENV https_proxy $HTTPS_PROXY
+ENV no_proxy $NO_PROXY
+
+EXPOSE 9015
+
+RUN groupadd -r onap && useradd -r -g onap onap
+
+WORKDIR /opt/multicloud/k8s/orchestrator
+RUN chown onap:onap /opt/multicloud/k8s/orchestrator -R
+
+ADD --chown=onap ./orchestrator ./
+
+USER onap
+
+CMD ["./orchestrator"]
\ No newline at end of file
index cba65d9..1200f71 100755 (executable)
@@ -28,9 +28,17 @@ function start_etcd {
 function generate_config {
 cat << EOF > config.json
 {
+    "ca-file": "ca.cert",
+    "server-cert": "server.cert",
+    "server-key": "server.key",
+    "password": "",
     "database-ip": "${DATABASE_IP}",
     "database-type": "mongo",
     "plugin-dir": "plugins",
+    "etcd-ip": "127.0.0.1",
+    "etcd-cert": "",
+    "etcd-key": "",
+    "etcd-ca-file": "",
     "service-port": "9015"
 }
 EOF
diff --git a/src/orchestrator/scripts/build.sh b/src/orchestrator/scripts/build.sh
new file mode 100755 (executable)
index 0000000..5446dac
--- /dev/null
@@ -0,0 +1,68 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2020 Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+set -o nounset
+set -o pipefail
+
+k8s_path="$(git rev-parse --show-toplevel)"
+
+VERSION="0.0.1-SNAPSHOT"
+export IMAGE_NAME="nexus3.onap.org:10003/onap/multicloud/k8s/orchestrator"
+
+function _compile_src {
+    echo "Compiling source code"
+    pushd $k8s_path/src/orchestrator/
+    make
+    popd
+}
+
+function _move_bin {
+    echo "Moving binaries"
+    mv $k8s_path/src/orchestrator/orchestrator .
+}
+
+function _cleanup {
+    echo "Cleaning previous execution"
+    docker-compose kill
+    image=$(grep "image.*orchestrator" docker-compose.yml)
+    if [[ -n ${image} ]]; then
+        docker images ${image#*:} -q | xargs docker rmi -f
+    fi
+    docker ps -a --filter "status=exited" -q | xargs docker rm
+}
+
+function _build_docker {
+    echo "Building docker image"
+    docker-compose build --no-cache
+}
+
+function _push_image {
+    local tag_name=${IMAGE_NAME}:${1:-latest}
+
+    echo "Start push {$tag_name}"
+    docker push ${IMAGE_NAME}:latest
+    docker tag ${IMAGE_NAME}:latest ${tag_name}
+    docker push ${tag_name}
+}
+
+if [[ -n "${JENKINS_HOME+x}" ]]; then
+    set -o xtrace
+    _compile_src
+    _move_bin
+    _build_docker
+    _push_image $VERSION
+else
+    source /etc/environment
+
+    _compile_src
+    _move_bin
+    _cleanup
+    _build_docker
+fi
\ No newline at end of file
index e5a1d68..3bb7bda 100644 (file)
 version: '3.0'
 
 services:
+  orchestrator:
+    image: nexus3.onap.org:10003/onap/multicloud/k8s/orchestrator
+    build:
+      context: ./
+      args:
+        - HTTP_PROXY=${HTTP_PROXY}
+        - HTTPS_PROXY=${HTTPS_PROXY}
+        - NO_PROXY=${NO_PROXY}
+    environment:
+      - HTTP_PROXY=${HTTP_PROXY}
+      - HTTPS_PROXY=${HTTPS_PROXY}
+      - NO_PROXY=${NO_PROXY},mongo
+    depends_on:
+      - mongo
+    network_mode: host
+    volumes:
+      - /opt/csar:/opt/csar
+      - ${PWD}/config.json:/opt/multicloud/k8s/orchestrator/config.json:ro
+    ports:
+      - 9015:9015
   mongo:
     image: mongo
     environment:
       - HTTP_PROXY=${HTTP_PROXY}
       - HTTPS_PROXY=${HTTPS_PROXY}
       - NO_PROXY=${NO_PROXY}
+    ports:
+      - 27017:27017
   etcd:
     image: bitnami/etcd:3
     environment:
diff --git a/src/orchestrator/scripts/start-docker.sh b/src/orchestrator/scripts/start-docker.sh
new file mode 100755 (executable)
index 0000000..c6f53c6
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2020 Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+source _functions.sh
+
+#
+# Start from containers. build.sh should be run prior this script.
+#
+stop_all
+start_mongo
+start_etcd
+generate_config
+start_all
\ No newline at end of file