create_app.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. VERSION="v4.31.1"
  3. BINARY="yq_linux_amd64"
  4. YQ_PATH="$(pwd)/yq"
  5. BASE_PATH="library/ix-dev"
  6. if [[ ! -f "$YQ_PATH" ]]; then
  7. echo "Downloading yq..."
  8. wget -q "https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}" -O "$YQ_PATH" && \
  9. chmod +x "$YQ_PATH"
  10. echo "Done"
  11. fi
  12. function check_args(){
  13. local arg=$1
  14. if [[ -z "$arg" ]]; then
  15. echo "Error: $2 not specified"
  16. exit 1
  17. fi
  18. }
  19. function copy_app() {
  20. local train=$1
  21. local app=$2
  22. # Check arguments have values
  23. check_args "$train"
  24. check_args "$app"
  25. # Grab version from Chart.yaml
  26. version=$("$YQ_PATH" '.version' "$BASE_PATH/$train/$app/Chart.yaml")
  27. check_args "$version"
  28. # Make sure directories exist
  29. mkdir -p "$train/$app/$version"
  30. helm dependency update "$BASE_PATH/$train/$app"
  31. # Copy files over
  32. rsync --archive --delete "$BASE_PATH/$train/$app/" "$train/$app/$version"
  33. # Rename values.yaml to ix_values.yaml
  34. mv "$train/$app/$version/values.yaml" "$train/$app/$version/ix_values.yaml"
  35. # Remove CI directory from the versioned app
  36. rm -r "$train/$app/$version/ci"
  37. # Grab icon and categories from Chart.yaml
  38. icon=$("$YQ_PATH" '.icon' "$BASE_PATH/$train/$app/Chart.yaml")
  39. check_args "$icon"
  40. categories=$("$YQ_PATH" '.keywords' "$BASE_PATH/$train/$app/Chart.yaml")
  41. check_args "$categories"
  42. # Create item.yaml
  43. echo "" > "$train/$app/item.yaml"
  44. ICON="$icon" "$YQ_PATH" '.icon_url = env(ICON)' --inplace "$train/$app/item.yaml"
  45. CATEGORIES="$categories" "$YQ_PATH" '.categories = env(CATEGORIES)' --inplace "$train/$app/item.yaml"
  46. }
  47. # TODO: Call this function for each changed app
  48. copy_app "$1" "$2"