Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds workflow retry if it fails #407

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions dev-tools/build-packages/build-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ get_packages(){
cd ..
}

source ../utils/retry-operation.sh

build_tar() {
log
log "Building base package..."
Expand All @@ -92,9 +94,12 @@ build_tar() {
container_name="dashboard-base-builder"
cp ./base-builder.sh ${dockerfile_path}
cp ./plugins ${dockerfile_path}
docker build -t ${container_name} ${dockerfile_path} || return 1
docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\
${container_name} ${version} ${revision} ${architecture} ${verbose}|| return 1
retry_operation "build base package" 5 15 \
"docker build -t ${container_name} ${dockerfile_path} && \
docker run -t --rm \
-v ${tmp_dir}/:/tmp:Z \
-v ${output_dir}/:/output:Z \
${container_name} ${version} ${revision} ${architecture} ${verbose}" || exit 1
cd ..
}

Expand All @@ -106,10 +111,13 @@ build_rpm() {
cp -r ${package_config_dir} ${tmp_dir}
cp ./rpm-builder.sh ${dockerfile_path}
cp ./wazuh-dashboard.spec ${dockerfile_path}
docker build -t ${container_name} ${dockerfile_path} || return 1
docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\
${container_name} ${version} ${revision} ${architecture}\
${commit_sha} ${production} ${verbose}|| return 1
retry_operation "build rpm package" 5 15 \
"docker build -t ${container_name} ${dockerfile_path} && \
docker run -t --rm \
-v ${tmp_dir}/:/tmp:Z \
-v ${output_dir}/:/output:Z \
${container_name} ${version} ${revision} ${architecture} \
${commit_sha} ${production} ${verbose}" || exit 1
cd ../
}

Expand All @@ -123,9 +131,13 @@ build_deb() {
cp ./deb-builder.sh ${dockerfile_path}
cp -r ./debian ${dockerfile_path}
docker build -t ${container_name} ${dockerfile_path} || return 1
docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z \
${container_name} ${version} ${revision} ${architecture}\
${commit_sha} ${production} ${verbose}|| return 1
retry_operation "build deb package" 5 15 \
"docker build -t ${container_name} ${dockerfile_path} && \
docker run -t --rm \
-v ${tmp_dir}/:/tmp:Z \
-v ${output_dir}/:/output:Z \
${container_name} ${version} ${revision} ${architecture} \
${commit_sha} ${production} ${verbose}" || exit 1
cd ..
}

Expand Down
16 changes: 10 additions & 6 deletions dev-tools/test-packages/test-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ check_metadata_rpm() {
echo "metadata package is correct: $metadataPackage"
}

source ../utils/retry-operation.sh

# Run test
test() {

if [[ $PACKAGE == *".deb" ]]; then
docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./deb/
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME
check_metadata_deb
retry_operation "test deb package" 5 15 \
"docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./deb/ && \
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME && \
check_metadata_deb" || exit 1
elif [[ $PACKAGE == *".rpm" ]]; then
docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./rpm/
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME
check_metadata_rpm
retry_operation "test rpm package" 5 15 \
"docker build --build-arg PACKAGE=$PACKAGE -t $CONTAINER_NAME ./rpm/ && \
docker run -it --rm -d --name $CONTAINER_NAME $CONTAINER_NAME && \
check_metadata_rpm" || exit 1
else
echo "ERROR: $PACKAGE is not a valid package (valid packages are .deb and .rpm ))"
exit 1
Expand Down
26 changes: 26 additions & 0 deletions dev-tools/utils/retry-operation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Function to retry an operation a number of times
# Arguments:
# $1: Name of the operation
# $2: Number of attempts
# $3: Delay between attempts
# $4+: Command to execute
retry_operation() {
local operation_name=$1
local max_attempts=$2
local sleep_time=$3
shift 3 # Delete the first 3 arguments

for i in $(seq 1 $max_attempts); do
if eval "$@"; then
return 0
else
if [ $i -eq $max_attempts ]; then
echo "Failed to $operation_name after $max_attempts attempts"
return 1
fi
sleep $sleep_time
fi
done
}
Loading