Skip to content

Instantly share code, notes, and snippets.

@pitluga
Created January 14, 2016 16:14
Show Gist options
  • Save pitluga/2bb8f1b354002fa464ec to your computer and use it in GitHub Desktop.
Save pitluga/2bb8f1b354002fa464ec to your computer and use it in GitHub Desktop.
#!/bin/bash
set -uf -o pipefail
ENVIRONMENT=$1
SESSION_NAME=${2:-kay-${ENVIRONMENT}}
SERVER_SOCKET=/tmp/tmux-${SESSION_NAME}
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
case ${ENVIRONMENT} in
dev)
docker-machine status dev | grep Running &> /dev/null
if [[ $? != 0 ]]; then
docker-machine start dev
fi
source ${SCRIPTS_DIR}/env-dev
;;
prod)
echo -n "env-prod.vault "
secure_env=$(ansible-vault view ${SCRIPTS_DIR}/env-prod.vault)
if [[ $? != 0 ]]; then
echo "Vault password incorrect, find it in the shared keypass"
exit 1
fi
eval "${secure_env}"
source ${SCRIPTS_DIR}/env-prod
aws configure --profile ${AWS_DEFAULT_PROFILE} list &> /dev/null
if [[ $? != 0 ]]; then
echo "Missing aws profile ${AWS_DEFAULT_PROFILE}"
echo
echo "Run this command to fix:"
echo " aws configure --profile ${AWS_DEFAULT_PROFILE}"
exit 1
fi
;;
*)
echo "Usage scripts/tmux <environment> [session-name]"
echo " environment is one of: dev, prod"
echo " session-name defaults to 'kay-{environment}'"
exit 1
;;
esac
tmux -S ${SERVER_SOCKET} has-session -t ${SESSION_NAME} &> /dev/null
if [[ $? == 0 ]]; then
exec tmux -S ${SERVER_SOCKET} attach-session -t ${SESSION_NAME}
else
exec tmux -S ${SERVER_SOCKET}\
new-session -s ${SESSION_NAME} -n platform "cd ${SCRIPTS_DIR}/../platform && docker-compose build && docker-compose up" \;\
new-window
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment