Create Docker image and build in Zuul
Change-Id: I9de51069c8302ac44711f08f0d396d09389b0067 Story: 2001694 Topic: 29771
This commit is contained in:
parent
f1d457fc79
commit
71817e2ede
|
@ -11,6 +11,7 @@
|
|||
- monasca-tempest-python2-cassandra
|
||||
- monascalog-python2-tempest
|
||||
- monascalog-python3-tempest
|
||||
- docker-build-monasca-service
|
||||
gate:
|
||||
queue: monasca
|
||||
jobs:
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
ARG DOCKER_IMAGE=monasca/tempest
|
||||
ARG APP_REPO=https://git.openstack.org/openstack/monasca-tempest-plugin
|
||||
|
||||
# Branch, tag or git hash to build from.
|
||||
ARG REPO_VERSION=master
|
||||
ARG CONSTRAINTS_BRANCH=master
|
||||
|
||||
# Extra Python3 dependencies.
|
||||
ARG EXTRA_DEPS="python-openstackclient"
|
||||
|
||||
# Always start from `monasca-base` image and use specific tag of it.
|
||||
ARG BASE_TAG=master
|
||||
FROM monasca/base:$BASE_TAG
|
||||
|
||||
# Environment variables used for our service or wait scripts.
|
||||
ENV \
|
||||
MONASCA_URI=http://monasca:8070 \
|
||||
KEYSTONE_IDENTITY_URI=http://keystone:35357 \
|
||||
USE_DYNAMIC_CREDS=True \
|
||||
KEYSTONE_ADMIN_USER=mini-mon \
|
||||
KEYSTONE_ADMIN_PASSWORD=password \
|
||||
KEYSTONE_ADMIN_PROJECT=mini-mon \
|
||||
KEYSTONE_ADMIN_DOMAIN=Default \
|
||||
OS_AUTH_URL=http://keystone:35357/v3 \
|
||||
OS_USERNAME=mini-mon \
|
||||
OS_PASSWORD=password \
|
||||
OS_TENANT_NAME=mini-mon \
|
||||
OS_DOMAIN_NAME=Default \
|
||||
STAY_ALIVE_ON_FAILURE=false
|
||||
|
||||
# Copy all neccessary files to proper locations.
|
||||
COPY tempest.conf.j2 /etc/tempest/
|
||||
|
||||
WORKDIR /tempest
|
||||
|
||||
# Run here all additionals steps your service need post installation.
|
||||
# Stay with only one `RUN` and use `&& \` for next steps to don't create
|
||||
# unnecessary image layers. Clean at the end to conserve space.
|
||||
#RUN \
|
||||
# echo "Some steps to do after main installation." && \
|
||||
# echo "Hello when building."
|
||||
|
||||
# Implement start script in `start.sh` file.
|
||||
CMD ["/start.sh"]
|
|
@ -0,0 +1,112 @@
|
|||
===============================================
|
||||
Docker image for Monasca Monasca Temptest tests
|
||||
===============================================
|
||||
This image could be used for running Tempest tests on Monasca installed in any
|
||||
way. After providing proper environment variables container could be started
|
||||
and will run tests based on what endpoints it will find in configured Keystone.
|
||||
Supported endpoints are ``monitoring`` and ``logs`` (``Service Type`` in
|
||||
``openstack endpoint list`` output).
|
||||
|
||||
|
||||
Building monasca-base image
|
||||
===========================
|
||||
See https://github.com/openstack/monasca-common/tree/master/docker/README.rst
|
||||
|
||||
|
||||
Building Docker image
|
||||
=====================
|
||||
|
||||
Example:
|
||||
$ ./build_image.sh <repository_version> <upper_constrains_branch> <common_version>
|
||||
|
||||
Everything after ``./build_image.sh`` is optional and by default configured
|
||||
to get versions from ``Dockerfile``. ``./build_image.sh`` also contain more
|
||||
detailed build description.
|
||||
|
||||
|
||||
How to start
|
||||
~~~~~~~~~~~~
|
||||
|
||||
When using running Monasca in Docker you can connect this image to the network
|
||||
where Monasca is accessible and run all tests.
|
||||
Find network on machine with Monasca with ``docker network ls``.
|
||||
For example you can see similar information to:
|
||||
``e20533f6112c monasca-docker_default bridge local``
|
||||
|
||||
Using this network run all tempest tests with following command:
|
||||
|
||||
``docker run -it --rm --network=monasca-docker_default monasca/tempest:master``
|
||||
|
||||
It's important to configure all necessary connection environment variables.
|
||||
They are listed in the next two sections.
|
||||
|
||||
Example command to run tempest tests with custom variables::
|
||||
|
||||
``docker run -it --rm --network=monasca-docker_default --env-file=tempest_con.env monasca/tempest:master``
|
||||
|
||||
In this example you configure all environment variables in ``tempest_con.env``
|
||||
file::
|
||||
|
||||
MONASCA_URI=172.17.0.1:8070
|
||||
KEYSTONE_IDENTITY_URI=http://172.17.0.1:35357
|
||||
USE_DYNAMIC_CREDS=True
|
||||
KEYSTONE_ADMIN_USER=mini-mon
|
||||
KEYSTONE_ADMIN_PASSWORD=password
|
||||
KEYSTONE_ADMIN_PROJECT=mini-mon
|
||||
KEYSTONE_ADMIN_DOMAIN=Default
|
||||
OS_AUTH_URL=http://172.17.0.1:35357/v3
|
||||
OS_USERNAME=mini-mon
|
||||
OS_PASSWORD=password
|
||||
OS_PROJECT_NAME=mini-mon
|
||||
OS_DOMAIN_NAME=Default
|
||||
|
||||
|
||||
Environment variables
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
========================= ============================== ==========================================
|
||||
Variable Default Description
|
||||
========================= ============================== ==========================================
|
||||
USE_DYNAMIC_CREDS True Create dynamic credentials for tests
|
||||
KEYSTONE_ADMIN_USER mini-mon OpenStack administrator user name
|
||||
KEYSTONE_ADMIN_PASSWORD password OpenStack administrator user password
|
||||
KEYSTONE_ADMIN_PROJECT mini-mon OpenStack administrator tenant name
|
||||
KEYSTONE_ADMIN_DOMAIN Default OpenStack administrator domain
|
||||
OS_AUTH_URL http://keystone:35357/v3 Versioned Keystone URL
|
||||
OS_USERNAME mini-mon Keystone user name
|
||||
OS_PASSWORD password Keystone user password
|
||||
OS_PROJECT_NAME mini-mon Keystone user project name
|
||||
OS_DOMAIN_NAME Default Keystone user domain name
|
||||
IDENTITY_URI http://keystone:35357/v2.0/ Full URI of the Keystone, v2
|
||||
IDENTITY_URI_V3 http://keystone:35357/v3/ Full URI of the Keystone, v3
|
||||
LOG_LEVEL INFO Log level for root logging
|
||||
STAY_ALIVE_ON_FAILURE false If true, container runs 2 hours after service fail
|
||||
========================= ============================== ==========================================
|
||||
|
||||
|
||||
Wait scripts environment variables
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
========================= ============================== ==========================================
|
||||
Variable Default Description
|
||||
========================= ============================== ==========================================
|
||||
MONASCA_URI http://monasca:8070 The metric pipeline endpoint
|
||||
KEYSTONE_IDENTITY_URI http://keystone:35357 URI to Keystone admin endpoint
|
||||
========================= ============================== ==========================================
|
||||
|
||||
|
||||
Scripts
|
||||
~~~~~~~
|
||||
start.sh
|
||||
In this starting script provide all steps that lead to the proper service
|
||||
start. Including usage of wait scripts and templating of configuration
|
||||
files. You also could provide the ability to allow running container after
|
||||
service died for easier debugging.
|
||||
|
||||
health_check.py
|
||||
This file will be used for checking the status of the application.
|
||||
|
||||
|
||||
Links
|
||||
~~~~~
|
||||
https://docs.openstack.org/monasca-api/latest/
|
||||
|
||||
https://github.com/openstack/monasca-api/blob/master/README.rst
|
|
@ -0,0 +1,150 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 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.
|
||||
|
||||
# TODO(Dobroslaw): move this script to monasca-common/docker folder
|
||||
# and leave here small script to download it and execute using env variables
|
||||
# to minimize code duplication.
|
||||
|
||||
set -x # Print each script step.
|
||||
set -eo pipefail # Exit the script if any statement returns error.
|
||||
|
||||
# This script is used for building Docker image with proper labels
|
||||
# and proper version of monasca-common.
|
||||
#
|
||||
# Example usage:
|
||||
# $ ./build_image.sh <repository_version> <upper_constains_branch> <common_version>
|
||||
#
|
||||
# Everything after `./build_image.sh` is optional and by default configured
|
||||
# to get versions from `Dockerfile`.
|
||||
#
|
||||
# To build from master branch (default):
|
||||
# $ ./build_image.sh
|
||||
# To build specific version run this script in the following way:
|
||||
# $ ./build_image.sh stable/queens
|
||||
# Building from specific commit:
|
||||
# $ ./build_image.sh cb7f226
|
||||
# When building from a tag monasca-common will be used in version available
|
||||
# in upper constraint file:
|
||||
# $ ./build_image.sh 2.5.0
|
||||
# To build image from Gerrit patch sets that is targeting branch stable/queens:
|
||||
# $ ./build_image.sh refs/changes/51/558751/1 stable/queens
|
||||
#
|
||||
# If you want to build image with custom monasca-common version you need
|
||||
# to provide it as in the following example:
|
||||
# $ ./build_image.sh master master refs/changes/19/595719/3
|
||||
|
||||
# Go to folder with Docker files.
|
||||
REAL_PATH=$(python -c "import os,sys; print(os.path.realpath('$0'))")
|
||||
cd "$(dirname "$REAL_PATH")/../docker/"
|
||||
|
||||
[ -z "$DOCKER_IMAGE" ] && \
|
||||
DOCKER_IMAGE=$(\grep DOCKER_IMAGE Dockerfile | cut -f2 -d"=")
|
||||
|
||||
: "${REPO_VERSION:=$1}"
|
||||
[ -z "$REPO_VERSION" ] && \
|
||||
REPO_VERSION=$(\grep REPO_VERSION Dockerfile | cut -f2 -d"=")
|
||||
# Let's stick to more readable version and disable SC2001 here.
|
||||
# shellcheck disable=SC2001
|
||||
REPO_VERSION_CLEAN=$(echo "$REPO_VERSION" | sed 's|/|-|g')
|
||||
|
||||
[ -z "$APP_REPO" ] && APP_REPO=$(\grep APP_REPO Dockerfile | cut -f2 -d"=")
|
||||
GITHUB_REPO=$(echo "$APP_REPO" | sed 's/git.openstack.org/github.com/' | \
|
||||
sed 's/ssh:/https:/')
|
||||
|
||||
if [ -z "$CONSTRAINTS_FILE" ]; then
|
||||
CONSTRAINTS_FILE=$(\grep CONSTRAINTS_FILE Dockerfile | cut -f2 -d"=") || true
|
||||
: "${CONSTRAINTS_FILE:=http://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt}"
|
||||
fi
|
||||
|
||||
: "${CONSTRAINTS_BRANCH:=$2}"
|
||||
[ -z "$CONSTRAINTS_BRANCH" ] && \
|
||||
CONSTRAINTS_BRANCH=$(\grep CONSTRAINTS_BRANCH Dockerfile | cut -f2 -d"=")
|
||||
|
||||
# When using stable version of repository use same stable constraints file.
|
||||
case "$REPO_VERSION" in
|
||||
*stable*)
|
||||
CONSTRAINTS_BRANCH_CLEAN="$REPO_VERSION"
|
||||
# Get monasca-common version from stable upper constraints file.
|
||||
CONSTRAINTS_TMP_FILE=$(mktemp)
|
||||
wget --output-document "$CONSTRAINTS_TMP_FILE" \
|
||||
"$CONSTRAINTS_FILE"?h="$CONSTRAINTS_BRANCH_CLEAN"
|
||||
UPPER_COMMON=$(\grep 'monasca-common' "$CONSTRAINTS_TMP_FILE")
|
||||
# Get only version part from monasca-common.
|
||||
UPPER_COMMON_VERSION="${UPPER_COMMON##*===}"
|
||||
rm -rf "$CONSTRAINTS_TMP_FILE"
|
||||
;;
|
||||
*)
|
||||
CONSTRAINTS_BRANCH_CLEAN="$CONSTRAINTS_BRANCH"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Monasca-common variables.
|
||||
if [ -z "$COMMON_REPO" ]; then
|
||||
COMMON_REPO=$(\grep COMMON_REPO Dockerfile | cut -f2 -d"=") || true
|
||||
: "${COMMON_REPO:=https://git.openstack.org/openstack/monasca-common}"
|
||||
fi
|
||||
: "${COMMON_VERSION:=$3}"
|
||||
if [ -z "$COMMON_VERSION" ]; then
|
||||
COMMON_VERSION=$(\grep COMMON_VERSION Dockerfile | cut -f2 -d"=") || true
|
||||
if [ "$UPPER_COMMON_VERSION" ]; then
|
||||
# Common from upper constraints file.
|
||||
COMMON_VERSION="$UPPER_COMMON_VERSION"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clone project to temporary directory for getting proper commit number from
|
||||
# branches and tags. We need this for setting proper image labels.
|
||||
# Docker does not allow to get any data from inside of system when building
|
||||
# image.
|
||||
TMP_DIR=$(mktemp -d)
|
||||
(
|
||||
cd "$TMP_DIR"
|
||||
# This many steps are needed to support gerrit patch sets.
|
||||
git init
|
||||
git remote add origin "$APP_REPO"
|
||||
git fetch origin "$REPO_VERSION"
|
||||
git reset --hard FETCH_HEAD
|
||||
)
|
||||
GIT_COMMIT=$(git -C "$TMP_DIR" rev-parse HEAD)
|
||||
[ -z "${GIT_COMMIT}" ] && echo "No git commit hash found" && exit 1
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
# Do the same for monasca-common.
|
||||
COMMON_TMP_DIR=$(mktemp -d)
|
||||
(
|
||||
cd "$COMMON_TMP_DIR"
|
||||
# This many steps are needed to support gerrit patch sets.
|
||||
git init
|
||||
git remote add origin "$COMMON_REPO"
|
||||
git fetch origin "$COMMON_VERSION"
|
||||
git reset --hard FETCH_HEAD
|
||||
)
|
||||
COMMON_GIT_COMMIT=$(git -C "$COMMON_TMP_DIR" rev-parse HEAD)
|
||||
[ -z "${COMMON_GIT_COMMIT}" ] && echo "No git commit hash found" && exit 1
|
||||
rm -rf "$COMMON_TMP_DIR"
|
||||
|
||||
CREATION_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
docker build --no-cache \
|
||||
--build-arg CREATION_TIME="$CREATION_TIME" \
|
||||
--build-arg GITHUB_REPO="$GITHUB_REPO" \
|
||||
--build-arg APP_REPO="$APP_REPO" \
|
||||
--build-arg REPO_VERSION="$REPO_VERSION" \
|
||||
--build-arg GIT_COMMIT="$GIT_COMMIT" \
|
||||
--build-arg CONSTRAINTS_FILE="$CONSTRAINTS_FILE" \
|
||||
--build-arg CONSTRAINTS_BRANCH="$CONSTRAINTS_BRANCH_CLEAN" \
|
||||
--build-arg COMMON_REPO="$COMMON_REPO" \
|
||||
--build-arg COMMON_VERSION="$COMMON_VERSION" \
|
||||
--build-arg COMMON_GIT_COMMIT="$COMMON_GIT_COMMIT" \
|
||||
--tag "$DOCKER_IMAGE":"$REPO_VERSION_CLEAN" .
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
# (C) Copyright 2018 FUJITSU LIMITED
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""Health check will returns 0 when service is working properly."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
LOG_LEVEL = logging.getLevelName(os.environ.get('LOG_LEVEL', 'INFO'))
|
||||
logging.basicConfig(level=LOG_LEVEL)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
logger.debug('No health check for tempest')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
|
||||
# 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.
|
||||
|
||||
# Starting script.
|
||||
# All checks and configuration templating you need to do before service
|
||||
# could be safely started should be added in this file.
|
||||
|
||||
set -x
|
||||
|
||||
set -eo pipefail # Exit the script if any statement returns error.
|
||||
|
||||
# Test services we need before starting our service.
|
||||
echo "Start script: waiting for needed services"
|
||||
/wait_for.sh "$MONASCA_URI"
|
||||
/wait_for.sh "$KEYSTONE_IDENTITY_URI"
|
||||
|
||||
# Template all config files before start, it will use env variables.
|
||||
# Read usage examples: https://pypi.org/project/Templer/
|
||||
echo "Start script: creating config files from templates"
|
||||
templer -v -f /etc/tempest/tempest.conf.j2 /etc/tempest/tempest.conf
|
||||
|
||||
# Start our service.
|
||||
echo "Start script: starting tempest"
|
||||
cd /tempest/
|
||||
# Initialize only when folder is empty.
|
||||
if [ ! "$(ls -A /tempest/)" ]; then
|
||||
tempest init
|
||||
fi
|
||||
tempest list-plugins
|
||||
|
||||
if openstack endpoint list --column "Service Type" -f value | grep -q monitoring
|
||||
then
|
||||
tempest run -r monasca_tempest_tests.tests.api
|
||||
else
|
||||
true
|
||||
fi
|
||||
if openstack endpoint list --column "Service Type" -f value | grep -q logs
|
||||
then
|
||||
tempest run -r monasca_tempest_tests.tests.log_api
|
||||
else
|
||||
true
|
||||
fi
|
||||
|
||||
# Allow server to stay alive in case of failure for 2 hours for debugging.
|
||||
RESULT=$?
|
||||
if [ $RESULT != 0 ] && [ "$STAY_ALIVE_ON_FAILURE" = "true" ]; then
|
||||
echo "Service died, waiting 120 min before exiting"
|
||||
sleep 7200
|
||||
fi
|
||||
exit $RESULT
|
|
@ -0,0 +1,11 @@
|
|||
[identity]
|
||||
auth_version = v3
|
||||
uri = {{ AUTH_URI | default(KEYSTONE_IDENTITY_URI + "/v2.0/") }}
|
||||
uri_v3 = {{ AUTH_URI_V3 | default(KEYSTONE_IDENTITY_URI + "/v3/") }}
|
||||
|
||||
[auth]
|
||||
use_dynamic_credentials = {{ USE_DYNAMIC_CREDS }}
|
||||
admin_username = {{ KEYSTONE_ADMIN_USER }}
|
||||
admin_password = {{ KEYSTONE_ADMIN_PASSWORD }}
|
||||
admin_project_name = {{ KEYSTONE_ADMIN_PROJECT }}
|
||||
admin_domain_name = {{ KEYSTONE_ADMIN_DOMAIN }}
|
Loading…
Reference in New Issue