Skip to content

Commit

Permalink
feat(chart): Add scripts/deploy-manifest.sh
Browse files Browse the repository at this point in the history
- #4
  • Loading branch information
BaeKY committed Jan 8, 2023
1 parent 26b2172 commit 3b58772
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"add-custom-dns": "sudo bash ./scripts/add-custom-dns-resolver.sh",
"sample-nginx:up": "bash ./scripts/sample-nginx-up-down.sh up",
"sample-nginx:down": "bash ./scripts/sample-nginx-up-down.sh down",
"config:network": "pnpm ip-alias:up && pnpm add-custom-dns"
"config:network": "pnpm ip-alias:up && pnpm add-custom-dns",
"k8s:deploy": "./scripts/deploy-manifest.sh $@"
},
"dependencies": {
"@package/cdk8s-loader": "workspace:^0.0.1",
Expand Down
55 changes: 55 additions & 0 deletions chart/scripts/deploy-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

MANIFESTS=$1

case $MANIFESTS in
-*|--*|'')
echo "Unknown k8s manifest path '$MANIFESTS'"
exit 1
;;
esac
shift

if [ -d $MANIFESTS ]; then
MANIFESTS=$(realpath $MANIFESTS)/*
elif [ ! -f $MANIFESTS ]; then
echo "Files not exists"
exit 1
fi

POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case $1 in
-w|--wait)
WAIT="$2"
shift # past argument
shift # past value
;;
-r|--resources)
RESOURCES=$(echo "$2" | sed -r 's/,/|/g')
shift # past argument
shift # past value
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done

set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters

echo "$RESOURCES"

# User가 선택하지 않은 Resource 먼저 생성
cat $(ls $MANIFESTS | grep '.yaml') | yq ". | select(.kind | test(\"$RESOURCES\") | not)" | kubectl apply -f -

sleep $WAIT

# User가 선택한 Resource 생성
cat $(ls $MANIFESTS | grep '.yaml') | yq ". | select(.kind | test(\"$RESOURCES\"))" | kubectl apply -f -

0 comments on commit 3b58772

Please sign in to comment.