Installing GitLab in your local network or your own PC and setting it up to work perfectly

Some Background

Online Git Hosting vs. Local Bare Repos

So you work very well using Git in your own PC and looking to get a couple of people in your local network to join with you in the project? There are couple of options available to you here: you either can initialize a bare Git repository for your project in one of the computers in your local network and have all the team members to use it as their origin repository, or you can create a repository in an online Git hosting service like GitHub and use that as your project’s central repository.

There are pros and cons in both methods. I will list some that comes to my mind.

GitHub or similar online Git hosting service.

Pros

  • You get a really nice GUI to manage your remote repositories.
  • You get an environment that encourage team work.
  • You can use “Merge Requests”/”Pull Requests” and have your team members review your code.
  • You get an issue tracking system, that heavily integrates with commits (You can mention the issue number in commit messages and the system will automatically link that commit to the mentioned issue!).
  • You can set permissions for each project member, whether they can only report issues, or develop features, or manage repository etc.

Cons

  • You have to have a working Internet connection to push your work, see issues, and collaborate with others.
  • You most likely have to pay for “Private Repositories”. You don’t really need your code to be open to the world, unless it’s a open source project, do you?
  • Even if you purchased a “Private Repository”, your code does reside in someone else’s server. Yes, yes, we trust GitHub. But what would happen should there be a security flow even they can’t controll, like Heartbleed?
  • Imagine you are an owner of a company, your employees can simply log into their GitHub account from their homes and clone the project to their own computers, can’t they? Private repositories won’t help here, as you have actually granted them access to it. You probably don’t want your employees taking the code home!

Bare repository in your own local network.

Pros

  • You control the hardware, you control the software on it.
  • You don’t need an Internet connection, just the local network is enough.
  • No one can access the repository from outside the office (Unless you explicitly made it possible.).
  • No payments are needed, you can create any number of repositories as you wish.

Cons

  • You can control it only through command line.
  • You have to use external tools for facilitating team work.
  • You will have to name a leader who will have to listen to other’s non-written requests to pull their code and merge to main branch.
  • You have to manually set user permissions on Git.
  • You have to manually set up a issue tracking system, and there won’t be any links between commits and the issues, you’ll have to map them in your mind!

What if there is something that gives you the best of both? Enter GitLab!

GitLab

GitLab is a Git repository management software, that does the same thing GitHub does, but in your own computer. It has a really beutiful GUI which makes it easy to manage remote Git repositories. Following are few options of it, in the order that they come into my mind.

  • Create and manage users.
  • Add SSH keys to user profiles, so they can securely access repositories.
  • Make repositories private, protected, or public, so that only assigned users, any registered user, or anyone can access them respectively.
  • Create branches and tags right from the GUI.
  • See commits and changes done in them.
  • Comment on commits, or comment per lines of code.
  • Receive email notifications when someone creates an issue and assign it to you, assign you to a new project, comment on one of your commits or a line of code within your commit.
  • Mention other users in your comments, so that they’ll receive notifications about them being mentioned in your comments.
  • Visualize each user’s contribution to the code base.

Apart from the above features in the software itself, you get following benefits:

  • You get a really nice GUI to manage your remote repositories.
  • You get tools that encourage team work.
  • You can use “Merge Requests”/”Pull Requests” and have your team members review your code.
  • You get a issue tracking system, that heavily integrates with commits (You can mention the issue number in commit messages and the system will automatically link that commit to the mentioned issue!).
  • You can set permissions for each project member, whether they can only report issues, or develop features, or manage repository etc.
  • You control the hardware, you control the software on it.
  • You don’t need an Internet connection, just the local network is enough.
  • No one can access the repository from outside the office (Unless you made it possible.).
  • No payments are needed, you can create any number of repositories as you wish.

Can you see what I did there? I just copied and pasted the pros sections of GitHub like online services, and having Git bare repositories in a local machine together. I think that clearly explains the value of GitLab, if not, please say it in the comments section. :)

Above are just a few good things about using GitLab. If you’d like to see it for yourself, you can read GitLab specific articles, and search YouTube for “GitLab”; I find watching videos of a software is the best way to get a feeling about it before you even try downloading it.

