Skip to content

Commit

Permalink
Add default verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
iankouls-aws committed Jul 1, 2024
1 parent f0e84b8 commit 10f8506
Show file tree
Hide file tree
Showing 28 changed files with 229 additions and 86 deletions.
9 changes: 8 additions & 1 deletion 0-provision/stack-create.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash

aws cloudformation create-stack --stack-name ManagementInstance --template-body file://ManagementInstance.json --capabilities CAPABILITY_IAM
source ../config.properties

CMD="aws cloudformation create-stack --stack-name ManagementInstance --template-body file://ManagementInstance.json --capabilities CAPABILITY_IAM"

if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

7 changes: 6 additions & 1 deletion 1-build/pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ else
echo "config.properties not found!"
fi

docker pull ${registry}${base_image_name}${base_image_tag}
CMD="docker pull ${registry}${base_image_name}${base_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

13 changes: 11 additions & 2 deletions 1-build/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ fi
IMAGE=${base_image_name}
REGISTRY_COUNT=$(aws ecr describe-repositories | grep ${IMAGE} | wc -l)
if [ "$REGISTRY_COUNT" == "0" ]; then
aws ecr create-repository --repository-name ${IMAGE} --region ${region}
CMD="aws ecr create-repository --repository-name ${IMAGE} --region ${region}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
fi

docker push ${registry}${base_image_name}${base_image_tag}
CMD="docker push ${registry}${base_image_name}${base_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

7 changes: 6 additions & 1 deletion 3-pack/pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ else
echo "config.properties not found!"
fi

docker pull ${registry}${model_image_name}${model_image_tag}
CMD="docker pull ${registry}${model_image_name}${model_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

13 changes: 11 additions & 2 deletions 3-pack/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ fi
IMAGE=${model_image_name}
REGISTRY_COUNT=$(aws ecr describe-repositories | grep ${IMAGE} | wc -l)
if [ "$REGISTRY_COUNT" == "0" ]; then
aws ecr create-repository --repository-name ${IMAGE} --region ${region}
CMD="aws ecr create-repository --repository-name ${IMAGE} --region ${region}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
fi

docker push ${registry}${model_image_name}${model_image_tag}
CMD="docker push ${registry}${model_image_name}${model_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

12 changes: 9 additions & 3 deletions 4-deploy/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ echo "Processor: $processor"

if [ "$runtime" == "docker" ]; then
CMD="docker exec -it ${app_name}-0 bash"
echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
elif [ "$runtime" == "kubernetes" ]; then
kubectl -n ${namespace} exec -it $(kubectl -n ${namespace} get pod | grep ${app_name}-$1 | cut -d ' ' -f 1) -- bash
CMD="kubectl -n ${namespace} exec -it $(kubectl -n ${namespace} get pod | grep ${app_name}-$1 | cut -d ' ' -f 1) -- bash"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
else
echo "Runtime $runtime not recognized"
fi
8 changes: 5 additions & 3 deletions 4-deploy/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ do
export instance_name=${prefix}${instance}
echo "Generating ./${app_dir}/${instance_name}.yaml ..."
CMD="cat $template | envsubst > ./${app_dir}/${instance_name}.yaml"
#echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
instance=$((instance+1))
done

set +a
set +a
15 changes: 10 additions & 5 deletions 4-deploy/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ echo ""
echo "Runtime: $runtime"
echo "Processor: $processor"

CMD=""
if [ "$runtime" == "docker" ]; then
if [ "$num_servers" == "1" ]; then
CMD="docker logs -f ${app_name}-0"
Expand All @@ -27,20 +28,24 @@ if [ "$runtime" == "docker" ]; then
CMD="docker logs -f ${app_name}-$1"
fi
fi
echo "$CMD"
eval "$CMD"
elif [ "$runtime" == "kubernetes" ]; then
command -v kubetail > /dev/null
if [ "$?" == "1" ]; then
echo "kubetail not found"
echo "Please follow the instructions here https://github.com/johanhaleby/kubetail#installation, then try again"
else
if [ "$1" == "" ]; then
kubetail -n ${namespace} -f ${app_name}
CMD="kubetail -n ${namespace} -f ${app_name}"
else
kubectl -n ${namespace} logs -f $(kubectl -n ${namespace} get pods | grep ${app_name}-$1 | cut -d ' ' -f 1)
CMD="kubectl -n ${namespace} logs -f $(kubectl -n ${namespace} get pods | grep ${app_name}-$1 | cut -d ' ' -f 1)"
fi
fi
else
echo "Runtime $runtime not recognized"
fi
fi

if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

12 changes: 9 additions & 3 deletions 4-deploy/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ if [ "$runtime" == "docker" ]; then
run_opts="--device=/dev/neuron${server} ${run_opts}"
fi
CMD="docker run -d ${run_opts} ${registry}${model_image_name}${model_image_tag}"
echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
server=$((server+1))
done
elif [ "$runtime" == "kubernetes" ]; then
kubectl create namespace ${namespace} --dry-run=client -o yaml | kubectl apply -f -
./generate-yaml.sh
kubectl apply -f ${app_dir}
CMD="kubectl apply -f ${app_dir}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
else
echo "Runtime $runtime not recognized"
fi
32 changes: 25 additions & 7 deletions 4-deploy/status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,42 @@ echo "Processor: $processor"

