ci_logs.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # Exit immediately for non zero status
  18. set -e
  19. # Check unset variables
  20. set -u
  21. # Print commands
  22. set -x
  23. SOURCE="${BASH_SOURCE[0]}"
  24. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  25. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  26. SOURCE="$(readlink "$SOURCE")"
  27. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  28. done
  29. ROOT="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )"
  30. while (( "$#" )); do
  31. case "$1" in
  32. --release-name)
  33. RELEASE_NAME=$2
  34. shift 2
  35. ;;
  36. --artifacts-name)
  37. ARTIFACTS_NAME=$2
  38. shift 2
  39. ;;
  40. --log-dir)
  41. LOG_DIR=$2
  42. shift 2
  43. ;;
  44. -h|--help)
  45. { set +x; } 2>/dev/null
  46. HELP="
  47. Usage:
  48. $0 [flags] [Arguments]
  49. --log-dir Log Path
  50. --artifacts-name Artifacts Name
  51. --release-name Milvus helm release name
  52. -h or --help Print help information
  53. Use \"$0 --help\" for more information about a given command.
  54. "
  55. echo -e "${HELP}" ; exit 0
  56. ;;
  57. -*)
  58. echo "Error: Unsupported flag $1" >&2
  59. exit 1
  60. ;;
  61. *) # preserve positional arguments
  62. PARAMS+=("$1")
  63. shift
  64. ;;
  65. esac
  66. done
  67. LOG_DIR=${LOG_DIR:-/ci-logs/}
  68. RELEASE_NAME=${RELEASE_NAME:-milvus-testing}
  69. RELEASE_LOG_DIR=/${RELEASE_NAME}
  70. if [[ ! -d ${RELEASE_LOG_DIR} ]] ;then
  71. mkdir -p ${RELEASE_LOG_DIR}
  72. fi
  73. # Try to found logs file from mount disk /volume1/ci-logs
  74. # log_files=$(find ${LOG_DIR} -type f -name "*${RELEASE_NAME}*" )
  75. log_files=$(ls ${LOG_DIR} | grep ${RELEASE_NAME} || echo nonexistent)
  76. if [ "${log_files}" == "nonexistent" ]; then
  77. echo "No log files find"
  78. else
  79. for log_file in ${log_files}
  80. do
  81. file_name=$(basename ${log_file})
  82. mv ${LOG_DIR}/${log_file} ${RELEASE_LOG_DIR}/`echo ${file_name} | sed 's/ci.var.log.containers.//g' `
  83. done
  84. tar -zcvf ${ARTIFACTS_NAME:-artifacts}.tar.gz ${RELEASE_LOG_DIR}/*
  85. rm -rf ${RELEASE_LOG_DIR}
  86. fi
  87. # remain_log_files=$(find ${LOG_DIR} -type f -name "*${RELEASE_NAME}*")
  88. # ls ${LOG_DIR} | grep ${RELEASE_NAME}
  89. remain_log_files=$(ls ${LOG_DIR} | grep ${RELEASE_NAME} || echo nonexistent)
  90. if [ "${remain_log_files}" == "nonexistent" ]; then
  91. echo "No remain log files"
  92. else
  93. echo "Still have log files & Remove again"
  94. for log_file in ${remain_log_files}
  95. do
  96. rm -rf ${LOG_DIR}/${log_file}
  97. done
  98. echo "Check if any remain log files after using rm to delete again "
  99. ls ${LOG_DIR} | grep ${RELEASE_NAME} || echo nonexistent
  100. fi