GitLab also offers a SaaS (Software as a Service) option called “GitLab.com”. Just like GitHub, you can sign up for an account there and create some repositories to test it. Of course you can do your projects just using GitLab.com without even installing GitLab on your computer, but my goal is to guide you through the process of creating a GitLab server in your own work space.

Prepararing, Installing, and Configuring GitLab

I recently installed GitLab in my office. So I will just tell you the way I did it, so that you’ll be able to learn something from my first hand experience and do it yourself.

Without digging in to details, I will first just tell you the overall steps I took in order to get my GitLab installation working perfectly.

First I got a computer and installed VirtualBox in it. The operating system of this machine is not important, because we will be installing GitLab inside VirtualBox. I will explain why I used VirtualBox later. Then I created a Virtual Machine with Ubuntu as it’s operating system. Using Ubuntu as the OS of the VM is important. Then, within the VM, I downloaded the installer DEB file for GitLab and installed it. Then I made GitLab available to anyone in the same network as the host machine. Finally I did some configurations within GitLan to make it fully functional.

Yes, that’s all what I did. So let’s get into details.

The Host Machine

The host machine I used has 4 GB of RAM and a 2+ GHz Core 2 Duo processor. I am not a hardware geek, but I guess that’s about the lowest specifications that VirtualBox can run without slowing down like a sloth.

The Virtual Machine

Download and install VirtualBox in your host machine. Then create a Virtual Machine with about 1.5 GB RAM and a expandable Virtual Hard Disk. I suggest using VMDK format for the disk, as it will come handy when you back the VM up.

Once the VM is created, download Ubuntu Disk Image, load it to VM’s optical drive, and install Ubuntu on your VM. I am not going to walk you through the process of installing Ubuntu, as it is more than simple. But keep it in mind that, when you are given the option to partition the hard disk within the Ubuntu installer, just use the entire hard disk. There is no use in partitioning the virtual hard disk.

The main reason for using a VM is that GitLab uses it’s own version of Ngnix as a web server and it takes control of the port 80 of the machine you install GitLab. Installing GitLab directly on a machine, in which you might want to install Apache or any other software will make a mess; it’s not impossible to get them to co-exist, but why bother when you have an easier and more rewarding method?

The other reason for using a VM is that you can back the entire VM up for safe keeping. It is much easier than backing up GitLab alone, and when you back the VM up, you get all it’s configurations and settings with the back up archive. Should something go wrong, you only have to restore the VM, and all it’s settings and installed programs (Including GitLab) will be available.

Installing GitLab

Once Ubuntu is successfully installed in your VM, boot it up, and within the VM, navigate to GitLab’s website, and download “GitLab Community Edition” (“GitLab CE”) for Ubuntu. The version number of Ubuntu mentioned in the GitLab’s installer package doesn’t matter (When I installed GitLab, it worked fine in Ubuntu 14.04 although it said it’s for Ubuntu 12.04 in the file name.).

Once the DEB file is downloaded, go ahead and install it. I prefer to use the command line for this.

cd to-the-directory-you-downloaded-gitlab-deb
sudo dpkg -i the-name-of-gitlab-deb-file

This will install GitLab on your VM. At the end of the installation, you will be instructed to

sudo gitlab-ctl reconfigure

Now restart the VM for good meassures. Once it is back up, try going to http://localhost inside your VM.

If go to http://localhost as soon as the VM booted up, you’ll see a 502 error; don’t panic, it’s normal; GitLab need a couple of minutes to fully awaken itself.

Once the 502 error is gone, you will see a login window. The default username is “root” and the default password is “5iveL!fe”. Once you are logged in, you’ll immediately be given the chance to change the password to one of your own. Do that and turn the VM off. It’s true that the GitLab is up and running. But we got more work to do.

Making GitLab available from the network

Although GitLab is up and running, it can only be accessed within the VM yet. We need to make a couple of changes to the VM and make GitLab accessible to any machine in the network to which the host machine is connected.

Once the VM is turned off, right-click on our VM in VirtualBox manager window, and go to “Settings”. Inside the Settings window, go to the “Network” section. Here, activate two network connections. First one should be a bridge and the second should be a NAT.

