From: Jack Lucas Date: Tue, 27 Mar 2018 04:04:46 +0000 (-0400) Subject: Add k8s bootstrap container X-Git-Tag: v2.0.0~51 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=230ae894c1b2f489e31d6a0d9f7db99cf6b65cbe;p=dcaegen2%2Fdeployments.git Add k8s bootstrap container Change-Id: Ib21bd80a1e43d1005974527cecf93e99462e94fa Issue-ID: DCAEGEN2-421 Signed-off-by: Jack Lucas --- diff --git a/k8s-bootstrap-container/.gitignore b/k8s-bootstrap-container/.gitignore new file mode 100644 index 0000000..d615c60 --- /dev/null +++ b/k8s-bootstrap-container/.gitignore @@ -0,0 +1,4 @@ +.project +Dockerfile +.vscode/ +bootstrap-container.code-workspace diff --git a/k8s-bootstrap-container/Dockerfile-template b/k8s-bootstrap-container/Dockerfile-template new file mode 100644 index 0000000..300a9f6 --- /dev/null +++ b/k8s-bootstrap-container/Dockerfile-template @@ -0,0 +1,49 @@ +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +FROM centos:7.4.1708 +LABEL maintainer="maintainer" + +ENV DCAE_REPO {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }} +ENV CCSDK_REPO {{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }} +ENV BP_REPO {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases }} + +# Install gcc +RUN yum install -y gcc python-devel + +# Install pip +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ + && python get-pip.py \ + && rm get-pip.py \ + && pip install cloudify==17.11.22 + +# Get plugin archives and build wagons +RUN mkdir scripts +COPY build-plugins.sh scripts +RUN scripts/build-plugins.sh ${DCAE_REPO} ${CCSDK_REPO} \ + && rm scripts/build-plugins.sh + +# Load blueprints and input templates +COPY load-blueprints.sh scripts +RUN scripts/load-blueprints.sh ${BP_REPO} \ + && rm scripts/load-blueprints.sh + +# Set up runtime script +COPY bootstrap.sh scripts +ENTRYPOINT exec "/scripts/bootstrap.sh" \ No newline at end of file diff --git a/k8s-bootstrap-container/README.md b/k8s-bootstrap-container/README.md new file mode 100644 index 0000000..614669b --- /dev/null +++ b/k8s-bootstrap-container/README.md @@ -0,0 +1,20 @@ +# DCAE Bootstrap Container +This container is responsible for loading plugins and wagons onto the +DCAE Cloudify Manager instance and for launching DCAE components. + +The script builds plugins and loads blueprints for the DCAE components +to be deployed into the container image +at image build time. At run time, the main script in the container +(`bootstrap.sh`) uploads the plugins to Cloudify Manager, then installs +components using the blueprints. + +The container expects to be started with two environment variables: + - `CMADDR` -- the address of the target Cloudify Manager + - `CMPASS` -- the password for Cloudify Manager + +The container expects input files to use when deploying the blueprints. +It expects to find them in /inputs. The normal method for launching +the container is via a Helm Chart launched by OOM. That chart creates +a Kubernetes ConfigMap containing the input files. The ConfigMap is +mounted as a volume at /inputs. + diff --git a/k8s-bootstrap-container/bootstrap.sh b/k8s-bootstrap-container/bootstrap.sh new file mode 100755 index 0000000..38da261 --- /dev/null +++ b/k8s-bootstrap-container/bootstrap.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Install DCAE via Cloudify Manager +# Expects: +# CM address (IP or DNS) in CMADDR environment variable +# CM password in CMPASS environment variable (assumes user is "admin") +# Plugin wagon files in /wagons + +set -x + +# Deploy components +# $1 -- name (for bp and deployment) +# $2 -- blueprint name +# $3 -- inputs file name +function deploy { + cfy install -b $1 -d $1 -i /inputs/$3 /blueprints/$2 +} +# Set up profile to access CMs +cfy profiles use -u admin -t default_tenant -p "${CMPASS}" "${CMADDR}" + +# Output status, for debugging purposes +cfy status + +# Load plugins onto CM +for wagon in /wagons/*.wgn +do + cfy plugins upload ${wagon} +done + +# Deploy platform components +deploy config_binding_service k8s-config_binding_service.yaml k8s-config_binding_service-inputs.yaml +deploy inventory k8s-inventory.yaml k8s-inventory-inputs.yaml +deploy deployment_handler k8s-deployment_handler.yaml k8s-deployment_handler-inputs.yaml +deploy policy_handler k8s-policy_handler.yaml k8s-policy_handler-inputs.yaml + +# Keep the container running +# Useful to exec into it for debugging and uninstallation +while true +do + sleep 120 +done \ No newline at end of file diff --git a/k8s-bootstrap-container/build-plugins.sh b/k8s-bootstrap-container/build-plugins.sh new file mode 100755 index 0000000..9055194 --- /dev/null +++ b/k8s-bootstrap-container/build-plugins.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# org.onap.dcae +# ================================================================================ +# Copyright (c) 2018 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========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. + +# Pull plugin archives from repos +# Build wagons +# $1 is the DCAE repo URL +# $2 is the CCSDK repo URL +# (This script runs at Docker image build time) +# +set -x +DEST=wagons + +# For DCAE, we get zips of the archives and build wagons +DCAEPLUGINFILES=\ +"\ +k8splugin/1.0.0/k8splugin-1.0.0.tgz +dcaepolicyplugin/2.1.0/dcaepolicyplugin-2.1.0.tgz \ +" + +# For CCSDK, we pull down the wagon files directly +CCSDKPLUGINFILES=\ +"\ +plugins/pgaas-1.0.0-py27-none-any.wgn +plugins/sshkeyshare-1.0.0-py27-none-any.wgn +" + +# Build a set of wagon files from archives in a repo +# $1 -- repo base URL +# $2 -- list of paths to archive files in the repo +function build { + for plugin in $2 + do + # Could just do wagon create with the archive URL as source, + # but can't use a requirements file with that approach + mkdir work + target=$(basename ${plugin}) + curl -Ss $1/${plugin} > ${target} + tar zxvf ${target} --strip-components=2 -C work + wagon create -t tar.gz -o ${DEST} -r work/requirements.txt --validate ./work + rm -rf work + done +} + +# Copy a set of wagons from a repo +# $1 -- repo baseURL +# $2 -- list of paths to wagons in the repo +function get_wagons { + for wagon in $2 + do + target=$(basename ${wagon}) + curl -Ss $1/${wagon} > ${DEST}/${target} + done +} + +mkdir ${DEST} +build $1 "${DCAEPLUGINFILES}" +get_wagons $2 "${CCSDKPLUGINFILES}" \ No newline at end of file diff --git a/k8s-bootstrap-container/load-blueprints.sh b/k8s-bootstrap-container/load-blueprints.sh new file mode 100755 index 0000000..4b7270a --- /dev/null +++ b/k8s-bootstrap-container/load-blueprints.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Load DCAE blueprints/inputs onto container +# $1 Blueprint repo base URL +# Expect blueprints to be at /blueprints + +set -x + +BLUEPRINTS=\ +" +k8s-config_binding_service.yaml \ +k8s-deployment_handler.yaml \ +k8s-inventory.yaml \ +k8s-policy_handler.yaml +" + +BPDEST=blueprints +mkdir ${BPDEST} + +# Download blueprints +for bp in ${BLUEPRINTS} +do + curl -Ss $1/blueprints/${bp} > ${BPDEST}/$(basename ${bp}) +done diff --git a/k8s-bootstrap-container/pom.xml b/k8s-bootstrap-container/pom.xml new file mode 100644 index 0000000..6046a9c --- /dev/null +++ b/k8s-bootstrap-container/pom.xml @@ -0,0 +1,172 @@ + + + + 4.0.0 + + org.onap.dcaegen2.deployments + deployments + 1.2.0-SNAPSHOT + + org.onap.dcaegen2.deployments + k8s-bootstrap-container + dcaegen2-deployments-k8s-bootstrap-container + 1.0.0 + http://maven.apache.org + + UTF-8 + true + . + + + + + py + Python + **/*.py + + + + + ${project.artifactId}-${project.version} + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + clean phase script + clean + + exec + + + + ${project.artifactId} + clean + + + + + generate-sources script + generate-sources + + exec + + + + ${project.artifactId} + generate-sources + + + + + compile script + compile + + exec + + + + ${project.artifactId} + compile + + + + + package script + package + + exec + + + + ${project.artifactId} + package + + + + + test script + test + + exec + + + + ${project.artifactId} + test + + + + + install script + install + + exec + + + + ${project.artifactId} + install + + + + + deploy script + deploy + + exec + + + + ${project.artifactId} + deploy + + + + + + + + diff --git a/k8s-bootstrap-container/test-expand.sh b/k8s-bootstrap-container/test-expand.sh new file mode 100755 index 0000000..1e929f5 --- /dev/null +++ b/k8s-bootstrap-container/test-expand.sh @@ -0,0 +1,6 @@ +#!/bin/bash +sed \ + -e 's#{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}#https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R2#' \ + -e 's#{{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}#https://nexus.onap.org/service/local/repositories/raw/content/org.onap.ccsdk.platform.plugins#' \ + -e 's#{{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases }}#https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.blueprints/R2#' \ +Dockerfile-template > Dockerfile \ No newline at end of file diff --git a/mvn-phase-script.sh b/mvn-phase-script.sh index 58294da..b9f99eb 100755 --- a/mvn-phase-script.sh +++ b/mvn-phase-script.sh @@ -83,7 +83,7 @@ deploy) upload_files_of_extension sh build_and_push_docker ;; - k8s-bootstrap|tca-cdap-container|cm-container|redis-cluster-container) + k8s-bootstrap-container|tca-cdap-container|cm-container|redis-cluster-container) build_and_push_docker ;; scripts|cloud_init) diff --git a/pom.xml b/pom.xml index f233acf..2a5f941 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,7 @@ limitations under the License. redis-cluster-container tca-cdap-container cm-container + k8s-bootstrap-container