ci/cd - add missing scripts

This commit is contained in:
bunkerity 2023-03-03 14:47:18 +01:00
parent 7149a34cc5
commit 139eaa2dd1
3 changed files with 109 additions and 0 deletions

45
src/linux/package.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
function do_and_check_cmd() {
if [ "$CHANGE_DIR" != "" ] ; then
cd "$CHANGE_DIR"
fi
output=$("$@" 2>&1)
ret="$?"
if [ $ret -ne 0 ] ; then
echo "❌ Error from command : $*"
echo "$output"
exit $ret
fi
#echo $output
return 0
}
# Check arg
if [ "$1" = "" ] ; then
echo "❌ Missing distro arg"
exit 1
fi
linux="$1"
# Create empty directory
package_dir="${PWD}/package-$linux"
if [ -d "$package_dir" ] ; then
do_and_check_cmd rm -rf "$package_dir"
fi
do_and_check_cmd mkdir "$package_dir"
# Generate package
version="$(cat VERSION | tr -d '\n')"
type="deb"
if [ "$linux" = "fedora" ] || [ "$linux" = "centos" ] ; then
type="rpm"
fi
do_and_check_cmd docker run --rm -v "${package_dir}:/data" "local/bunkerweb-${linux}:latest" "$type"
name="bunkerweb_${version}-1_amd64"
if [ "$type" = "rpm" ] ; then
name="bunkerweb-${version}-1.x86_64"
fi
do_and_check_cmd mv "${package_dir}/bunkerweb.$type" "${package_dir}/${name}.${type}"
exit 0

45
tests/create.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
# drop and export secrets
echo "${CICD_SECRETS}" > /opt/.env
chmod +x /opt/.env
. /opt/.env
# create terraform env
mkdir "/tmp/$1"
cp ./tests/terraform/providers.tf "/tmp/$1"
cp -r ./tests/terraform/templates "/tmp/$1"
cp "./tests/terraform/${1}.tf" "/tmp/$1"
old_dir="$(pwd)"
cd "/tmp/$1"
# terraform init
terraform init
if [ $? -ne 0 ] ; then
echo "terraform init failed"
exit 1
fi
# terraform apply
terraform apply -auto-approve
if [ $? -ne 0 ] ; then
echo "terraform apply failed"
terraform destroy -auto-approve
exit 2
fi
# run ansible playbook
if [ -f "/tmp/${1}_inventory" ] ; then
cd "${old_dir}/tests/ansible"
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -i "/tmp/${1}_inventory" "${1}_playbook"
if [ $? -ne 0 ] ; then
echo "ansible-playbook failed"
cd "/tmp/$1"
terraform destroy -auto-approve
exit 3
fi
fi
# done
exit 0

19
tests/rm.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# drop and export secrets
echo "${CICD_SECRETS}" > /opt/.env
chmod +x /opt/.env
. /opt/.env
# go to terraform env
cd "/tmp/$1"
if [ $? -ne 0 ] ; then
echo "terraform env is absent"
exit 1
fi
# terraform destroy
terraform destroy -auto-approve
# done
exit $?