GitLab Network SettingsGitLab Network Settings

Now boot the VM up again, and in it’s network manager, edit the bridged connection to have the static IP address 192.168.1.99 (Or something you like, I went with the above.).

 

To do that we need to find among the two network connections available to the VM, which is the bridged connection and which is the NAT connection. So, open up a terminal in Ubuntu, and issue following command:

ifconfig

It’ll show an output like the following:

Fining network configurations in Ubuntu.

Here we can see the IP address of “eth1″ connection is 10.0.3.15. This is the NAT connection. As you can see, the IP address of the “eth0″ is already 192.168.1.99, that’s because I am taking screenshots from an already configured VM. But you’ll see a different IP address here, probably within 192.168.XXX.XXX range. This is the bridged connection.

To assign a static IP address, open the network menu in Ubuntu, and click “Edit Connections…”.

Ubuntu Network Connections

That’ll show you a window titled “Network Connections”.

Ubuntu Network Connections

From this window, select the bridged connection (“eth0″), and click “Edit…”. In the window that would open, go to the “IPv4 Settings” tab, and make changes to the settings mimicking the following screenshot.

Editing Network in Ubuntu

If you want to use a different IP address than 192.168.1.99, set what you like under the “Address” column. Then restart the VM.

From here on, your GitLab installation will be accessible to any machine in the host machine’s local network by goin to http://192.168.1.99 through the web browser.

GitLab accessed from a remote PC.

Enable Email Notifications

I found how properly configure SMTP email sending in GitLab from http://blog.fizyk.net.pl/blog/configure-gitlab-with-smtp-mail-server.html, feel free to go thank him.

By enabling email notifications, you cut off the need to go to every project you are a member of and seeing if there’s anything new that you should be aware of.

We need to have a SMTP server configured for GitLab to send email through. I am using a service called “MailGun.com”, which allows up to 300 mails to be sent for free per a day. You might either want to buy their paid subscription or use an alternative; but for now MailGun is enough for me.

Choose a SMTP service you like, and acquire it’s settings.

Then open the file

/opt/gitlab/embedded/service/gitlab-rails/config/environments/production.rb

in a text editor as root, and find the string that says

config.action_mailer.delivery_method = :sendmail

and change it to this:

config.action_mailer.delivery_method = :smtp

Then go to

/opt/gitlab/embedded/service/gitlab-rails/config/initializers

You can see there is a file named “smtp_settings.rb.sample”; we need to make a copy of it. Then open the newly created file as root in a text editor. And change the settings in that file to look like the following.

if Rails.env.production?
 Gitlab::Application.config.action_mailer.delivery_method = :smtp
 ActionMailer::Base.smtp_settings = {
 address: "smtp.mailgun.org (Your SMTP server address.)",
 port: 587 (Your SMTP server port.),
 user_name: "you@sandboxXXXXX.mailgun.org (Your SMTP server username.)",
 password: "XXXXXXXXXXXXXXXXXX (Your SMTP server password.)",
 domain: "your.fake.domain (The domain you need your email to be appeared sent from.)",
 authentication: 'plain',
 enable_starttls_auto: true
 }
end

To test email sending, create another user with a legit email address, activate that account, and from the admin account create a test repository and add the new user to it as a developer, if mail configuration is done okay, the new user’s email account should get an email about himself being added to the new project.

If something goes wrong here, let me know.

Setting the static IP address as the Host Name of GitLab

GitLab automatically uses the hostname of it’s operating system as it’s host name. This is not a problem, but it’ll result in useless addresses like the following in GitLab.

GitLab Access

We need it to be like this instead:

GitLab Access

So you don’t have to remember to replace “VirtualBox-PC” with “192.168.1.99”, every time you have to use this.

To do that, open the file

/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

and find the string that says

host: VirtualBox-PC

This should be in the very top section of the file, so it won’t be hard to find this. Replace it with the IP address you previously selected, so that it’ll look like this:

host: 192.168.1.99

Now GitLab will use the IP address in place of hostname.

Upgrading GitLab

Upgrading GitLab is very easy. Just download the DEB file for the new version of GitLab, and install it just like you did the first time.

Remember to back the VM up before upgrading though!

