github.com/oam-dev/kubevela@v1.9.11/vela-templates/gen_definitions.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -e
     4  export IGNORE_KUBE_CONFIG=true
     5  
     6  LIGHTGRAY='\033[0;37m'
     7  GREEN='\033[0;32m'
     8  YELLOW='\033[1;33m'
     9  RED='\033[0;31m'
    10  NC='\033[0m'
    11  
    12  HEAD_PROMPT="${LIGHTGRAY}[${0}]${NC} "
    13  
    14  SCRIPT_DIR=$(dirname "$0")
    15  pushd "$SCRIPT_DIR" &> /dev/null
    16  
    17  DEPRECATED_DEFINITION_DIR="definitions/deprecated"
    18  INTERNAL_DEFINITION_DIR="definitions/internal"
    19  REGISTRY_DEFINITION_DIR="definitions/registry"
    20  INTERNAL_TEMPLATE_DIR="../charts/vela-core/templates/defwithtemplate"
    21  REGISTRY_TEMPLATE_DIR="registry/auto-gen"
    22  
    23  OS=$(uname -s | tr '[:upper:]' '[:lower:]')
    24  ARCH=""
    25  case $(uname -m) in
    26      i386)   ARCH="386" ;;
    27      i686)   ARCH="386" ;;
    28      x86_64) ARCH="amd64" ;;
    29      arm)    ARCH="arm64" ;;
    30  esac
    31  
    32  VELA_CMD="../bin/vela"
    33  if [ ! -f "$VELA_CMD" ]; then
    34    VELA_CMD="../_bin/vela/$OS-$ARCH/vela"
    35    echo -e "${HEAD_PROMPT}${LIGHTGRAY}Search cross build vela binary in ${VELA_CMD}.${NC}"
    36  fi
    37  if [ ! -f "$VELA_CMD" ]; then
    38      echo -e "${HEAD_PROMPT}${YELLOW}Failed to get vela command, fallback to use \`go run\`.${NC}"
    39      VELA_CMD="go run ../references/cmd/cli/main.go"
    40  else
    41    echo -e "${HEAD_PROMPT}${GREEN}Got vela command binary, version information:"
    42    $VELA_CMD version
    43  fi
    44  
    45  function render {
    46    inputDir=$1
    47    outputDir=$2
    48    if [ -z "$3" ] || [ "$3" != "--append" ]; then
    49      rm "$outputDir"/* 2>/dev/null || true
    50    fi
    51    mkdir -p "$outputDir"
    52    $VELA_CMD def render "$inputDir" -o "$outputDir" --message "Definition source cue file: vela-templates/$inputDir/{{INPUT_FILENAME}}"
    53    retVal=$?
    54    if [ $retVal -ne 0 ]; then
    55      echo -ne "${RED}Failed. Exit code: ${retVal}.${NC}\n"
    56      exit $retVal
    57    fi
    58  }
    59  
    60  function renderMinimal {
    61    inputDir=$1
    62    outputDir=$2
    63  
    64    cp -r "$inputDir" "$outputDir"
    65  
    66    rm -f "$outputDir"/defwithtemplate/env-binding.yaml
    67    rm -f "$outputDir"/defwithtemplate/deploy2env.yaml
    68  }
    69  
    70  echo -e "${HEAD_PROMPT}Start generating definitions at ${LIGHTGRAY}${SCRIPT_DIR}${NC} ..."
    71  
    72  # Generate Internal definitions
    73  echo -ne "${HEAD_PROMPT}${YELLOW}(0/3) Generating internal definitions from ${LIGHTGRAY}${INTERNAL_DEFINITION_DIR}${YELLOW} to ${LIGHTGRAY}${INTERNAL_TEMPLATE_DIR}${YELLOW} ... "
    74  export AS_HELM_CHART=true
    75  render $INTERNAL_DEFINITION_DIR $INTERNAL_TEMPLATE_DIR
    76  
    77  # Generate deprecated definitions
    78  echo -ne "${GREEN}Generated.\n${HEAD_PROMPT}${YELLOW}(1/3) Generating deprecated definitions from ${LIGHTGRAY}${DEPRECATED_DEFINITION_DIR}${YELLOW} to ${LIGHTGRAY}${INTERNAL_TEMPLATE_DIR}${YELLOW} ... "
    79  render $DEPRECATED_DEFINITION_DIR $INTERNAL_TEMPLATE_DIR --append
    80  echo -ne "${GREEN}Generated.\n${HEAD_PROMPT}${YELLOW}(2/3) Generating registry definitions from ${LIGHTGRAY}${REGISTRY_DEFINITION_DIR}${YELLOW} to ${LIGHTGRAY}${REGISTRY_TEMPLATE_DIR}${YELLOW} ... "
    81  
    82  # Generate registry definitions
    83  export AS_HELM_CHART=system
    84  render $REGISTRY_DEFINITION_DIR $REGISTRY_TEMPLATE_DIR
    85  
    86  echo -ne "${GREEN}Generated.\n${HEAD_PROMPT}${GREEN}(3/3) All done.${NC}\n"
    87  popd &> /dev/null