Add docker image build config file

Add python2 based services to docker_image_build_cfg_file.
The config file could then be modified to individually shift
images from python2 to python3 build method without having
to sync with cengn build scripts when there is a change.
Add --python2-wheels opt for build-stx-images.sh to specify link
to python2 based wheels tarball.

Story: 2007474
Task: 40139

Depends-on: https://review.opendev.org/#/c/712880/
Change-Id: Ic4313a2ac6f7ec2c8b87bef960f4a796f6a10738
Signed-off-by: zhipengl <zhipengs.liu@intel.com>
This commit is contained in:
zhipengl 2020-06-23 23:49:42 +08:00
parent ee5eb24836
commit 43323eb3fa
2 changed files with 40 additions and 2 deletions

View File

@ -31,12 +31,15 @@ DOCKER_USER=${USER}
DOCKER_REGISTRY=
BASE=
WHEELS=
WHEELS_ALTERNATE=
IMAGE_BUILD_CFG_FILE="docker-image-build.cfg"
CLEAN=no
TAG_LATEST=no
TAG_LIST_FILE=
TAG_LIST_LATEST_FILE=
declare -a ONLY
declare -a SKIP
declare -a SERVICES_ALTERNATE
declare -i MAX_ATTEMPTS=1
function usage {
@ -50,6 +53,7 @@ Options:
--stream: Build stream, stable or dev (default: stable)
--base: Specify base docker image (required option)
--wheels: Specify path to wheels tarball or image, URL or docker tag (required option)
--wheels-alternate: Specify path to alternate wheels tarball or image, URL or docker tag
--push: Push to docker repo
--proxy: Set proxy <URL>:<PORT>
--user: Docker repo userid
@ -329,7 +333,15 @@ function build_image_loci {
BUILD_ARGS=(--build-arg PROJECT=${PROJECT})
BUILD_ARGS+=(--build-arg PROJECT_REPO=${PROJECT_REPO})
BUILD_ARGS+=(--build-arg FROM=${BASE})
BUILD_ARGS+=(--build-arg WHEELS=${WHEELS})
if is_in ${LABEL} ${SERVICES_ALTERNATE[@]}; then
echo "Python2 service ${LABEL}"
BUILD_ARGS+=(--build-arg WHEELS=${WHEELS_ALTERNATE})
else
echo "Python3 service ${LABEL}"
BUILD_ARGS+=(--build-arg WHEELS=${WHEELS})
fi
if [ ! -z "$PROXY" ]; then
BUILD_ARGS+=(--build-arg http_proxy=$PROXY)
fi
@ -592,7 +604,7 @@ function build_image {
esac
}
OPTS=$(getopt -o h -l help,os:,version:,release:,stream:,push,proxy:,user:,registry:,base:,wheels:,only:,skip:,prefix:,latest,latest-prefix:,clean,attempts: -- "$@")
OPTS=$(getopt -o h -l help,os:,version:,release:,stream:,push,proxy:,user:,registry:,base:,wheels:,wheels-alternate:,only:,skip:,prefix:,latest,latest-prefix:,clean,attempts: -- "$@")
if [ $? -ne 0 ]; then
usage
exit 1
@ -619,6 +631,10 @@ while true; do
WHEELS=$2
shift 2
;;
--wheels-alternate)
WHEELS_ALTERNATE=$2
shift 2
;;
--version)
IMAGE_VERSION=$2
shift 2
@ -708,6 +724,26 @@ if [ -z "${WHEELS}" ]; then
exit 1
fi
# Get python2 based services from config file
if [ -f ${MY_REPO}/build-tools/build-docker-images/${IMAGE_BUILD_CFG_FILE} ]; then
SERVICES_ALTERNATE=(`source ${MY_REPO}/build-tools/build-docker-images/$IMAGE_BUILD_CFG_FILE \
&& echo ${SERVICES_ALTERNATE} | sed s/,/\ /g`)
if [ -z "${WHEELS_ALTERNATE}" ]; then
WHEELS_ALTERNATE=$(source ${MY_REPO}/build-tools/build-docker-images/$IMAGE_BUILD_CFG_FILE \
&& echo ${WHEELS_ALTERNATE})
fi
echo "SERVICES_ALTERNATE: ${SERVICES_ALTERNATE[@]}" >&2
echo "WHEELS_ALTERNATE: ${WHEELS_ALTERNATE}" >&2
else
echo "IMAGE_BUILD_CFG_FILE not found!" >&2
fi
if [ ${#SERVICES_ALTERNATE[@]} -ne 0 ] && [ -z "${WHEELS_ALTERNATE}" ]; then
echo "Path to wheels-alternate tarball must be specified with --wheels-alternate option"\
"if python2 based services need to be build!" >&2
exit 1
fi
if [ -z "${BASE}" ]; then
echo "Base image must be specified with --base option." >&2
exit 1

View File

@ -0,0 +1,2 @@
SERVICES_ALTERNATE=stx-fm-rest-api,stx-keystone-api-proxy,stx-nova-api-proxy,stx-platformclients
WHEELS_ALTERNATE=http://mirror.starlingx.cengn.ca/mirror/starlingx/master/centos/stx-centos-py2_stable-wheels.tar