Wednesday, December 6, 2017

Vagrant - now we're talking infra as Code!!

Two weeks ago I'm in an Infrastructure team meeting and we get some news; people are clamoring for a docker-compose ephemeral lab for R&D and Test Engineering to work on and test the Black Duck Software Hub.
Damn, the team's been focusing on more Cloud Native deployments like Kubernetes, and OpenShift - docker-compose wasn't even in our peripheral vision.  Shit!  Okay time for me to make my move.  One of our team's technical leaders is +jay vyas and he asked if I could take ownership of the docker-compose work.  Of course I will.  We decided that I can probably get this done in about a week using Vagrant by HashiCorp. 
So last Tuesday I 'brew install vagrant' and set off to change the world!

So in three days I went from never having spun up any infra as software to a demo to the entire engineering team on Friday.

Doc Vyas helped me with a some seed code and I ran with that to get started. By the end of that 1st day I already had a Vagrant recipe that spun an Ubuntu 16.04 running in EC2.  Hell yea!

Day two I set forth to write some solid bash script that would:
update_os
inst_packs #installs the proper packages I need
add_gpgkey
add_stable_repo
update_packg_index
inst_docker
hello_world
inst_compose
start_hub
hub_ready

These are literally the functions I ended up with, self documenting - w00t!
The most complex code in this whole shebang is this:

=======================================
# Smoke test:  Is HUB ready and healthy
  function hub_ready() {
    TRIES=0
    while [[ $(sudo docker ps -a | grep 'blackduck' | grep "(healthy)" | wc -l) -lt $NUM_CONTAINERS ]] && [[ $TRIES -lt 120 ]] ; do
      sudo docker ps -a;
      sleep 1;
        let TRIES+=1
    done
  }

========================================
I'm just checking that all the hub docker containers are running and healthy, in 120 ticks of the clock.

So once I got all the things working on my local I committed and pushed, and was merged upstream  to our cool infrastructure project over on github:  https://github.com/blackducksoftware/kippernetes

My demo project is in /hack/compose-vagrant-up
and I'm actively working on wiring the demo into the Kippernetes CI/CD, with a goal of completing that work before Christmas break.
I've been blogging a bit about a test bastion host I've built in EC2 to run through the setup and configuration I'll need to do to the upstream Kippernetes bastion host to wire in my demoware.  You can check that out here https://tinyurl.com/sheppvagrantup01

Vagrant up!








As always, what I blog about are my views and opinions and only mine, and are never the views or opinions of my past | present | future employers.

No comments:

Post a Comment