Skip to content

Commit

Permalink
[WFLY-19337] The GitHub Action to test ejb-txn-remote-call is now wor…
Browse files Browse the repository at this point in the history
…king
  • Loading branch information
jmfinelli committed Dec 13, 2024
1 parent c808441 commit e97a484
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 274 deletions.
124 changes: 114 additions & 10 deletions .github/workflows/scripts/kubernetes/core/overridable-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Parameters
# 1 - the name of the qs directory (not the full path)
#
function applicationName() {
echo "${1}"
}
Expand All @@ -20,6 +21,7 @@ function applicationName() {
#
# Parameters
# 1 - the name of the qs directory
#
function namespace() {
application="${1}"
# Uncomment to make the tests run in the 'testing' namespace
Expand All @@ -32,6 +34,7 @@ function namespace() {
#
# Parameters
# 1 - application name
#
function installPrerequisites()
{
application="${1}"
Expand All @@ -43,12 +46,35 @@ function installPrerequisites()
#
# Parameters
# 1 - application name
#
function cleanPrerequisites()
{
application="${1}"
echo "No prerequisites to clean for ${application}"
}

# Provision server and push imagestream
# The current directory is the quickstart directory
#
# Parameters
# 1 - application name
# 2 - quickstart dir
#
function provisionServer()
{
application="${1}"
qs_dir="${2}"

echo "Building application and provisioning server image..."
mvn -B package -Popenshift wildfly:image -DskipTests

echo "Tagging image and pushing to registry..."
export root_image_name="localhost:5000/${application}"
export image="${root_image_name}:latest"
docker tag ${qs_dir} ${image}
docker push ${image}
}

# Performs the 'helm install' command.
# The current directory is the quickstart directory
# Parameters
Expand All @@ -61,15 +87,33 @@ function cleanPrerequisites()
# * helm_install_timeout - the adjusted timeout for the helm install
#
function helmInstall() {
application="${1}"
helm_set_arguments="$2"

# '--wait' waits until the pods are ready
# `--timeout` sets the timeout for the wait.
# https://helm.sh/docs/helm/helm_install/ has more details
# Don't quote ${helm_set_arguments} since then it fails when there are none
helm install "${application}" wildfly/wildfly -f charts/helm.yaml --wait --timeout=${helm_install_timeout} ${helm_set_arguments}
echo "$?"
application="${1}"
helm_set_arg_prefix="${2}"
helm_install_timeout="${3}"

# Helm install, waiting for the pods to come up
helm_set_arguments=" --set ${helm_set_arg_prefix}build.enabled=false --set ${helm_set_arg_prefix}deploy.route.enabled=false --set ${helm_set_arg_prefix}image.name=${root_image_name}"

additional_arguments="No additional arguments"
if [ -n "${helm_set_arguments}" ]; then
additional_arguments="Additional arguments: ${helm_set_arguments}"
fi

echo "Performing Helm install and waiting for completion.... (${additional_arguments})"

# '--wait' waits until the pods are ready
# `--timeout` sets the timeout for the wait.
# https://helm.sh/docs/helm/helm_install/ has more details
# Don't quote ${helm_set_arguments} since then it fails when there are none
helm install "${application}" wildfly/wildfly -f charts/helm.yaml --wait --timeout=${helm_install_timeout} ${helm_set_arguments}

echo "ret: $?"
if [ "$?" != "0" ]; then
echo "Helm install failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
helmInstallFailed
fi
}

# Commands to run once the Helm install has completed
Expand Down Expand Up @@ -106,10 +150,70 @@ function helmInstallFailed() {
echo ""
}

# Port forward to test the quickstart
# Parameters
# 1 - application name
#
function portForward() {
application="${1}"

kubectl port-forward service/${application} 8080:8080 &
kubectl_fwd_pid=$!
echo "${kubectl_fwd_pid}"
}

# Running tests of the quickstart
# Parameters
# 1 - application name
# 2 - server protocol
# 3 - extra maven argument for the verify target
#
function runningTests() {
application="${1}"
server_protocol="${2}"
extraMvnVerifyArguments="${3}"

route="localhost:8080"

mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
if [ -n "${extraMvnVerifyArguments}" ]; then
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
fi
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
fi

echo "Verify Arguments: ${mvnVerifyArguments}"

mvn -B verify -Pintegration-testing ${mvnVerifyArguments}

test_status="$?"

if [ "$?" != "0" ]; then
test_status=1
echo "Tests failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
testsFailed
fi

echo "${test_status}"
}

# Performs the 'helm uninstall' command.
# Parameters
# 1 - application name
#
function helmUninstall() {
application="${1}"

helm uninstall "${application}" --wait --timeout=10m0s
}

# More output when the tests have failed
# Parameters
# 1 - application name
#
function testsFailed() {
echo ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,23 @@ fi

################################################################################################
# Install any pre-requisites. Function is from overridable-functions.sh

echo "Checking if we need to install pre-requisites"
installPrerequisites "${application}"

################################################################################################
# Provision server and push imagestream

echo "Building application and provisioning server image..."
mvn -B package -Popenshift wildfly:image -DskipTests

echo "Tagging image and pushing to registry..."
export root_image_name="localhost:5000/${application}"
export image="${root_image_name}:latest"
docker tag ${qs_dir} ${image}
docker push ${image}
provisionServer "${application}" "${qs_dir}"

################################################################################################
# Helm install, waiting for the pods to come up
helm_set_arguments=" --set ${helm_set_arg_prefix}build.enabled=false --set ${helm_set_arg_prefix}deploy.route.enabled=false --set ${helm_set_arg_prefix}image.name=${root_image_name}"

additional_arguments="No additional arguments"
if [ -n "${helm_set_arguments}" ]; then
additional_arguments="Additional arguments: ${helm_set_arguments}"
fi

echo "Performing Helm install and waiting for completion.... (${additional_arguments})"
# helmInstall is from overridable-functions.sh
helm_install_ret=$(helmInstall "${application}" "${helm_set_arguments}")

# For some reason the above sometimes becomes a multi-line string. actual The exit code will be
# on the last line
helm_install_ret=$(echo "${helm_install_ret}"| tail -n 1)

echo "ret: ${helm_install_ret}"
if [ "${helm_install_ret}" != "0" ]; then
echo "Helm install failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
helmInstallFailed
fi
helmInstall "${application}" "${helm_set_arg_prefix}" "${helm_install_timeout}"

kubectl port-forward service/${application} 8080:8080 &
kubectl_fwd_pid=$!
echo "Process ID of kubect port-forward: ${kubectl_fwd_pid}"
echo "Performing Port Forward and waiting for completion...."
kubectl_fwd_pids=$(portForward "${application}")
echo "Process ID(s) of kubect port-forward: ${kubectl_fwd_pids}"

################################################################################################
# Run any post install
Expand All @@ -130,35 +104,15 @@ runPostHelmInstallCommands
echo "running the tests"
pwd

route="localhost:8080"

mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
extraMvnVerifyArguments="$(getMvnVerifyExtraArguments)"
if [ -n "${extraMvnVerifyArguments}" ]; then
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
fi
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
fi

echo "Verify Arguments: ${mvnVerifyArguments}"

mvn -B verify -Pintegration-testing ${mvnVerifyArguments}

if [ "$?" != "0" ]; then
test_status=1
echo "Tests failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
testsFailed
fi
runningTests "${application}" "${server_protocol}" "$(getMvnVerifyExtraArguments)"
test_status=$?

kill -9 ${kubectl_fwd_pid}
kill -9 ${kubectl_fwd_pids}

################################################################################################
# Helm uninstall
echo "Running Helm uninstall"
helm uninstall "${application}" --wait --timeout=10m0s
helmUninstall "${application}"

################################################################################################
# Clean pre-requisites (cleanPrerequisites is fromm overridable-functions.sh)
Expand Down Expand Up @@ -187,4 +141,4 @@ end=$SECONDS
duration=$((end - start))
echo "${application} tests run in $(($duration / 60))m$(($duration % 60))s."

exit ${test_status}
exit ${test_status}
Loading

0 comments on commit e97a484

Please sign in to comment.