Add Docker build file template

Add Docker build file template and a module to create customized
build file.

Change-Id: Ie67573797362befb3546f64788a790c9c4bd33aa
This commit is contained in:
Catherine Diep 2014-03-04 21:23:32 -08:00
parent 695ce75eeb
commit 3b734153b2
2 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,74 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014 IBM Corp.
#
# 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.
from jinja2 import FileSystemLoader, Environment
import os
class DockerBuildFile(object):
'''*
Build a docker buildfile with customized parameters from a pre-defined
docker build file template.
'''
test_id = None
api_server_address = None
tempest_code_url = None
confJSON = None
def build_docker_buildfile(self, output_file_with_path):
'''*
Build a docker build file based on a pre-defined template.
This method assumes that the caller has already initialized all the
needed parameters for customization.
'''
docker_template_dir = os.path.dirname(os.path.abspath(__file__))
template_file_with_path = os.path.join(docker_template_dir,
"docker_buildfile.template")
values = {"THE_TEST_ID": self.test_id,
"THE_API_SERVER_ADDRESS": self.api_server_address,
"THE_TEMPEST_CODE_URL": self.tempest_code_url,
"THE_CONF_JSON": self.confJSON
}
template_filling(template_file_with_path, output_file_with_path,
values)
def template_filling(template_file_with_path,
output_file_with_path, value_dict):
'''Filling values in a template file.'''
outputText = ""
if os.path.isfile(template_file_with_path):
input_dir = os.path.dirname(os.path.abspath(template_file_with_path))
file_name = os.path.basename(template_file_with_path)
j2_env = Environment(loader=FileSystemLoader(input_dir),
trim_blocks=True)
template = j2_env.get_template(file_name)
outputText = template.render(value_dict)
output_dir = os.path.dirname(os.path.abspath(output_file_with_path))
if not os.path.exists(output_dir):
os.makedirs(output_dir)
with open(output_file_with_path, "wt") as fout:
fout.write(outputText)

View File

@ -0,0 +1,39 @@
FROM ubuntu
RUN apt-get update
#Downloading tools
RUN apt-get install -y git python-pip wget unzip
#Downloading dependencies
RUN apt-get install -y libxml2-dev libxslt-dev lib32z1-dev python2.7-dev libssl-dev
#other dependencies
RUN apt-get install -y python-dev libxslt1-dev libsasl2-dev libsqlite3-dev libldap2-dev libffi-dev
RUN pip install ftp://xmlsoft.org/libxml2/python/libxml2-python-2.6.9.tar.gz
#Get tempest code
#THE_TEMPEST_CODE_URL should be replaced with an appropriate address. For example:
#replace THE_TEMPEST_CODE_URL with https://github.com/openstack/tempest/archive/stable/havana.zip
RUN wget {{ THE_TEMPEST_CODE_URL }} -O tempest.zip
RUN unzip tempest.zip
RUN mv /tempest-stable* /tempest
#Tempest dependencies
RUN pip install -r /tempest/requirements.txt
RUN pip install -r /tempest/test-requirements.txt
#THE_API_SERVER_ADDRESS should be replaced with the real IP address of the RefStack engine (local or public).
#The format of THE_API_SERVER_ADDRESS is x.x.x.x:port
ENV API_SERVER_ADDRESS {{ THE_API_SERVER_ADDRESS }}
#THE_TEST_ID should be replaced with an unique ID associated with this test,
#so that the following commands will always be executed.
ENV TEST_ID {{ THE_TEST_ID }}
#Download the Python script to the container. This script will be used to prepare
#the test environment, run tempest tests and upload the test results to RefStack.
RUN wget http://${API_SERVER_ADDRESS}/get-script -O execute_test.py
# Run the script
RUN python execute_test.py ${API_SERVER_ADDRESS} ${TEST_ID} '{{ THE_CONF_JSON }}'
RUN echo "done"