Howeverv, when you upgrade your GitLab installation, the hostname we changed will be reverted to default. You will have to repeat the step “Setting the static IP address as the Host Name of GitLab” to set it again.

Backing the VM Up

I take backups of the VM in my office at the end of every working day. I suggest you do the same. To do that, first turn the VM off, and in the VirtualBox Manager, choose “File -> Export Applicance…”.

Exporting VirtualBox Appliance

Then choose the VM you need to backup (If you have more than one VMs.).

Exporting VirtualBox Appliance

Next, choose a place to save the back up. Remember to save the backup with the OVA extension.

Exporting VirtualBox Appliance

Now you know how to successfully setup GitLab, work with it, and manage it in your own local network.

Will the blogging platform “Ghost” be successful?

Ghost” is the newest player in the field where blogging platforms compete. It’s creator John O’Nolan’s blog post explains why he saw the need for a new platform. Basically, he created Ghost because his ex-favorite blogging platform WordPress is no longer just a blogging platform. He still loves WordPress as a platform on which advanced websites can be created, including blogs, but for someone who want something for “just blogging” he thinks WordPress is too much; So he created “Ghost”.

I tried Ghost

The self hosted edition of Ghost has been out for quite a while, but I received an invitation to try out the hosted edition yesterday.

Invitation to try out

Invitation to try out

I clicked on the get started link and it took me to the login page.

Ghost Login Page

Once you’re logged in you can start a blog hosted in Ghost’s servers, or download a copy of Ghost to install on your own server.

Ghost Home Page

I wanted to try Ghost on their server, so I clicked “Start a New Ghost Blog” button, and I was given the choice to select a plan.

Ghost Select Plan Page

There was an option to try Ghost for free for 30 days; I choose that. And I got your typical screen to set a blog name and (sub) domain.

Creating a Ghost Blog

Once that is done, a page with the list of blogs I have created on Ghost, is presented.

Ghost Blogs List

This is how a Ghost blog looks like just after it’s created.

Front end of a Ghost blog

Following is the page where you can see all the posts you have written in your Ghost blog.

Ghost Posts List

You have a menu to access account settings in the top right.

Ghost Account Settings

When you click the “Settings” button, you’ll get a screen where you can change settings of the blog.

Ghost Blog Settings

You can change your profile too.

Ghost Change Profile

Ghost Change Profile

You can change or view details of posts by clicking on the gear icon at the top right corner of posts.

Ghost Post Details

When you click on the “New Post” button, you get an empty screen like the following. You write on the left side while you can view a live preview on the right.

Ghost Post Details

This is how you write posts in Ghost.

Ghost Post Details

You can set vanity URLs for the posts.

Ghost Post Details

There are no categories, but you can tag posts.

Tags in Ghost

You can save drafts and publish them when they’re ready.

Tags in Ghost

This is the homepage with a recently published post.

Tags in Ghost

And this is the single post page.

Tags in Ghost

I like Ghost

Just like Medium, Ghost is so minimalistic, and I like that. It is very writer friendly and inviting to write. It indeed is distraction free. If you are familiar with markdown, you can easily format your writings in Ghost; you can use the universal keyboard shortcuts like “Ctrl+B”, “Ctrl+I” as well. Just like John O’Nolan wanted it to be, it is just a blogging platform; no more – no less.

But…

Will it succeed? Ghost have all the functionality to be the one thing it intends to be – just a really simple blogging platform. But will it be able to reach writers without technical knowledge or financial back up?

First of all, there are no any free plans for their hosted platform. When WordPress.com and Blogger are offering free hosted blogging platforms, why would someone choose Ghost paying 5USD per month for the cheapest plan? For the simplicity of Ghost you say? If you don’t make it complicated with plugins and more, WordPress is simple enough out of the box. Of course you can’t install plugins in the hosted edition of WordPress, either.

The self hosted edition is free. But you won’t be able to run it on your typical Apache, PHP shared hosting account. You’ll have to buy a VPS (Virtual Private Server) and install Node.js to be able to install Ghost.

Neither is the cheapest way for someone who is looking to start a blog on a low budget. The latter requires some proficiency in technology to handle a VPS; someone who is comfortable with that will be very very very comfortable with using WordPress and won’t find it as complex as Ghost people say, and they’ll even appreciate the extendability of WordPress.

