Update from upstream

This commit is contained in:
Lumir Balhar 2021-12-06 07:09:18 +01:00
commit b3bc61b518
7 changed files with 78 additions and 29 deletions

View file

@ -1,4 +1,4 @@
FROM #IMAGE_NAME# # Replaced by sed in tests, see test_from_dockerfile in test/run
FROM #IMAGE_NAME# # Replaced by sed in ct_test_app_dockerfile
# Add application sources to a directory that the assemble script expects them
# and set permissions so that the container runs without root access

View file

@ -1,4 +1,4 @@
FROM #IMAGE_NAME# # Replaced by sed in tests, see test_from_dockerfile in test/run
FROM #IMAGE_NAME# # Replaced by sed in ct_test_app_dockerfile
# Add application sources with correct permissions for OpenShift
USER 0

View file

@ -6,7 +6,7 @@
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#
declare -a WEB_APPS=({gunicorn-config-different-port,gunicorn-different-port,django-different-port,standalone,setup,setup-requirements,django,numpy,app-home,npm-virtualenv-uwsgi,locale,mod-wsgi,pipenv,pipenv-and-micropipenv-should-fail,pin-pipenv-version,app-module,micropipenv,micropipenv-requirements}-test-app)
declare -a WEB_APPS=({gunicorn-config-different-port,gunicorn-different-port,django-different-port,standalone,setup,setup-cfg,setup-requirements,django,numpy,app-home,npm-virtualenv-uwsgi,locale,mod-wsgi,pipenv,pipenv-and-micropipenv-should-fail,pin-pipenv-version,app-module,micropipenv,micropipenv-requirements}-test-app)
# TODO: Make command compatible for Mac users
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
@ -223,13 +223,11 @@ test_from_dockerfile(){
django_example_repo_url="https://github.com/sclorg/django-ex.git@2.2.x"
fi
sed "s@#IMAGE_NAME#@${IMAGE_NAME}@" $test_dir/from-dockerfile/Dockerfile.tpl > $test_dir/from-dockerfile/Dockerfile
ct_test_app_dockerfile $test_dir/from-dockerfile/Dockerfile $django_example_repo_url 'Welcome to your Django application on OpenShift' app-src
ct_test_app_dockerfile $test_dir/from-dockerfile/Dockerfile.tpl $django_example_repo_url 'Welcome to your Django application on OpenShift' app-src
check_result $?
info "Test from Dockerfile with no s2i scripts used"
sed "s@#IMAGE_NAME#@${IMAGE_NAME}@" $test_dir/from-dockerfile/Dockerfile_no_s2i.tpl > $test_dir/from-dockerfile/Dockerfile
ct_test_app_dockerfile $test_dir/from-dockerfile/Dockerfile $django_example_repo_url 'Welcome to your Django application on OpenShift' app-src
ct_test_app_dockerfile $test_dir/from-dockerfile/Dockerfile_no_s2i.tpl $django_example_repo_url 'Welcome to your Django application on OpenShift' app-src
check_result $?
}

View file

