summaryrefslogtreecommitdiffstats
path: root/consul-loader-container
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2019-02-08 14:21:58 -0500
committerJack Lucas <jflucas@research.att.com>2019-02-15 17:05:55 -0500
commit5caf1654683a567da7e4158e4e7e108dd2232a13 (patch)
tree02370038eff60f8393d0a50533e75d1fd4340af6 /consul-loader-container
parentba636576dd196fd8f22b461763320abcd785c751 (diff)
Move ph and dh to Helm
-- Helm charts for ph and dh -- New container to do Consul k-v storage and service reg -- Bootstrap container no longer deploys ph and dh -- Healthcheck looks for ph and dh as Helm deployments -- Updated/added licensing information Issue-ID: DCAEGEN2-1091 Issue-ID: DCAEGEN2-1092 Change-Id: I5340bee6fba1340d4c05b0f37ddfb539c543469e Signed-off-by: Jack Lucas <jflucas@research.att.com>
Diffstat (limited to 'consul-loader-container')
-rw-r--r--consul-loader-container/Dockerfile23
-rw-r--r--consul-loader-container/README.md11
-rwxr-xr-xconsul-loader-container/consul_store.sh94
-rw-r--r--consul-loader-container/pom.xml172
4 files changed, 300 insertions, 0 deletions
diff --git a/consul-loader-container/Dockerfile b/consul-loader-container/Dockerfile
new file mode 100644
index 0000000..868b41f
--- /dev/null
+++ b/consul-loader-container/Dockerfile
@@ -0,0 +1,23 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# 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.
+# ============LICENSE_END=========================================================
+#
+FROM ubuntu:16.04
+RUN apt-get update && apt-get install -y curl && mkdir -p /opt/app
+COPY *.sh /opt/app/
+WORKDIR /opt/app
+ENTRYPOINT ["/opt/app/consul_store.sh"]
diff --git a/consul-loader-container/README.md b/consul-loader-container/README.md
new file mode 100644
index 0000000..f3869d7
--- /dev/null
+++ b/consul-loader-container/README.md
@@ -0,0 +1,11 @@
+# DCAE Consul Loader Container
+
+The Dockerfile in this directory builds an image that can be used to spin up a container (typical a Kubernetes init container) that can load
+service registrations and key-value pairs into a Consul instance. This capability supports moving certain DCAE platform components from
+deployment using a Cloudify blueprint and the ONAP Kubernetes plugin to a Helm-based deployment. An init container can do the Consul
+setup previously handled by the ONAP Kubernetes plugin and the ONAP DCAE bootstrap script.
+
+The entrypoint for the container is the script `consul_store.sh`. See the documentation for `consul_store.sh` to see how to provide arguments to the script
+as well as how to use environment variables to set the Consul API protocol, host, and port.
+
+Note that the container runs the script to completion. It is not intended to be a long-running service. \ No newline at end of file
diff --git a/consul-loader-container/consul_store.sh b/consul-loader-container/consul_store.sh
new file mode 100755
index 0000000..4e64fc3
--- /dev/null
+++ b/consul-loader-container/consul_store.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# ================================================================================
+# Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# 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.
+# ============LICENSE_END=========================================================
+
+# Push service registrations and key-value pairs to consul
+#
+# Environment variables control the consul address used:
+# -- CONSUL_PROTO: The protocol (http or https) used to access consul. DEFAULT: http
+# -- CONSUL_HOST: The Consul host address. DEFAULT: consul
+# -- CONSUL_PORT: The Consul API port. DEFAULT: 8500
+#
+# Command line options
+# --service name|address|port : Register a service with name 'name', address 'address', and port 'port'.
+# --key keyname|filepath: Register a key-value pair with key 'keyname' and the contents of a file at 'filepath' as its value
+# A command can include multiple instances of each option.
+
+CONSUL_ADDR=${CONSUL_PROTO:-http}://${CONSUL_HOST:-consul}:${CONSUL_PORT:-8500}
+KV_URL=${CONSUL_ADDR}/v1/kv
+REG_URL=${CONSUL_ADDR}/v1/catalog/register
+
+# Register a service into Consul so that it can be discovered via the Consul service discovery API
+# $1: Name under which service is registered
+# $2: Address (typically DNS name, but can be IP) of the service
+# $3: Port used by the service
+function register_service {
+ service="{\"Node\": \"dcae\", \"Address\": \"$2\", \"Service\": {\"Service\": \"$1\", \"Address\": \"$2\", \"Port\": $3}}"
+ echo $service
+ curl -v -X PUT --data-binary "${service}" -H 'Content-Type: application/json' $REG_URL
+}
+
+# Store the contents of a file into Consul KV store
+# $1: Key under which content is stored
+# $2: Path to file whose content will be the value associated with the key
+function put_key {
+ curl -v -X PUT --data-binary @$2 -H 'Content-Type: application/json' ${KV_URL}/$1
+}
+
+set -x
+
+# Check Consul readiness
+# The readiness container waits for a "consul-server" container to be ready,
+# but this isn't always enough. We need the Consul API to be up and for
+# the cluster to be formed, otherwise our Consul accesses might fail.
+# Wait for Consul API to come up
+until curl ${CONSUL_ADDR}/v1/agent/services
+do
+ echo Waiting for Consul API
+ sleep 60
+done
+# Wait for a leader to be elected
+until [[ "$(curl -Ss {$CONSUL_ADDR}/v1/status/leader)" != '""' ]]
+do
+ echo Waiting for leader
+ sleep 30
+done
+
+while (( "$#" ))
+do
+ case $1 in
+
+ "--service")
+ # ${2//|/ } turns all of the | characters in argument 2 into spaces
+ # () uses the space delimited string to initialize an array
+ # this turns an argument like inventory-api|inventory.onap|8080 into
+ # a three-element array with elements "inventory-api", "inventory.onap", and "8080"
+ s=(${2//|/ })
+ register_service ${s[@]}
+ shift 2;
+ ;;
+ "--key")
+ # See above for explanation of (${2//|/ })
+ kv=(${2//|/ })
+ put_key ${kv[@]}
+ shift 2;
+ ;;
+ *)
+ echo "ignoring $1"
+ shift
+ ;;
+ esac
+done
diff --git a/consul-loader-container/pom.xml b/consul-loader-container/pom.xml
new file mode 100644
index 0000000..dd68443
--- /dev/null
+++ b/consul-loader-container/pom.xml
@@ -0,0 +1,172 @@
+<?xml version="1.0"?>
+<!--
+================================================================================
+Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+================================================================================
+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.
+============LICENSE_END=========================================================
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.dcaegen2.deployments</groupId>
+ <artifactId>deployments</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.onap.dcaegen2.deployments</groupId>
+ <artifactId>consul-loader-container</artifactId>
+ <name>dcaegen2-deployments-consul-loader-container</name>
+ <version>1.0.0</version>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <sonar.skip>true</sonar.skip>
+ <sonar.sources>.</sonar.sources>
+ <!-- customize the SONARQUBE URL -->
+ <!-- sonar.host.url>http://localhost:9000</sonar.host.url -->
+ <!-- below are language dependent -->
+ <!-- for Python -->
+ <sonar.language>py</sonar.language>
+ <sonar.pluginName>Python</sonar.pluginName>
+ <sonar.inclusions>**/*.py</sonar.inclusions>
+ <!-- for JavaScaript -->
+ <!--
+ <sonar.language>js</sonar.language>
+ <sonar.pluginName>JS</sonar.pluginName>
+ <sonar.inclusions>**/*.js</sonar.inclusions>
+ -->
+ </properties>
+ <build>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <plugins>
+ <!-- plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.4.1</version>
+ <configuration>
+ <descriptors>
+ <descriptor>assembly/dep.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin -->
+ <!-- now we configure custom action (calling a script) at various lifecycle phases -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.2.1</version>
+ <executions>
+ <execution>
+ <id>clean phase script</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>clean</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>generate-sources script</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>generate-sources</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>compile script</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>compile</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>package script</id>
+ <phase>package</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>package</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>test script</id>
+ <phase>test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>test</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>install script</id>
+ <phase>install</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>install</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ <execution>
+ <id>deploy script</id>
+ <phase>deploy</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <arguments>
+ <argument>${project.artifactId}</argument>
+ <argument>deploy</argument>
+ </arguments>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>