ceph.sh.j2 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. CMD=$(basename $0)
  3. TAG="v16.2.14"
  4. if [[ "$CMD" == *"-14" ]]; then
  5. CMD=${CMD%"-14"}
  6. TAG="v14.2.22"
  7. elif [[ "$CMD" == *"-16" ]]; then
  8. CMD=${CMD%"-16"}
  9. TAG="v16.2.14"
  10. elif [[ "$CMD" == *"-18" ]]; then
  11. CMD=${CMD%"-18"}
  12. TAG="v18.2.7"
  13. fi
  14. TTY=""
  15. BIMG={{ insecure_registry | default('registry.cn-beijing.aliyuncs.com') }}/{{ registry | default('yunion') }}/ceph:$TAG
  16. {% if k8s_or_k3s | default('k3s') == 'k3s' %}
  17. if [ -t 0 ]; then
  18. TTY="-t"
  19. fi
  20. IMG=$(k3s ctr images list -q | grep -m 1 -w "yunion/ceph")
  21. if [ -z "$IMG" ]; then
  22. IMG=$(k3s ctr images list -q | grep -m 1 -w "yunionio/ceph")
  23. if [ -z "$IMG" ]; then
  24. IMG=$BIMG
  25. k3s ctr images list name==$IMG -q | grep $IMG > /dev/null
  26. if [ $? -ne 0 ]; then
  27. k3s ctr images pull $IMG
  28. fi
  29. fi
  30. fi
  31. k3s ctr run --rm --net-host $TTY \
  32. --mount type=bind,src=/tmp,dst=/tmp,options=rbind \
  33. $IMG \
  34. ceph-common \
  35. /usr/bin/$CMD $@
  36. {% else %}
  37. if [ -t 0 ]; then
  38. TTY="-it"
  39. fi
  40. IMG=$(docker image ls --filter 'reference=*/yunion/ceph' | grep -m 1 -w "yunion/ceph" | awk '{print $1 ":" $2}')
  41. if [ -z "$IMG" ]; then
  42. IMG=$(docker image ls --filter 'reference=*/yunionio/ceph' | grep -m 1 -w "yunionio/ceph" | awk '{print $1 ":" $2}')
  43. if [ -z "$IMG" ]; then
  44. IMG=$BIMG
  45. fi
  46. fi
  47. docker run --rm --network host $TTY \
  48. -v /tmp:/tmp \
  49. $IMG \
  50. /usr/bin/$CMD $@
  51. {% endif %}