@ -150,6 +150,16 @@ function ct_os_get_build_pod_status() {
| sort -u | awk '{print $2}' | tail -n 1
}
# ct_os_get_buildconfig_pod_name POD_PREFIX
# ----------------------------
# Returns status of the buildconfig pod specified by prefix [pod_prefix].
# Argument: pod_prefix - prefix
function ct_os_get_buildconfig_pod_name() {
local pod_prefix="${1}" ; shift
local query="custom-columns=NAME:.metadata.name"
oc get bc -o "$query" | grep -e "${pod_prefix}" | sort -u | tail -n 1
}
# ct_os_get_pod_name POD_PREFIX
# --------------------
# Returns the full name of pods specified by prefix [pod_prefix].
@ -169,6 +179,22 @@ function ct_os_get_pod_ip() {
oc get pod "$pod_name" --no-headers -o custom-columns=IP:status.podIP
}
# ct_os_get_sti_build_logs
# -----------------
# Return logs from sti_build
# Arguments: pod_name
function ct_os_get_sti_build_logs() {
local pod_prefix="${1}"
pod_name=$(ct_os_get_buildconfig_pod_name "${pod_prefix}")
# Print logs but do not failed. Just for traces
if [ x"${pod_name}" != "x" ]; then
oc logs "bc/$pod_name" || return 0
else
echo "Build config bc/$pod_name does not exist for some reason."
echo "Import probably failed."
fi
}
# ct_os_check_pod_readiness POD_PREFIX STATUS
# --------------------
# Checks whether the pod is ready.
@ -195,7 +221,12 @@ function ct_os_wait_pod_ready() {
echo -n "Waiting for ${pod_prefix} build pod to finish ..."
while ! [ "$(ct_os_get_build_pod_status "${pod_prefix}")" == "Succeeded" ] ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}0" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}0" ]; then
echo " FAIL"
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -204,7 +235,12 @@ function ct_os_wait_pod_ready() {
echo -n "Waiting for ${pod_prefix} pod becoming ready ..."
while ! ct_os_check_pod_readiness "${pod_prefix}" "true" ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}" ]; then
echo " FAIL";
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -223,7 +259,12 @@ function ct_os_wait_rc_ready() {
while ! test "$( (oc get --no-headers statefulsets; oc get --no-headers rc) 2>/dev/null \
| grep "^${pod_prefix}" | awk '$2==$3 {print "ready"}')" == "ready" ; do
echo -n "."
[ "${SECONDS}" -gt "${timeout}" ] && echo " FAIL" && return 1
if [ "${SECONDS}" -gt "${timeout}" ]; then
echo " FAIL";
ct_os_print_logs || :
ct_os_get_sti_build_logs "${pod_prefix}" || :
return 1
fi
sleep 3
done
echo " DONE"
@ -331,7 +372,12 @@ function ct_os_delete_project() {
return
fi
local project_name="${1:-$(oc project -q)}" ; shift || :
oc delete project "${project_name}"
if oc delete project "${project_name}" ; then
echo "Project ${project_name} was deleted properly"
else
echo "Project ${project_name} was not delete properly. But it does not block CI."
fi
}
# ct_delete_all_objects

View file

@ -827,7 +827,7 @@ ct_show_resources()
# -----------------------------
# Argument: dockerfile - path to a Dockerfile that will be used for building an image
# (must work with an application directory called 'app-src')
# Argument: app_url - git URI with a testing application, supports "@" to indicate a different branch
# Argument: app_url - git or local URI with a testing application, supports "@" to indicate a different branch
# Argument: body_regexp - PCRE regular expression that must match the response body
# Argument: app_dir - name of the application directory that is used in the Dockerfile
# Argument: port - Optional port number (default: 8080)
@ -865,20 +865,25 @@ ct_test_app_dockerfile() {
echo "Using this Dockerfile:"
cat Dockerfile
# If app_url contains @, the string after @ is considered
# as a name of a branch to clone instead of the main/master branch
IFS='@' read -ra git_url_parts <<< "${app_url}"
if [ -n "${git_url_parts[1]}" ]; then
git_clone_cmd="git clone --branch ${git_url_parts[1]} ${git_url_parts[0]} ${app_dir}"
if [ -d "$app_url" ] ; then
echo "Copying local folder: $app_url -> $app_dir."
cp -Lr $app_url $app_dir
else
git_clone_cmd="git clone ${app_url} ${app_dir}"
fi
# If app_url contains @, the string after @ is considered
# as a name of a branch to clone instead of the main/master branch
IFS='@' read -ra git_url_parts <<< "${app_url}"
if ! $git_clone_cmd ; then
echo "ERROR: Git repository ${app_url} cannot be cloned into ${app_dir}."
echo "Terminating the Dockerfile build."
return 1
if [ -n "${git_url_parts[1]}" ]; then
git_clone_cmd="git clone --branch ${git_url_parts[1]} ${git_url_parts[0]} ${app_dir}"
else
git_clone_cmd="git clone ${app_url} ${app_dir}"
fi
if ! $git_clone_cmd ; then
echo "ERROR: Git repository ${app_url} cannot be cloned into ${app_dir}."
echo "Terminating the Dockerfile build."
return 1
fi
fi
echo "Building '${app_image_name}' image using docker build"