-
-
Save karampok/6f4b711a31d1c72058a3317f17d8915b to your computer and use it in GitHub Desktop.
Bring up a bosh-lite
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
#!/bin/bash | |
set -euo pipefail | |
bosh_deployment=~/workspace/bosh-deployment | |
if [ ! -d "$bosh_deployment" ]; then | |
echo "try: git clone https://github.com/cloudfoundry/bosh-deployment.git ~/workspace/bosh-deployment" | |
exit 1 | |
fi | |
director_dir=~/workspace/bosh-lite | |
mkdir -p "$director_dir" | |
update() { | |
pushd $bosh_deployment | |
git stash | |
git pull --rebase | |
git stash pop | |
popd | |
} | |
create() { | |
log "deploying director..." | |
unset BOSH_USER | |
bosh-cli create-env $bosh_deployment/bosh.yml \ | |
--vars-store $director_dir/bosh-vars.yml \ | |
--state $director_dir/bosh-state.json \ | |
-o $bosh_deployment/virtualbox/cpi.yml \ | |
-o $bosh_deployment/virtualbox/outbound-network.yml \ | |
-o $bosh_deployment/bosh-lite.yml \ | |
-o $bosh_deployment/bosh-lite-runc.yml \ | |
-o $bosh_deployment/jumpbox-user.yml \ | |
-v director_name=BoshLiteDirector \ | |
-v internal_ip=192.168.50.6 \ | |
-v internal_gw=192.168.50.1 \ | |
-v internal_cidr=192.168.50.0/24 \ | |
-v outbound_network_name=NatNetwork | |
log "writing bosh-env sourceable file..." | |
cat <<EOF >$director_dir/bosh-env | |
export BOSH_CLIENT=admin | |
export BOSH_CLIENT_SECRET=\$(bosh-cli int ${director_dir}/bosh-vars.yml --path /admin_password) | |
export BOSH_CA_CERT=\$(bosh-cli int ${director_dir}/bosh-vars.yml --path /director_ssl/ca) | |
export BOSH_ENVIRONMENT=192.168.50.6 | |
export BOSH_GW_USER=jumpbox | |
export BOSH_GW_HOST=192.168.50.6 | |
export BOSH_GW_PRIVATE_KEY=${director_dir}/id_rsa_jumpbox | |
EOF | |
rm -f ${director_dir}/id_rsa_jumpbox | |
bosh-cli int ${director_dir}/bosh-vars.yml --path /jumpbox_ssh/private_key > ${director_dir}/id_rsa_jumpbox | |
chmod 400 ${director_dir}/id_rsa_jumpbox | |
log "source ${director_dir}/bosh-env" | |
log "bosh-cli upload-stemcell https://bosh.io/d/stemcells/bosh-warden-boshlite-ubuntu-trusty-go_agent" | |
log "gfd() { bosh-cli create-release --force && bosh-cli -n upload-release && bosh-cli deploy -d \$1; }" | |
log "sudo route add -net 10.244.0.0/16 192.168.50.6" | |
} | |
destroy() { | |
log "deleting director VM..." | |
unset BOSH_USER | |
bosh-cli delete-env $bosh_deployment/bosh.yml \ | |
--vars-store $director_dir/bosh-vars.yml \ | |
--state $director_dir/bosh-state.json \ | |
-o $bosh_deployment/virtualbox/cpi.yml \ | |
-o $bosh_deployment/virtualbox/outbound-network.yml \ | |
-o $bosh_deployment/bosh-lite.yml \ | |
-o $bosh_deployment/bosh-lite-runc.yml \ | |
-o $bosh_deployment/jumpbox-user.yml \ | |
-v director_name="Bosh Lite Director" \ | |
-v internal_ip=192.168.50.6 \ | |
-v internal_gw=192.168.50.1 \ | |
-v internal_cidr=192.168.50.0/24 \ | |
-v outbound_network_name=NatNetwork | |
} | |
log() { | |
printf "\n" | |
echo "$1" | |
printf "\n" | |
} | |
usage_msg="usage: $0 <up|down>" | |
case "$1" in | |
up) | |
create | |
;; | |
down) | |
destroy | |
;; | |
restart) | |
destroy | |
update | |
create | |
;; | |
*) | |
echo "$usage_msg" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment