How to ignore files only locally in git?

I have automated tests running everyday, and the issue is that those tests make necessary changes to certain files depending on which test is running. This becomes a problem when I have to report the changes in the repo, as this will report untracked changed, which means I have to ignore certain files such that local Git doesn’t report changes in them specifically.

By making sure to run git update-index --assume-unchanged ./matplotlibrc after making the addition to the exclude file this means changes won’t be picked up until then.


git update-index --assume-unchanged index.rst
git update-index --assume-unchanged matplotlibrc

Before:
Screenshot_2017-06-02_07-31-01

After:

Screenshot_2017-06-02_08-19-20.png

Changes made but untracked, nice!!!

How can I merge two or more Git commits into one[locally and remote]?

You can do this fairly easily without git rebase or git merge --squash. In this example, we’ll squash the last 3 commits.

If you want to write the new commit message from scratch, this suffices:

git reset --soft HEAD~3 &&
git commit

If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit:

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”).

Important: If you’ve already pushed commits to GitHub, and then squash them locally, you will have to force the push to your branch.

$ git push origin branch-name --force

Helpful hint: You can always edit your last commit message, before pushing, by using:

$ git commit --amend

Credit

Diagnosing LAN Speeds

After having network issues/degradation while trying to access a work server, I had to diagnose the network the server is connected to. I had to set myself on a mission – and after realising that the seems to be very limited tools for such things, I stumbled upon ‘iperf‘.

Iperf is a command-line tool used in the diagnostics of network speed issues, it measures the maximum network throughput a server can handle. It is particularly useful when experiencing network speed issues, as you can use Iperf to determine which server is unable to reach maximum throughput.

Iperf installation

Iperf must be installed on both computers you are testing the connection between.

sudo apt-get install -y iperf

TCP Clients & Servers

Iperf requires two systems because one system must act as a server, while the other acts as a client. The client connects to the server you’re testing the speed of.

  1. On the node you wish to test, launch Iperf in server mode:
iperf -s

You should see output similar to:

Screenshot_2017-05-05_12-02-15

2. On your second Linode, connect to the first. Replace dbelab04 with the first node’s IP address in my case i’m using the hostname

iperf -c dbelab04

You should see output similar to:
Screenshot_2017-05-05_12-02-53

3. You will also see the connection and results on your Iperf server. This will look similar to:

Screenshot_2017-05-05_12-03-04

4. To stop the Iperf server process, press CTRL + c.

————————————————————————————————–

You can do pretty much the same thing with plain old nc (netcat) if you’re that way inclined. On the server machine:

nc -vvlnp 12345 >/dev/null

You should see something similar to:

Screenshot_2017-05-05_12-14-05

And the client can pipe a 10Gb of zeros through dd over the nc tunnel.

dd if=/dev/zero bs=10M count=1K status=progress | nc -vvn 192.168.4.23 12345

You should see something similar to:

Screenshot_2017-05-05_12-13-54

The timing there is given by dd but it should be accurate enough as it can only output as fast the pipe will take it. If you’re unhappy with that you could wrap the whole thing up in a time call.

Remember that the result is in megabytes so multiply it by 8 to get a megabits-per-second speed. The demo above is running at 11.8mbps due to my laptops network limitation and number of hops…

How to make Git commit to trigger a job/build in Jenkins CI

In this blog post I will show you how to configure a post commit hook on Git that notifies a Jenkins CI server about repository changes. This means that whenever a new commit is pushed to the Git repository, the cURL command line tool will be launched to initiate a Http request telling Jenkins to trigger a job.

1. Execute Jenkins build with Curl

In this setup, there is no authentication at Jenkins, considering that I will be responsible for the repository and jenkins server.

To test, I had to execute jenkins with curl


(Test)mmphego@dbelab04:~/src/mkat_fpga_tests/.git/hooks (GIT_DIR!)
|_ [2017-04-05 11:58:47] $ >>> curl -D - -X POST http://dbelab04:8080/job/mkat_fpga_tests_4k/build

HTTP/1.1 201 Created
Date: Wed, 05 Apr 2017 09:59:23 GMT
X-Content-Type-Options: nosniff
Location: http://dbelab04:8080/queue/item/387/
Content-Length: 0
Server: Jetty(9.2.z-SNAPSHOT)

2. Configure a hook of repository

Create a file in .git/hooks called post-commit and do not forget to make it executable.

$ nano $(pwd)/.git/hooks/post-commit

#!/bin/bash
# Jenkins-Git build trigger
# Mpho Mphego

machine=$(uname -n)
echo 'Notifying Jenkins Server to execute a Build on' $machine
curl -X POST http://$machine:8080/job/mkat_fpga_tests_4k/build

Screenshot_2017-04-05_12-57-44

Assumptions:
Git version > 2.6
Jenkins version > 2.0
Git Plugin (Jenkins)
Gitlab hook (Jenkins)

3. Configure Jenkins 

Configure your Jenkins job to be able to “Trigger builds remotely”

Screenshot_2017-04-05_13-18-19.png

Enable SCM polling for each project you want to notify:

  1. Go to the Dashboard.
  2. Click on your project.
  3. Click Configure.
  4. Under Build Triggers check the box for Poll SCM.
  5. Repeat for any other projects.

The notification you send tells Jenkins to poll the repository, so projects will only respond if SCM polling is enabled.

 

Now Jenkins will runs automatically when I/we commit and push using Git via CLI.

Done.

Allow users of a certain group to run a command without sudo passwd

Time to time I usually find myself typing sudo to execute commands requiring sudo rights, and this is repetitive which simply means one gets weary of typing sudo password every time, hence this blog post. Reason for this is to remind me how to do it the next time I am faced with such conundrum(s).

Suppose I wanted to add a group of users who are allowed to run mount and umount without passwords. So I first want to add a group called “staff”

sudo groupadd staff

Next we need to edit the /etc/group and add the users

staff:407:

will be present ,hence append users you want to add the users separated by commas.

staff:x:407:user1,user2,...

Now we need to configure sudo to allow members of the “staff” group to actually invoke the mount and umount commands.

You just need to add the following lines to /etc/sudoers or execute sudo visudo

%staff ALL=NOPASSWD: /sbin/mount, /sbin/umount

Now sudo mount won’t ask password but since it is a pain in the butt typing sudo all the time, we can avoid it by doing the following:

I can create the following script called “/usr/bin/mount” (and similar script for umount)

#! /bin/sh
sudo /sbin/mount $*

To make this slightly more secure, We might want to change the ownership of these scripts to the “staff” group.

chgrp staff /usr/bin/mount /usr/bin/umount

and then make them executable only for the group “staff”

chmod g+x /usr/bin/mount  /usr/bin/umount

Note:Depending on the OS you are using please check where mount and umount commands are located. It might be in /bin/ instead of /sbin.
So you might have to make necessary changes

 

Done