What do you think? Will Ghost be successful?

[Today I Learned] Insert and Update rows with MySQL “ON DUPLICATE KEY UPDATE”

Today at work, I had to create a SQL query that’d insert some rows to a MySQL table. The rows are not user generated, they are dynamically created through several SQL queries. The results of the queries should be entered to a separate table, unless if they’re already inserted.

Imagine there’s a table called “library_lending”, which looks like the following.

CREATE  TABLE `library_lending` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `user_name` VARCHAR(45) NOT NULL ,
  `date` DATE NOT NULL ,
  `book_name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `user_date` (`user_name` ASC, `date` ASC) );

Please note that we have created a “Unique Index” (“Unique Key”) called “user_date” that combined both “user_name” and “date” fields. MySQL won’t allow inserting two rows that has same values for “user_name” and “date” fields. In other words, the above table is designed to keep records of people who’re borrowing books from a library, and this table won’t allow anyone to borrow more than one book in a day, because only one record can be inserted with same “user_name” and “date”. Continue reading [Today I Learned] Insert and Update rows with MySQL “ON DUPLICATE KEY UPDATE”

Features I don’t Use in My Smartphone

I bought my current smartphone Sony Xperia P on 1st December 2012 (Thanks Facebook Timeline!). Since then I have made a good use of it. It helps me to read mail, check-in to places, take photos, send and receive text messages, make calls and everything that a smartphone would do. However, I have noticed that I have never used some features packed with it. I am going to try and list them, so I can know what exactly I need from a smartphone, and that’d give me an idea of what should I look for in a future smartphone I might purchase.

Internal Storage

Sony Xperia P comes with a little more than 11GB of internal storage available for users. From that, I have only used about 2GB of that! This is because I don’t use my phone as a “file storage facility”. I don’t listen to music on phone regularly, so I don’t have to store music in it like most people do. I think an smartphone with about 8GB of internal storage would be more than enough for me.

Features I don't Use in My Smartphone - Internal Storage

WiFi Hot Spot

My phone can act as a WiFi Hot Spot if necessary. I have used it one or two times, but I decided not to use that ever again. Ever. Turning the WiFi Hot Spot drains the battery so fast and heats the phone too much. I could even fry an egg on the phone while the WiFi hot spot is on.

NFC

After testing the feature with Praboda’s Xperia V, I haven’t use NFC in my Xperia P. I know it’s cool when you can tap another device with your phone and send files, but the need never arose. And NFC enabled payment systems are at least a decade in the future for us Sri Lankans.

Ring and Notification Tones

This might not be a big deal, and may be just me. I use a plain ring and notification tones, and I never change them. So the dozens of different tone options go unused.

Pre Installed Apps

Here are a list of apps Sony had installed on my phone and I then uninstalled (Actually I froze them using “Titanium Backup”).

  • All the themes except the one I am using. I’d never change it.
  • Back Up and Restore. I don’t store any file in my phone. My emails are already backed up in GMail, and I save my text messages to PC once a month or so.
  • Stock Browser. I use Chrome and Dolphin.
  • Stock Email Client. I use GMail app, Outlook app, and SolMail for other email accounts.
  • Text Messenger. I used this for a long time. But as Google Hangouts now support text messaging, I said goodbye to the stock text messaging app.
  • SenseMe. I guess it is Sony’s alternative to Shazam. I use Shazam.usage-of-features-and-functions-in-a-software-system
  • Sony Select. Sony’s “recommended” apps can be found in this. Duh. Why waste time Sony? I know what I want, and Google Play’s own recommendations are better.
  • Timescape. Updates from social networks are displayed “beautifully” in this app. Why?
  • Voice Dialer. It can’t recognize Sinhala names, which almost all of my contacts have.

Features I don't Use in My Smartphone - Pre Installed Apps

Do you use all the features of your phone? What are the ones you don’t use?

PS:

The featured image was taken from http://www.softwareresults.us/2011/07/where-do-unused-features-come-from.html. It shows most of the features in a software system goes unused. I think it’s the same for phones.

usage-of-features-and-functions-in-a-software-system

Following-up your own Tweets and Creating a Sensible Thread

We all have faced that moment when we need to add a little more to your last tweet. May be what you have in mind can’t simply fit into 140 characters limit, and you need to find a way around to get your whole opinion out there. May be you tweeted something and then you remember you need to add something more to it.

I have seen some people divide ideas into multiple tweets and place “1st of 3″, “2nd of 3″ etc at the end of the tweet, so that people who sees that would look for next tweets as well. Some simply use “1/3″, “2/3″, “3/3″. This approach doesn’t do anything more than letting people know there are more tweets related to the one someone just saw. They have to come to your Twitter profile and look for the other related tweets. If the tweet is few days or more old, they will have a hard time searching for it and it’s most likely that they will never bother to.

The only solution is finding a way to display all the related tweets in one place.

That is impossible, right? We don’t have any options to tell Twitter that there will be following-up tweets for the one you’re currently tweeting, or tell it that the current tweet is a follow-up for a previous one. Well, not really – we have that option. But it is hidden in the plain sight.

We all know that Twitter can identify replies to tweets and it can display a tweets with all the replies to it. We are going to use that feature for our purpose. I am not sure whether Twitter intended it this way, but it makes sense and does work. This can’t be any more simple – you just have to reply to your own tweet!

When you have a lengthy idea to be tweeted, just start typing. When you reach 133 characters, type “… TBC” so that people would know that the tweet isn’t complete and it is “To Be Continued”, and then tweet it. Now click the “Reply” button for the tweet you just tweeted. Twitter will automatically fill in your Twitter username and any other Twitter usernames you had in the last tweet in the reply box, just select them all and delete. Type the rest of the tweet. If your tweet is exceeding limits again, just repeat the process.

If you need to add something more or “comment” on a previous Tweet you tweeted, just find that old Tweet and reply to it. Just remember to delete unwanted usernames Twitter auto fills for you.

Following is an screenshot of a Twitter thread created that way:

Twitter Thread

On 11th of October, I have tweeted about a glitch I experienced in news reader app Feedly. On 17th, I found that they have fixed it. I needed to comment on my tweet about the glitch and say they have fixed it, so I did what I explained above. If someone directly come to the original Tweet, they’ll see my comment and know that the issue is no longer there.

Don’t forget to leave a comment and tell me what you think about this.

Credits: Some Image(s) From: http://wallnen.com/wallpaper/twitter-02-hd-wallpaper.html.

[Rant] “I won’t use Google Hangouts, until it adds an invisible mode!” – Me

Yeah, you read the title correct. Yeah yeah, I am a huge fan of Google and I have made fun of people who uses alternatives for Google’s products and services, like when someone uses Bing instead of Google Search, or Yahoo! Mail instead of GMail – the list goes on and on. But ever since the replacement of GTalk with Google Hangouts, I have stopped using it.

Why? I am glad that you asked. Well, here is the thing. I really like to be online in Google Hangouts, but the biggest problem is people come to talk… err… chat with me in it! You are always more than welcome to pass me “Instant Messages” in it, but if you wish to have long chit chats with me, I am not your guy. You see, I am not that talky and when I am online, I am always doing something productive – like scrolling through 9gag, and umm… well… you know what I mean.

I am sure I am not the only one who has done this. Back in the day, when we had GTalk, I was always in “Invisible Mode”. My friends knew I do that. So if anyone wanted to contact me, they could’ve just sent a message and see whether I’d respond. If I did, I was online, if I didn’t, I was either offline or didn’t want to talk to them. But it isn’t possible to hide the fact that you’re online in Hangouts.

Have you faced this trouble with Google Hangouts? What did you do about it?

Image from http://www.flickr.com/photos/mapleveins/5446464200/in/photostream/ .

GnuCash – The Free and Easy Accounting Software

I and one of my colleagues at Sanmark Solutions started a little side business couple of weeks ago. We immediately ran into the problem of managing and keeping track of money we put into that business and we spent for various things. Neither of us knew anything about accounting. So we clearly needed the help of a software, that would make it easier to handle it all for us. Continue reading GnuCash – The Free and Easy Accounting Software