Skip to content

Instantly share code, notes, and snippets.

@smt116
Created January 10, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smt116/0c09b38dd3d00fc594d4a074523e49bc to your computer and use it in GitHub Desktop.
Save smt116/0c09b38dd3d00fc594d4a074523e49bc to your computer and use it in GitHub Desktop.
The script that setup Admin Panel application on Workflow (Deis v2)
#!/usr/bin/env sh
green() { echo "$(tput setaf 2)$*$(tput setaf 9)"; }
yellow() { echo "$(tput setaf 3)$*$(tput setaf 9)"; }
wait_for_pods () {
green "Waiting for pods..."
STARTED_AT=$(date +%s)
while true; do
should_wait=false
for pod in $(kubectl get pods $1 | awk '{print $2}' | tail -n +2)
do
if [ "$(echo $pod | cut -d / -f 1)" != "$(echo $pod | cut -d / -f 2)" ]; then
should_wait=true
fi
done
if $should_wait; then
sleep 5
else
break
fi
done
yellow -> Done in $(echo "$(date +%s) - $STARTED_AT" | bc) seconds.
}
call () {
yellow Running $@...
STARTED_AT=$(date +%s)
eval $@
yellow -> Done in $(echo "$(date +%s) - $STARTED_AT" | bc) seconds.
}
green "Disabling interactive errors reporting for minikube..."
call minikube config set WantReportErrorPrompt false
kubectl version 2>/dev/null | grep --quiet "Server Version"
if [ $? -eq 0 ]; then
green "Deleting local cluster..."
call minikube stop
call minikube delete
call rm -rf ~/.kube ~/.helm ~/.minikube
fi
set -e
green "Starting local cluster..."
call minikube start --cpus=2 --memory=4096
sleep 5 # wait is required for helm init
green "Installing Deis Workflow..."
call helm init
wait_for_pods "--namespace=kube-system"
call helm repo add deis https://charts.deis.com/workflow
call helm install deis/workflow --namespace deis
wait_for_pods "--namespace=deis"
export DEIS_PROFILE=local
green "Extending timeout for Git..."
manifest=$(mktemp)
call helm get manifest deis/workflow | sed -e '1,/builder-deployment.yaml/d;/---/,$d' > $manifest
call sed -i.bak 's/10/30/' $manifest
call kubectl apply -f $manifest --namespace deis
wait_for_pods "--namespace=deis"
green "Refreshing known hosts file..."
call sed -i.bak '/deis-builder.192.168.99.100.nip.io/d' ~/.ssh/known_hosts
ssh-keyscan -p 2222 deis-builder.192.168.99.100.nip.io >> ~/.ssh/known_hosts
green "Creating database for Admin Panel application..."
DATABASE_POD_NAME=$(kubectl --namespace deis get pods --output name | grep database | sed -E 's/pod\///')
call kubectl --namespace=deis exec $DATABASE_POD_NAME -it -- bash -ilc "psql -U postgres -c \"CREATE USER admin WITH PASSWORD 'secret';\""
call kubectl --namespace=deis exec $DATABASE_POD_NAME -it -- bash -ilc "psql -U postgres -c \"ALTER USER admin WITH SUPERUSER;\""
call kubectl --namespace=deis exec $DATABASE_POD_NAME -it -- bash -ilc "psql -U postgres -c \"CREATE DATABASE sinatra;\""
DATABASE_IP=$(kubectl --namespace deis describe pod $DATABASE_POD_NAME | grep IP | sed -E 's/IP:[[:space:]]+//')
green "Creating admin/secret account with keys..."
call deis2 register http://deis.192.168.99.100.nip.io --username=admin --password=secret --email=smt116@gmail.com
call deis2 keys:add ~/.ssh/id_rsa.pub
exit 0
green "Creating Admin Panel application..."
call deis2 apps:create admin-panel --no-remote
call deis2 git:remote --remote local --force
call deis2 config:push --path .env.kubernetes
call deis2 config:set DATABASE_URL=postgres://admin:secret@$DATABASE_IP/admin
call git push local master
call deis2 run rake db:setup
deis2 info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment