Skip to content

Instantly share code, notes, and snippets.

@jsinai
Last active February 8, 2022 01:53
Show Gist options
  • Save jsinai/532048bd7cc0f9f4a0f5c95858a9098a to your computer and use it in GitHub Desktop.
Save jsinai/532048bd7cc0f9f4a0f5c95858a9098a to your computer and use it in GitHub Desktop.
A script to make it more convenient to switch environments in the world of dotenv and kubernetes. Make sure to change line 3 (BCC)
#! /bin/bash
BCC=~/git/bs/bsn-cloud-configuration
set -e
usage()
{
cat <<EOF
Usage: $0 [options]
First: cd to the directory where you intend to do development.
Then: run this command, choosing the platform, target environment and project.
Platforms:
--dotenv|-n
--kubernetes|-k
Environments:
--production|-p
--staging|-s
--qa|test|-t
--dev|-d
--load-test|-l
Projects:
--oauth2|--oauth|-o
--certs|-c
--pvs|-v
--pss|-x
--websockets|-w
EOF
exit 1
}
while [ "$1" != "" ]; do
case "$1" in
# platforms
--dotenv|-n)
platform="dotenv"
;;
--kubernetes|-k)
platform="kubernetes"
;;
# environments
--production|-p)
environment="production"
;;
--staging|-s)
environment="staging"
;;
--qa|test|-t)
environment="qa"
;;
--dev|-d)
environment="dev"
;;
--load-test|-l)
environment="load-test"
;;
# projects
--oauth2|--oauth|-o)
project="oauth2"
short_name="oauth"
config_file=$short_name-config.env
;;
--certs|-c)
project="certs"
short_name="certs"
config_file=$project-config.env
;;
--pvs|-v)
project="provisioning-server"
short_name="pvs"
config_file=$short_name-config.env
;;
--pss|-x)
project="pss"
short_name="pss"
config_file=$project-config.env
;;
--websockets|-w)
project="websockets"
short_name="wss"
config_file=$project-config.env
;;
--help|-h)
usage
;;
*)
usage
;;
esac
shift
done
if [ -z "$platform" ]; then
usage
elif [ -z "$environment" ]; then
usage
elif [ -z "$project" ]; then
usage
else
if [ $platform = "dotenv" ]; then
echo Copying: $BCC/src/$environment/$project/$config_file
cp $BCC/src/$environment/$project/$config_file .env
else
echo Copying: $BCC/src/$environment/$project/Dockerfile
cp $BCC/src/$environment/$project/Dockerfile .
echo Copying: $BCC/src/$environment/$project/.dockerignore
cp $BCC/src/$environment/$project/.dockerignore .
echo Copying: $BCC/src/$environment/$project/npmrc
cp $BCC/src/$environment/$project/npmrc .
echo Copying: $BCC/src/$environment/$project/$short_name.yaml
cp $BCC/src/$environment/$project/$short_name.yaml .
echo Copying: $BCC/src/$environment/$project/$short_name-config.yaml
cp $BCC/src/$environment/$project/$short_name-config.yaml .
echo Copying: $BCC/src/$environment/$project/$short_name-secrets.yaml
cp $BCC/src/$environment/$project/$short_name-secrets.yaml .
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment