Skip to content

Commit

Permalink
Merge pull request #154 from dxw/feature/list-services-by-buildspec
Browse files Browse the repository at this point in the history
Add list-services-by-buildspec command
  • Loading branch information
snim2 authored Sep 18, 2023
2 parents 694e324 + 9405f7c commit 663e631
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bin/config/list-services-by-buildspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

"$APP_ROOT/bin/dalmatian-refresh-config" > /dev/null

usage() {
echo "List all services with a given buildspec"
echo "e.g. dalmatian config $(basename "$0") -b dalmatian_core_buildspec_saluki"
echo "Usage: $(basename "$0") <infrastructure name [OPTIONAL]>" 1>&2
echo " -b - buildspec e.g. dalmatian_core_buildspec_saluki"
echo " -i - infrastructure name (optional)"
echo " -h - help"
exit 1
}

INFRASTRUCTURE_NAME=""
while getopts "b:i:h" opt; do
case $opt in
b)
BUILDSPEC=$OPTARG
;;
i)
INFRASTRUCTURE_NAME=$OPTARG
;;
h)
usage
;;
*)
usage
;;
esac
done


if [[ -z "$BUILDSPEC" ]]
then
usage
fi

INFRAS=$(yq e -o=json ".infrastructures" "$APP_ROOT/bin/tmp/dalmatian-config/dalmatian.yml")

if [ -z "$INFRASTRUCTURE_NAME" ]
then
echo "$INFRAS" | jq -r --arg b "$BUILDSPEC" '. as $infras | keys[] as $infra_name | $infras[$infra_name].services[] | select(.buildspec == $b) | "\($infra_name) \(.name)"'
else
echo "$INFRAS" | jq -r --arg i "$INFRASTRUCTURE_NAME" --arg b "$BUILDSPEC" '. as $infras | keys[] as $infra_name | $infras[$infra_name].services[] | select($infra_name == $i) | select(.buildspec == $b) | "\($infra_name) \(.name)"'
fi

0 comments on commit 663e631

Please sign in to comment.