mercredi 3 juin 2015

Automatic environment setup for Mac OS X developers

This post covers the subject of how to setup the automatic project infrastructure startup for users working on Mac OS X.


This article will be useful for those who are working on the projects combining multiple technologies. In my case the project includes Xmpp server, Rtmp server, ElasticSearch, MySQL, Ruby on Rails application, Memcached. All of this technologies are running in a separate terminal (terminal tab). So when I start my working day I should always repeat the same actions by running each of those services. To be more productive and don't spend my time by re-typing many times the same commands, I automated the creation of development environment.


The key tool for such automatisation is 
One powerful features of iTerm is profile. In our case, one profile - one server/service.
My solution consists of the following parts:
1. iTerm2
2. zsh + ohMyZsh
3. iTerm Profiles
4. iTerm Window saving mechanism


1. Open iTerm.

2. For each technology (server) we will create a specific profile:
In this screenshot I've created a profile for Rails server. Before server start I want to show the state of my git repo.
3. Then, for newly created profile we will define some useful hot keys for server restart or trigger the rebuild, followed by restart, etc:

4. How do you manage the error messages which occur in different terminals/tabs? Well, in my case, I should go tab by tab and look into the logs... Annoying, no? It would be better, if I could be notified automatically by Growl or something like that with error message and service name which produced the error. There is a nice hack for this. We will use a feature of iTerm Profile which is called Triggers (select Profile -> Advanced -> Triggers -> Edit). Then you should specify 3 parameters:

  •  regexp expression which identify the error entry for a particular service. For example, for my java based XMPP server, this regexp is simple 'ERROR'.
  • Action to be taken when regexp is occurred in the tab. You have many options there. Play sound, run a cmd, show growl notification, bounce dock icon, etc.
  • finally the optional parameter for the action you choose in the previous step. For example, for Growl notification it will be a text to be showed.
5. Now it's time to group all the profiles, set them properly as tabs, assign a different color for each. When it's done, we need to save this configuration. Window -> Save Window Arrangement.

Now each time you need to start working on this project, you simple go to Window -> Restore Window Arrangement and voila all the project env is up and you are ready to work in less the 2 seconds.

For those lucky developers, who are using multiple computers, like iMac at the office and MacBook at home, you can reuse the iTerm config with all setups iTerm -> Preferences -> General -> Preferences -> Load preferences from a custom folder or URL. You specify your Dropbox/Google disk folder and you can restore it from another computer.  

Aucun commentaire: