Since I want to make use of these metrics at work, my implementation should be able to work against a Perforce server, the VCS we mainly use.
In order to have the appropriate development environment I needed a Linux virtual machine on which Perforce is installed, configured an running properly. I had previously used Vagrant to sandbox a development environment, and at that moment I knew it was the beginning of a long-term addiction.
Fortunately for me, Perforce can be downloaded free for up to 20 users.
My goal was to configure a virtual machine via Vagrant and provision it by installing a perforce server, running it and make it accessible from the host machine.
Interested ? Here’s how to do it.
1. Port Forwarding: Configuration
1 2 3 4 5 6 7 8 9 10 11
Since I was already using a Vagrant virtual machine I had to pay attention to using a different set of ports. The SSH port forwarding is bound, out of the box, to 2222. It was not clear in the documentation how to disable it. After several attempts and some googling I ended up by finding the right way to do it. For it to work you need to add the following two entries in the Vagrant file:
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", disabled: true
config.vm.network :forwarded_port, guest: 22, host: 2223, auto_correct: true
Perforce uses by default the port 1666, I chose to use the same port when forwarding it to the host.
2. Provisioning: Installing and starting Perfoce
Next I had to install perforce and run it. I was lucky enough to stumble upon an article that revealed to me the existence of a public Perforce FTP server.
Knowing that, I used a first provisioning shell script to download the perforce server binary (p4d) and its command line client (p4).
1 2 3 4 5 6 7 8 9 10 11 12
A second provisioning script, executed with a non privileged user, starts the Perforce server and does a connection attempt.
1 2 3 4 5
This script is configured to run at each restart of the virtual machine to make sure that the Perforce server is always started.
3. Accessing Perforce from host
It’s worth to note that if the second provisioning script is ran with a privileged user
the connection from the host was failing. I took me some time to figure out that starting the perforce server with the non privileged user, is the solution. I didn’t understand the reason behind it but I was glad it was working.
With that in place, the Perforce command line client running on the host machine was able to connect to the Perforce server running on the guest machine with no trouble.
Want to try it ? Fork it from vagrant-perforce-provisioning.