if [ "$runtime" == "docker" ]; then
CMD="docker ps -a | grep ${app_name}"
echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
elif [ "$runtime" == "kubernetes" ]; then
if [ "$1" == "" ]; then
CMD="kubectl -n ${namespace} get pods"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
echo ""
echo "Pods:"
kubectl -n ${namespace} get pods
eval "${CMD}"
CMD="kubectl -n ${namespace} get services"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
echo ""
echo "Services:"
kubectl -n ${namespace} get services
eval "${CMD}"
else
CMD="kubectl -n ${namespace} get pod $(kubectl -n ${namespace} get pods | grep ${app_name}-$1 | cut -d ' ' -f 1) -o wide"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
echo ""
echo "Pod:"
kubectl -n ${namespace} get pod $(kubectl -n ${namespace} get pods | grep ${app_name}-$1 | cut -d ' ' -f 1) -o wide
eval "${CMD}"
CMD="kubectl -n ${namespace} get service ${app_name}-$1"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
echo ""
echo "Service:"
kubectl -n ${namespace} get service ${app_name}-$1
eval "${CMD}"
fi
else
echo "Runtime $runtime not recognized"
fi
fi
13 changes: 10 additions & 3 deletions 4-deploy/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ if [ "$runtime" == "docker" ]; then
server=0
while [ $server -lt $num_servers ]; do
CMD="docker rm -f ${app_name}-${server}"
echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
server=$((server+1))
done
elif [ "$runtime" == "kubernetes" ]; then
kubectl delete -f ${app_dir}
CMD="kubectl delete -f ${app_dir}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
else
echo "Runtime $runtime not recognized"
fi

7 changes: 5 additions & 2 deletions 5-test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ fi
#use CMD variable for better debugging
CMD="docker build -t ${registry}${test_image_name}${test_image_tag} --build-arg BASE_IMAGE=${registry}${base_image_name}${base_image_tag} \
-f 5-test/Dockerfile ."
eval $CMD

if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

11 changes: 6 additions & 5 deletions 5-test/exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ if [ "$runtime" == "docker" ]; then
CMD="docker exec -it ${test_image_name}-$1 bash"
fi
fi
echo "$CMD"
eval "$CMD"
elif [ "$runtime" == "kubernetes" ]; then
if [ "$num_test_containers" == "1" ]; then
CMD="kubectl -n ${test_namespace} exec -it $(kubectl -n ${test_namespace} get pod | grep ${test_image_name}-0 | cut -d ' ' -f 1) -- bash"
Expand All @@ -41,8 +39,11 @@ elif [ "$runtime" == "kubernetes" ]; then
CMD="kubectl -n ${test_namespace} exec -it $(kubectl -n ${test_namespace} get pod | grep ${test_image_name}-$1 | cut -d ' ' -f 1) -- bash"
fi
fi
echo "$CMD"
eval "$CMD"
else
echo "Runtime $runtime not recognized"
fi
fi
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

8 changes: 5 additions & 3 deletions 5-test/generate-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ do
export instance_name=${prefix}${instance}
echo "Generating ./${test_dir}/${instance_name}.yaml ..."
CMD="cat $template | envsubst > ./${test_dir}/${instance_name}.yaml"
#echo "$CMD"
eval "$CMD"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
instance=$((instance+1))
done

set +a
set +a
11 changes: 7 additions & 4 deletions 5-test/logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ if [ "$runtime" == "docker" ]; then
CMD="docker logs -f ${test_image_name}-$1"
fi
fi
echo "$CMD"
eval "$CMD"
elif [ "$runtime" == "kubernetes" ]; then
if [ "$1" == "" ]; then
kubectl -n ${test_namespace} get pods | grep ${test_image_name}- | cut -d ' ' -f 1 | xargs -L 1 kubectl -n ${test_namespace} logs
CMD="kubectl -n ${test_namespace} get pods | grep ${test_image_name}- | cut -d ' ' -f 1 | xargs -L 1 kubectl -n ${test_namespace} logs"
else
kubectl -n ${test_namespace} logs -f $(kubectl -n ${test_namespace} get pods | grep ${test_image_name}-$1 | cut -d ' ' -f 1)
CMD="kubectl -n ${test_namespace} logs -f $(kubectl -n ${test_namespace} get pods | grep ${test_image_name}-$1 | cut -d ' ' -f 1)"
fi
else
echo "Runtime $runtime not recognized"
fi
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

7 changes: 6 additions & 1 deletion 5-test/pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ else
echo "config.properties not found!"
fi

docker pull ${registry}${test_image_name}${test_image_tag}
CMD="docker pull ${registry}${test_image_name}${test_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

13 changes: 11 additions & 2 deletions 5-test/push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ fi
IMAGE=${test_image_name}
REGISTRY_COUNT=$(aws ecr describe-repositories | grep ${IMAGE} | wc -l)
if [ "$REGISTRY_COUNT" == "0" ]; then
aws ecr create-repository --repository-name ${IMAGE} --region ${region}
CMD="aws ecr create-repository --repository-name ${IMAGE} --region ${region}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"
fi

docker push ${registry}${test_image_name}${test_image_tag}
CMD="docker push ${registry}${test_image_name}${test_image_tag}"
if [ ! "$verbose" == "false" ]; then
echo "\n${CMD}\n"
fi
eval "${CMD}"

Loading

0 comments on commit 10f8506

Please sign in to comment.