Last active
October 20, 2021 17:06
-
-
Save arunmascarenhas/437305f06f3d45c0e306c0702d7b62b1 to your computer and use it in GitHub Desktop.
Useful Bash snippets to add to your ~/.bashrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Kill and re-download docker | |
function redock() { | |
echo "Removing all stopped containers" | |
#docker rm ${docker ps -a -q} | |
echo "Pruning images" | |
docker image prune | |
if [ -z "$1" ] | |
then | |
echo "What should I kill?" | |
return -1 | |
fi | |
local psid=$(docker ps | grep $1 | awk '{print $1}') | |
echo $psid | |
if [ -z "$psid" ] | |
then | |
echo "No ps id found for \"$1\"" | |
else | |
docker kill $psid | |
docker rm $psid | |
fi | |
local iid=$(docker images | grep $1 | awk '{print $3}') | |
echo $iid | |
if [ -z "$iid" ] | |
then | |
echo "No image id found for \"$1\"" | |
else | |
docker rmi $iid | |
fi | |
if [ "$1" = "test-data" ] | |
then | |
compose-testdata up -d | |
fi | |
if [ "$1" = "prod" ] | |
then | |
compose-prod up -d | |
fi | |
} | |
## Akka Calc utilities | |
function rm_target() { | |
cd ~/Repos/akka-calc | |
rm -rf target | |
rm -rf calculator-api/target | |
} | |
function set_run_configs() { | |
rsync -avzrP ~/Repos/runConfigurations/ ~/Repos/akka-calc/.idea/runConfigurations/ | |
} | |
function killsbt() { | |
# empty the ivy cache if you have good network | |
# rm -rfv ~/.ivy2/cache/* | |
# or even better just backup it to sync it later on ... | |
mv ~/.ivy2/cache ~/.ivy2/cache.`date "+%Y%m%d_%H%M%S`.bak | |
# remove all sbt lock files | |
find ~/.sbt ~/.ivy2 -name "*.lock" -print -delete | |
find ~/.sbt ~/.ivy2 -name "ivydata-*.properties" -print -delete | |
# remove all the class files | |
rm -fvr ~/.sbt/1.0/plugins/target | |
rm -fvr ~/.sbt/1.0/plugins/project/target | |
rm -fvr ~/.sbt/1.0/target | |
rm -fvr ~/.sbt/0.13/plugins/target | |
rm -fvr ~/.sbt/0.13/plugins/project/target | |
rm -fvr ~/.sbt/0.13/target | |
rm -fvr ./project/target | |
rm -fvr ./project/project/target | |
} | |
function refresh_intellij() { | |
rm_target | |
set_run_configs | |
killsbt | |
} | |
## Kube utilities | |
function kube_into() { | |
case "$1" in | |
prod) | |
kubectl config use-context eks-us-west-2-prod | |
;; | |
gprod) | |
kubectl config use-context gke_c2fo-application_us-west1-a_prod-gke-us-west-1 | |
;; | |
euprod) | |
kubectl config use-context gke_c2fo-application_europe-west3-c_prod-gke-eu-west-3 | |
;; | |
cnprod) | |
kubectl config use-context prod-aws-cn-north-1.k8s.local | |
;; | |
inprod) | |
kubectl config use-context eks-ap-south-1-prod | |
;; | |
uat) | |
kubectl config use-context eks-us-west-2-non-prod | |
;; | |
guat) | |
kubectl config use-context gke_c2fo-application_us-west1-b_biggy | |
;; | |
euuat) | |
kubectl config use-context gke_c2fo-application_europe-west3-c_frankfurt-1 | |
;; | |
cnuat) | |
kubectl config use-context beijing-1.k8s.local | |
;; | |
inuat) | |
kubectl config use-context eks-ap-south-1-nonprod | |
;; | |
fss) | |
kubectl config use-context eks-us-west-2-non-prod | |
;; | |
gfss) | |
kubectl config use-context gke_c2fo-application_us-west1-b_biggy | |
;; | |
eufss) | |
kubectl config use-context gke_c2fo-application_europe-west3-c_frankfurt-1 | |
;; | |
cnfss) | |
kubectl config use-context beijing-1.k8s.local | |
;; | |
infss) | |
kubectl config use-context eks-ap-south-1-nonprod | |
;; | |
esac | |
postfix=$RANDOM | |
kubectl --namespace manual-commandline run --rm -i --tty "${1}-${postfix}" --image=postgres -- /bin/sh | |
} | |
function switch_to() { | |
username="arun.mascarenhas" | |
if [[ $1 = "devload" ]]; then | |
kubectl config use-context eks-us-west-2-testing | |
kubectl config set-context --current --namespace=devload | |
#kaf config use-cluster devload | |
elif [[ $1 = "indevload" ]]; then | |
kubectl config use-context eks-ap-south-1-testing | |
kubectl config set-context --current --namespace=indevload | |
#kaf config use-cluster devload | |
elif [[ $1 = "fss" ]]; then | |
kubectl config use-context eks-us-west-2-non-prod | |
kubectl config set-context --current --namespace=fss | |
#kaf config use-cluster fss | |
elif [[ $1 = "infss" ]]; then | |
kubectl config use-context eks-ap-south-1-non-prod | |
kubectl config set-context --current --namespace=infss | |
#kaf config use-cluster fss | |
elif [[ $1 = "uat" ]]; then | |
kubectl config use-context eks-us-west-2-non-prod | |
kubectl config set-context --current --namespace=uat | |
#kaf config use-cluster uat | |
elif [[ $1 = "prod" ]]; then | |
kubectl config use-context eks-us-west-2-prod | |
kubectl config set-context --current --namespace=production | |
#kaf config use-cluster production | |
elif [[ $1 = "phoenix" ]]; then | |
kubectl config use-context eks-us-west-2-testing | |
kubectl config set-context --current --namespace=phoenix-scooot; | |
#kaf config use-cluster development | |
elif [[ $1 = "gfss" ]]; then | |
kubectl config use-context gke_c2fo-application_us-west1-b_biggy | |
kubectl config set-context --current --namespace=gfss; | |
elif [[ $1 = "gdevload" ]]; then | |
kubectl config use-context gke_c2fo-application_us-west1-a_manual-west1; | |
kubectl config set-context --current --namespace=gdevload; | |
elif [[ $1 = "guat" ]]; then | |
kubectl config use-context gke_c2fo-application_us-west1-b_biggy | |
kubectl config set-context --current --namespace=guat; | |
elif [[ $1 = "gprod" ]]; then | |
kubectl config use-context gke_c2fo-application_us-west1-a_prod-gke-us-west-1 | |
kubectl config set-context --current --namespace=gprod; | |
elif [[ $1 = "eufss" ]]; then | |
kubectl config use-context gke_c2fo-application_europe-west3-c_frankfurt-1 | |
kubectl config set-context --current --namespace=eufss; | |
elif [[ $1 = "cnfss" ]]; then | |
kubectl config use-context eks-cn-north-1-non-prod | |
kubectl config set-context --current --namespace=cnfss; | |
elif [[ $1 = "euuat" ]]; then | |
kubectl config use-context gke_c2fo-application_europe-west3-c_frankfurt-1 | |
kubectl config set-context --current --namespace=euuat; | |
else | |
echo "Cluster not recognized" | |
fi | |
} | |
function env_details() { | |
if [[ $1 = "devload" ]]; then | |
echo eks-us-west-2-testing | |
elif [[ $1 = "indevload" ]]; then | |
echo eks-ap-south-1-testing | |
elif [[ $1 = "fss" ]]; then | |
echo eks-us-west-2-non-prod | |
elif [[ $1 = "infss" ]]; then | |
echo eks-ap-south-1-non-prod | |
elif [[ $1 = "uat" ]]; then | |
echo eks-us-west-2-non-prod | |
elif [[ $1 = "prod" ]]; then | |
echo eks-us-west-2-prod | |
elif [[ $1 = "phoenix" ]]; then | |
echo eks-us-west-2-testing | |
elif [[ $1 = "gfss" ]]; then | |
echo gke_c2fo-application_us-west1-b_biggy | |
elif [[ $1 = "gdevload" ]]; then | |
echo gke_c2fo-application_us-west1-a_manual-west1; | |
elif [[ $1 = "guat" ]]; then | |
echo gke_c2fo-application_us-west1-b_biggy | |
elif [[ $1 = "gprod" ]]; then | |
echo gke_c2fo-application_us-west1-a_prod-gke-us-west-1 | |
elif [[ $1 = "eufss" ]]; then | |
echo gke_c2fo-application_europe-west3-c_frankfurt-1 | |
elif [[ $1 = "cnfss" ]]; then | |
echo eks-cn-north-1-non-prod | |
elif [[ $1 = "euuat" ]]; then | |
echo gke_c2fo-application_europe-west3-c_frankfurt-1 | |
else | |
echo "Cluster not recognized" | |
fi | |
} | |
function fix_helm() { | |
env=$1 | |
k8ctx=$(env_details $env) | |
deployment=$(helm --kube-context=$k8ctx --namespace=$env history $env-akka-calc | awk '{if ($7 == "deployed") printf "%s\n", $1}') | |
echo helm --kube-context=$k8ctx --namespace=$env rollback $env-akka-calc $deployment | |
$(helm --kube-context=$k8ctx --namespace=$env rollback $env-akka-calc $deployment) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment