This commit is contained in:
zeaslity
2024-10-30 16:30:51 +08:00
commit 437acbeb63
3363 changed files with 653948 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
#!/bin/bash
harbor_host=192.168.118.14:8033
namespace=jsntejpt
app_name=""
new_tag=""
upload_image_to_harbor(){
if [ "$app_name" == "" ]; then
echo "app name null exit!"
exit 233
fi
if ! docker load < "$1"; then
echo "docker load error !"
fi
docker tag "harbor.cdcyy.com.cn/cmii/$app_name:$new_tag" "$harbor_host/cmii/$app_name:$new_tag"
echo ""
echo ""
echo "upload_image_to_harbor - start to push to => $harbor_host/cmii/$app_name:$new_tag"
docker login -u admin -p V2ryStr@ngPss $harbor_host
docker push "$harbor_host/cmii/$app_name:$new_tag"
echo ""
echo ""
}
parse_args(){
if [ "$1" == "" ]; then
echo "no zip file in error!"
exit 233
fi
local image_name="$1"
# cmii-uav-surveillance=5.2.0-27031-cqga=2024-03-04=573.tar.gz
app_name=$(echo $image_name | cut -d "=" -f1)
new_tag=$(echo $image_name | cut -d "=" -f2)
}
update_image_tag(){
if [ "$new_tag" == "" ]; then
echo "new tag error!"
exit 233
fi
local image_prefix=$(kubectl -n ${namespace} get deployment "${app_name}" -o=jsonpath='{.spec.template.spec.containers[*].image}' | cut -d":" -f1)
echo "image grep is => ${image_prefix}"
echo "start to update ${namespace} ${app_name} to ${new_tag} !"
echo ""
kubectl -n ${namespace} patch deployment "${app_name}" -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"${app_name}\",\"image\": \"${harbor_host}/cmii/$app_name:${new_tag}\"}]}}}}"
echo ""
echo "start to wait for 3 seconds!"
sleep 3
local image_new=$(kubectl -n ${namespace} get deployment "${app_name}" -o=jsonpath='{.spec.template.spec.containers[*].image}')
echo ""
echo "new image are => $image_new"
echo ""
}
main(){
parse_args "$1"
upload_image_to_harbor "$1"
update_image_tag
}
main "$@"

View File

@@ -0,0 +1,17 @@
#!/bin/bash
name_space=xmyd
kubectl get deployments -n ${xmyd} -o custom-columns='NAME:.metadata.name,REPLICAS:.spec.replicas' --no-headers > deployments_replicas.txt
scale_back_replicas(){
while IFS= read -r line; do
name=$(echo "$line" | awk '{print $1}')
replicas=$(echo "$line" | awk '{print $2}')
kubectl scale deployment "$name" --replicas="$replicas" -n ${name_space}
done < deployments_replicas.txt
}

View File

@@ -0,0 +1,41 @@
#!/bin/bash
full_image_name_list_path=/root/octopus_image/cmii/all-cmii-image-list.txt
name_space=xmyd
local_harbor_prefix=192.168.0.8:8033/cmii
read_and_update_cmii_image_tag(){
linux_images=()
while IFS= read -r i; do
[ -z "${i}" ] && continue
linux_images+=("${i}");
done < "${full_image_name_list_path}"
for i in "${linux_images[@]}"; do
[ -z "${i}" ] && continue
echo ""
echo "[update] -- start of ${i}"
case $i in
*/*/*)
last_segment="${i##*/}"
local app_name=$(echo $last_segment | cut -d":" -f1)
local new_tag=$(echo $last_segment | cut -d":" -f2)
local image_name="$local_harbor_prefix/$app_name"
echo "[update] -- app of ${app_name} to ${new_tag} ==> $image_name:${new_tag}"
if kubectl get deployment ${app_name} -n ${name_space} --ignore-not-found; then
echo "Deployment exists"
kubectl -n ${name_space} patch deployment ${app_name} -p "{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"${app_name}\",\"image\": \"${image_name}:${new_tag}\"}]}}}}"
else
echo "Deployment does not exist of ${app_name}"
fi
;;
*)
image_name="${DockerRegisterDomain}/rancher/${i}"
;;
esac
done
}
read_and_update_cmii_image_tag