Created
October 18, 2016 20:49
-
-
Save johndpope/393f0735b6555005c234088422f0414d to your computer and use it in GitHub Desktop.
swift server docker
This file contains hidden or 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
#!/bin/bash | |
#Don't forget to do a 'chmod + buildAllContainers.sh' | |
# function to open a new terminal tab and run commands (for Apple Terminal or iTerm) | |
open_tab() { | |
[ $# -lt 1 ] && return | |
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] | |
then | |
osascript -e " | |
'tell application \"Terminal\" | |
activate' | |
" > /dev/null 2>&1 | |
osascript -e " | |
tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down | |
tell application \"Terminal\" to do script \"$1\" in selected tab of the front window | |
" > /dev/null 2>&1 | |
fi | |
if [ "$TERM_PROGRAM" == "iTerm.app" ] | |
then | |
osascript -e 'tell application "iTerm" to activate' -e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down' -e "tell application \"System Events\" to tell process \"iTerm\" to keystroke \"$1\n\"" | |
fi | |
} | |
exists() | |
{ | |
command -v "$1" >/dev/null 2>&1 | |
} | |
didStopAllContainers() | |
{ | |
docker ps >/dev/null 2>&1 | |
} | |
cloneSuccessfully() | |
{ | |
git clone "$1" >/dev/null 2>&1 | |
} | |
if ! exists docker-compose; then | |
echo -n "WARNING - could not detect docker-compose - Please download Docker for mac!!!!" | |
open https://docs.docker.com/docker-for-mac/ | |
exit | |
fi | |
printf "\033c" | |
echo -n "You need Docker for Mac to be running too (not docker toolbox)" | |
printf "\n" | |
echo -n "WARNING - docker-toolbox is not compatible with this script. " | |
printf "\n\n" | |
printf "\n\n" | |
printf "This script will stop all containers / and start them in sequence. \n" | |
printf "\n\n" | |
read -p "OK? [Y/n]" CONDITION; | |
if [ "$CONDITION" != "n" ]; then | |
echo "Stopping all docker containers" | |
docker stop $(docker ps -a -q) | |
printf "\033c" | |
# echo -n "Troubleshooting - Do you want to save All Docker images? " | |
# printf "\n\n" | |
# read -p "y/[N]" CONDITION; | |
# if [ "$CONDITION" == "y" ]; then | |
# save-all-image | |
# fi | |
echo -n "WARNING - Troubleshooting - do you now want to delete ALL docker images? " | |
read -p "y/[N]" CONDITION; | |
if [ "$CONDITION" == "y" ]; then | |
echo -n "Are you sure??? WARNING - THIS WILL DELETE ALL LOCAL DOCKER IMAGES + CONTAINERS !!!!!!!!! " | |
printf "\n\n" | |
read -p "[y/N] ?" CONDITION; | |
if [ "$CONDITION" == "y" ]; then | |
# FORCE Delete all images | |
docker rm $(docker ps -qa --no-trunc --filter "status=exited") | |
docker rm $(docker ps -aq) | |
docker rmi -f $(docker images -q) | |
docker rmi $(docker images -qf "dangling=true") | |
docker rmi $(docker images -a | grep "^<none>" | awk "{print $$3}") | |
printf "\033c" | |
fi | |
fi | |
printf "\033c" | |
echo -n "INFO - Install dependencies??? " | |
printf "\n\n" | |
printf "\n\n" | |
echo -n "0 - No...." | |
printf "\n\n" | |
echo -n "1 - just dependencies (pyenv / pip3 / virtualenv / zmq / python3 / freetds091)" | |
printf "\n\n" | |
echo -n "2 - dependencies + dev goodies (kitematic / oh-my-zsh / iterm2 / mongohub)" | |
printf "\n\n" | |
printf "[0] 1, 2" | |
printf "\n\n" | |
read -p "" CONDITION; | |
if [ "$CONDITION" == "2" ] ; then | |
brew install cask | |
brew cask install iterm2 | |
brew cask install kitematic | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null | |
brew cask install mongohub | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
fi | |
if [ "$CONDITION" == "1" ] || [ "$CONDITION" == "2" ] ; then | |
pip3 install virtualenv | |
brew update | |
brew install pyenv | |
brew install tree | |
pyvenv env | |
brew install python3 | |
brew unlink freetds; brew install homebrew/versions/freetds091 | |
pip install --upgrade pip | |
fi | |
printf "\033c" | |
open_tab "docker-compose -f docker-compose-dev.yml up;"; | |
open_tab "docker-compose run --rm db mongo mongodb://db; use test; db.items.insert({}); db.items.find();"; | |
read -p "Proceed [OK]?" CONDITION; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment