summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor Bramwell <tbramwell@linuxfoundation.org>2017-11-10 15:25:33 -0800
committerTrevor Bramwell <tbramwell@linuxfoundation.org>2017-11-10 15:30:05 -0800
commit48a16b2f416af135a60e92e1292bb126ba38523c (patch)
tree822f6f5f93dbc322779eab552a335bb33184b2c4
parent5dba82b4e8b5560eb726603d290698ca4c22ea11 (diff)
Initial Commit CI Files
These files come from the releng repository and are used in the automated deploy of testapi. Moving them into this repository removes the need to clone multiple repositories when deploying the testapi site and verifying the repository. Change-Id: Ibd54c47bd76e3f2d801cfb4eaaeb1623bd1ae7b9 Signed-off-by: Trevor Bramwell <tbramwell@linuxfoundation.org>
-rw-r--r--ci/docker-update.sh34
-rw-r--r--ci/htmlize/doc-build.sh37
-rw-r--r--ci/htmlize/htmlize.py57
-rw-r--r--ci/htmlize/push-doc-artifact.sh27
-rw-r--r--ci/testapi-backup-mongodb.sh31
5 files changed, 186 insertions, 0 deletions
diff --git a/ci/docker-update.sh b/ci/docker-update.sh
new file mode 100644
index 0000000..6c6a554
--- /dev/null
+++ b/ci/docker-update.sh
@@ -0,0 +1,34 @@
+#!/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. *
+
+set -o errexit
+set -o nounset
+
+cd $WORKSPACE/$MODULE_NAME/docker/
+
+# Remove previous containers
+docker ps -a | grep "opnfv/$MODULE_NAME" | awk '{ print $1 }' | xargs -r docker rm -f
+
+# Remove previous images
+docker images | grep "opnfv/$MODULE_NAME" | awk '{ print $3 }' | xargs -r docker rmi -f
+
+# Start build
+docker build --no-cache -t opnfv/$MODULE_NAME:$DOCKER_TAG .
+
+# Push Image
+docker push opnfv/$MODULE_NAME:$DOCKER_TAG
diff --git a/ci/htmlize/doc-build.sh b/ci/htmlize/doc-build.sh
new file mode 100644
index 0000000..f775b79
--- /dev/null
+++ b/ci/htmlize/doc-build.sh
@@ -0,0 +1,37 @@
+#!/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. *
+
+set -o errexit
+
+# Create virtual environment
+virtualenv $WORKSPACE/testapi_venv
+source $WORKSPACE/testapi_venv/bin/activate
+
+# Swgger Codegen Tool
+url="http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar"
+
+# Check for jar file locally and in the repo
+if [ ! -f swagger-codegen-cli.jar ];
+then
+ wget http://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.2.1/swagger-codegen-cli-2.2.1.jar -O swagger-codegen-cli.jar
+fi
+
+# Install Pre-requistics
+pip install requests
+
+python $WORKSPACE/ci/htmlize/htmlize.py -o ${WORKSPACE}/
diff --git a/ci/htmlize/htmlize.py b/ci/htmlize/htmlize.py
new file mode 100644
index 0000000..da6a6cf
--- /dev/null
+++ b/ci/htmlize/htmlize.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+# 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
+
+import argparse
+import requests
+import json
+import os
+
+
+def main(args):
+
+ # Merging two specs
+ api_response = requests.get(args.api_declaration_url)
+ api_response = json.loads(api_response.content)
+ resource_response = requests.get(args.resource_listing_url)
+ resource_response = json.loads(resource_response.content)
+ resource_response['models'] = api_response['models']
+ resource_response['apis'] = api_response['apis']
+
+ # Storing the swagger specs
+ with open('specs.json', 'w') as outfile:
+ json.dump(resource_response, outfile)
+
+ # Generating html page
+ cmd = 'java -jar swagger-codegen-cli.jar generate \
+ -i specs.json -l html2 -o %s' % (args.output_directory)
+ if os.system(cmd) == 0:
+ exit(0)
+ else:
+ exit(1)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='Create \
+ Swagger Spec documentation')
+ parser.add_argument('-ru', '--resource-listing-url',
+ type=str,
+ required=False,
+ default=('http://testresults.opnfv.org'
+ '/test/swagger/resources.json'),
+ help='Resource Listing Spec File')
+ parser.add_argument('-au', '--api-declaration-url',
+ type=str,
+ required=False,
+ default=('http://testresults.opnfv.org'
+ '/test/swagger/APIs'),
+ help='API Declaration Spec File')
+ parser.add_argument('-o', '--output-directory',
+ required=True,
+ default='./',
+ help='Output Directory where the \
+ file should be stored')
+ main(parser.parse_args())
diff --git a/ci/htmlize/push-doc-artifact.sh b/ci/htmlize/push-doc-artifact.sh
new file mode 100644
index 0000000..e6432d3
--- /dev/null
+++ b/ci/htmlize/push-doc-artifact.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -e
+set -o pipefail
+
+export PATH=$PATH:/usr/local/bin/
+
+project=$PROJECT
+workspace=$WORKSPACE
+artifact_dir="$project/docs"
+
+set +e
+gsutil&>/dev/null
+if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed"
+ exit 1
+else
+ gsutil ls gs://artifacts.opnfv.org/"$project"/ &>/dev/null
+ if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed."
+ exit 1
+ else
+ echo "Uploading document to artifact $artifact_dir"
+ gsutil cp "$workspace"/index.html gs://artifacts.opnfv.org/"$artifact_dir"/testapi.html >/dev/null 2>&1
+ echo "Document can be found at http://artifacts.opnfv.org/releng-testresults/docs/testapi.html"
+ fi
+fi
diff --git a/ci/testapi-backup-mongodb.sh b/ci/testapi-backup-mongodb.sh
new file mode 100644
index 0000000..e6465ab
--- /dev/null
+++ b/ci/testapi-backup-mongodb.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -e
+
+# Run MongoDB backup
+python $WORKSPACE/testapi/update/templates/backup_mongodb.py -o $WORKSPACE/
+
+# Compressing the dump
+now=$(date +"%m_%d_%Y_%H_%M_%S")
+echo $now
+
+file_name="testapi_mongodb_"$now".tar.gz"
+echo $file_name
+
+tar cvfz "$file_name" test_results_collection*
+
+rm -rf test_results_collection*
+
+artifact_dir="testapibackup"
+workspace="$WORKSPACE"
+
+set +e
+/usr/local/bin/gsutil &>/dev/null
+if [ $? != 0 ]; then
+ echo "Not possible to push results to artifact: gsutil not installed"
+ exit 1
+else
+ echo "Uploading mongodump to artifact $artifact_dir"
+ /usr/local/bin/gsutil cp -r "$workspace"/"$file_name" gs://artifacts.opnfv.org/"$artifact_dir"/
+ echo "MongoDump can be found at http://artifacts.opnfv.org/$artifact_dir.html"
+fi