The devcli

Every time you join a new company or project you start with setting up the environment for yourself locally. Historically this was a massive pain in the (@$@%$&#), but with the help of our saviors Vagrant and Docker everything was solved, right?

Well yes and no, packaging up apps and dependencies did get easier, but there still are plenty of things that are manual bits of work or arcane tribe knowledge on how to proceed.

Things like:

  • How do I add a new user?
  • What was the thing that I needed to do, to get that ABC thing to work?
  • How do I do Y again?

So this is a pretty good opportunity to set one up right? Before you say, well gosh I don’t know should I really be spending time doing this, I’ll only be using it until I get the hang of everything.

Before you go on with excuses stop there and look at it this way

alt text

So by taking a look at this awesome XKCD post

If you only shave off 2-3 minutes daily, you can afford to spend at least a day on this. (Not even counting all the new joiners after you + reduced number of interruptions you would have caused)

- Oh, but sure I won’t be able to automate everything in a day.

Yes, that seems unlikely but what you can do is the following:

  • Set up a template, so others can contribute to
  • Automate if easy
  • If it’s not easy to do quick just add a helpful message of how to do the manual work

- Well sound good, but how do I get started?

Look at this template and you can roll your own from it

#!/bin/bash

#Set up a few working folders
LOGDIR="/var/tmp/dev-logs/"
REPOS="/Users/someUser/work/repos/"

#Always check pre-reqs
function check_repo {
    #And if theres an available solution do it, don't just fail
    if [ ! -d $REPOS/$1 ]; then
        git clone git@github.com:someOrgThatHasRepos/$1
    else
        echo $1 "exists not cloning"
    fi
    
}
#Every service should have a sciprt to start things up
function runService {
    cd $REPOS/$1
    echo "Running" $1  && ./runService.sh  &> $LOGDIR/$1.log &
}
#What started up?
echo $$>$LOGDIR/pidfile
_cmd=${1}

case ${_cmd} in
    runDatabase)
        check_repo projectDB
        cd $REPOS/projectDB
        docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
        ;;
    run | start)
        #Start up needed things
        check_repo serviceA
        runService serviceA
        
        check_repo serviceB
        runService serviceB
        
        #Wonky dependency/manual work needed
        check_repo serviceC
        echo "This service is special in order to run it, please do ..."
        
        #Maybe a different kind of project
        check_repo frontEnd
        cd $REPOS/frontEnd
        npm run &> $LOGDIR/frontEnd.log &
        
        # A little reminder never hurts 
        echo ""
        echo "For logs see: ./devcli logs "
        
        ;;
    logs)
        tail -f $LOGDIR/*
        ;;
    kill)
        kill -9 $(pgrep -P$(cat $LOGDIR/pidfile))
        ;;
    *)
        echo "./devcli.sh run/start | logs | runDatabase"
        ;;
esac

As you can see, even something as simple as this can go a long way on developer on-boarding, and isn’t as horrible to maintain.

Hope it helps, let me know what you think. I would like to thank @andreitognolo for having the opportunity to work on a project that already had this set up. For a fully fledged example take a look here

comments powered by Disqus