This commit is contained in:
Oleg Sheynin 2024-03-02 13:33:28 -05:00
parent d93b46ef48
commit 2a72bb9cae
3 changed files with 231 additions and 1 deletions

View File

@ -1 +1 @@
0.5.7 0.5.8

148
scripts/build_release.sh Executable file
View File

@ -0,0 +1,148 @@
#!/bin/bash
# ---------------- Settings
declare -A git_repo_arr
git_repo_arr[cvttpy]=git@cloud21.cvtt.vpn:/opt/store/git/cvttpy.git
git_repo_arr[ops]=git@cloud21.cvtt.vpn:/opt/store/git/ops.git
default_project=cvttpy
default_branch=master
dist_root=/home/cvttdist/software/cvtt2
dist_user=cvttdist
dist_host="cloud21.cvtt.vpn"
dist_ssh_port="22"
interactive=Y
# cmdline
prj=${1:-${default_project}}
brnch=${2:-${default_branch}}
if [ "${3}" == "D" ]; then
interactive=N
fi
function confirm {
if [ "${interactive}" == "Y" ]; then
echo "--------------------------------"
echo -n "Press <Enter> to continue" && read
fi
}
if [ "${interactive}" == "Y" ]; then
echo -n "Enter project [${prj}]: "
read project
if [ "${project}" == "" ]
then
project=${prj}
fi
else
project=${prj}
fi
repo=${git_repo_arr[${project}]}
if [ -z ${repo} ]; then
echo "ERROR: Project repository for ${project} not found"
exit -1
fi
echo "Project repo: ${repo}"
if [ "${interactive}" == "Y" ]; then
echo -n "Enter branch to build release from [${brnch}]: "
read branch
if [ "${branch}" == "" ]
then
branch=${brnch}
fi
else
branch=${brnch}
fi
tmp_dir=$(mktemp -d)
prj_dir="${tmp_dir}/${prj}"
cmd_arr=()
Cmd="git clone ${repo} ${prj_dir}"
cmd_arr+=("${Cmd}")
Cmd="cd ${prj_dir}"
cmd_arr+=("${Cmd}")
if [ "${interactive}" == "Y" ]; then
echo "------------------------------------"
echo "The following commands will execute:"
echo "------------------------------------"
for cmd in "${cmd_arr[@]}"
do
echo ${cmd}
done
fi
confirm
for cmd in "${cmd_arr[@]}"
do
echo ${cmd} && eval ${cmd}
done
Cmd="git checkout ${branch}"
echo ${Cmd} && eval ${Cmd}
if [ "${?}" != "0" ]; then
echo "ERROR: Branch ${branch} is not found"
cd ${HOME} && rm -rf ${tmp_dir}
exit -1
fi
release_version=$(cat release_version.txt)
echo "--------------------------------"
echo "Release version: ${release_version}"
confirm
version_tag="v${release_version}"
version_comment="${version_tag}_${project}_${branch}_$(date +%Y%m%d)"
cmd_arr=()
Cmd="git tag -a ${version_tag} -m ${version_comment}"
cmd_arr+=("${Cmd}")
Cmd="git push origin --tags"
cmd_arr+=("${Cmd}")
Cmd="rm -rf .git"
cmd_arr+=("${Cmd}")
dist_path="${dist_root}/${project}/${release_version}"
Cmd="rsync -avzh"
Cmd="${Cmd} --rsync-path=\"mkdir -p ${dist_path} && rsync\""
Cmd="${Cmd} -e \"ssh -p ${dist_ssh_port}\""
Cmd="${Cmd} ../${project} ${dist_user}@${dist_host}:${dist_path}/"
cmd_arr+=("${Cmd}")
if [ "${interactive}" == "Y" ]; then
echo "------------------------------------"
echo "The following commands will execute:"
echo "------------------------------------"
for cmd in "${cmd_arr[@]}"
do
echo ${cmd}
done
fi
confirm
for cmd in "${cmd_arr[@]}"
do
echo ${cmd} && eval ${cmd}
done
cd ${HOME}
rm -rf ${tmp_dir}
echo $0 Done

82
scripts/set_version.sh Executable file
View File

@ -0,0 +1,82 @@
#!/bin/bash
function usage() {
echo "Usage: ${0} <project> <version>"
exit 1
}
Project=${1}
Version=${2}
if [ "${Project}" == "" ]
then
usage
fi
if [ "${Version}" == "" ]
then
usage
fi
# ----- Settings
LocalSoftwareDir=${HOME}/software
ProdDir=${HOME}/prod
ReleaseHosts=("cloud21.cvtt.vpn")
ReleasePorts=("22")
ReleaseUsers=("cvttdist")
ReleaseDir=("/home/cvttdist/software/cvtt2")
# ----- Settings
Location="${LocalSoftwareDir}/${Project}/${Version}/${Project}"
function rsync_load_version() {
for idx in "${!ReleaseHosts[@]}"
do
host=${ReleaseHosts[${idx}]}
port=${ReleasePorts[${idx}]}
user=${ReleaseUsers[${idx}]}
rel_dir=${ReleaseDir[${idx}]}
echo "Checking ${user}@${host} for ${rel_dir}/${Project}/${Version} ..."
if ssh -q -p ${port} ${user}@${host} "test -d ${rel_dir}/${Project}/${Version}"
then
echo "Directory found..."
rsync_cmd="rsync -ahvv -e \"ssh -p ${port}\""
rsync_cmd="${rsync_cmd} ${user}@${host}:${rel_dir}/${Project}/${Version}"
rsync_cmd="${rsync_cmd} ${LocalSoftwareDir}/${Project}/"
echo ${rsync_cmd}
eval ${rsync_cmd}
status=$?
if [ ${status} -eq 0 ]
then
echo "Loading successful..."
break
fi
else
echo "Not Found ${rel_dir}/${Project}/${Version} on ${user}@${host}"
fi
done
if [[ ! -d ${LocalSoftwareDir}/${Project} ]] ; then
echo ERROR loading software
exit 1
fi
}
mkdir -p ${LocalSoftwareDir}
# exists and not empty
if [[ ! -d "${Location}" ]] ; then
rsync_load_version
fi
Cmd="cd ${ProdDir}"
Cmd="${Cmd} && rm -rf ${Project}"
Cmd="${Cmd} && ln -snf ${Location} ${Project}"
echo ${Cmd}
eval ${Cmd}
echo "Done: $0 $*"