Pages

Saturday, January 9, 2016

GitBlit – Source Code Repository tool

Share it Please
Most of the Open Source projects are being hosted on Git Hub now days. People connect to Git hub using a version control tool ,get code and push code. In other cases , some organizations don’t want their source code to be hosted on internet but they want to implement a process much like Git hub.

Git-blit is one such tool which provides source code management services much like Git hub. We can configure Git-blit locally so that application teams connect to them, push, get and clone codes. This article will be a introduction of Git-blit and we will also see how we can configure a source code repository locally using Git-blit.

Introducing GitBlit
It is a Open Source, pure Java Stack for managing, Viewing and Serving Git repositories. It bundles all dependencies so that you can go from zero to Git in less than 5 minutes. It's designed primarily as a tool for small workgroups who want to host centralized repositories.

Download and Configure
Download gitblit directly from the Site over here. Extract the downloaded tar file. There is need for one basic configuration before starting the gitblit. Move to the gitblit/data/ location and open the gitblit.properties file. Add the below lines,

git.repositoriesFolder = /var/www/github
git.httpBindInterface = <IP address of the local Machine>
server.httpPort = 1337

Once these 3 lines are added which allows us to access the gitblit site on the IP address we defined and on the port 1337. The source code will be stored in /var/www/github location. Once changed save and start the shell file gitblit.sh in the main location.

[root@vx111a gitblit-1.7.1]# sh ./gitblit.sh
2015-12-31 11:38:59 [INFO ]
_____ _ _ _ _ _ _
| __ \(_)| | | | | |(_)| |
| | \/ _ | |_ | |__ | | _ | |_
| | __ | || __|| '_ \ | || || __| http://gitblit.com
| |_\ \| || |_ | |_) || || || |_ @gitblit
File: /root/Desktop/Docker.txt Page 32 of 37
\____/|_| \__||_.__/ |_||_| \__| 1.7.1
2015-12-31 11:38:59 [INFO ] Running on Linux (3.10.0-327.el7.x86_64)
2015-12-31 11:38:59 [INFO ] Logging initialized @717ms
2015-12-31 11:38:59 [INFO ] Using JCE Standard Encryption Policy files, encryption key lengths will belimited
2015-12-31 11:38:59 [INFO ] Generating Gitblit Certificate Authority (/test/gitblit-1.7.1/data/certs/caKeyStore.p12)
2015-12-31 11:39:00 [INFO ] Generating Gitblit Certificate Authority CRL (/test/gitblit-1.7.1/data/certs/caRevocationList.crl)
2015-12-31 11:39:00 [INFO ] Generating SSL certificate for localhost signed by Gitblit CertificateAuthority (/test/gitblit-1.7.1/data/serverKeyStore.jks)
2015-12-31 11:39:01 [INFO ] Importing Gitblit Certificate Authority into trust store (/test/gitblit-1.7.1/data/serverTrustStore.jks)
2015-12-31 11:39:01 [INFO ] Setting up HTTPS transport on port 8443
2015-12-31 11:39:01 [INFO ] certificate alias = localhost
2015-12-31 11:39:01 [INFO ] keyStorePath = /test/gitblit-1.7.1/data/serverKeyStore.jks
2015-12-31 11:39:01 [INFO ] trustStorePath = /test/gitblit-1.7.1/data/serverTrustStore.jks
2015-12-31 11:39:01 [INFO ] crlPath = /test/gitblit-1.7.1/data/certs/caRevocationList.crl
2015-12-31 11:39:01 [INFO ] Setting up HTTP transport on port 1337
2015-12-31 11:39:01 [INFO ] Shutdown Monitor listening on port 8081
2015-12-31 11:39:01 [INFO ] jetty-9.2.13.v20150730
2015-12-31 11:39:01 [INFO ] NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IRuntimeManager]----
2015-12-31 11:39:01 [INFO ] Basefolder : /test/gitblit-1.7.1/data
2015-12-31 11:39:01 [INFO ] Settings : /test/gitblit-1.7.1/data/gitblit.properties
2015-12-31 11:39:01 [INFO ] JVM timezone: Asia/Kolkata (IST +0530)
2015-12-31 11:39:01 [INFO ] App timezone: Asia/Kolkata (IST +0530)
2015-12-31 11:39:01 [INFO ] JVM locale : en_US
2015-12-31 11:39:01 [INFO ] App locale : <client>
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.INotificationManager]----
2015-12-31 11:39:01 [WARN ] Mail service disabled.
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IUserManager]----
2015-12-31 11:39:01 [INFO ] ConfigUserService(/test/gitblit-1.7.1/data/users.conf)
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IAuthenticationManager]----
2015-12-31 11:39:01 [INFO ] External authentication disabled.
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.transport.ssh.IPublicKeyManager]----
2015-12-31 11:39:01 [INFO ] FileKeyManager (/test/gitblit-1.7.1/data/ssh)
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IRepositoryManager]----
2015-12-31 11:39:01 [INFO ] Repositories folder : /var/www/github
2015-12-31 11:39:01 [INFO ] Identifying repositories...
2015-12-31 11:39:01 [INFO ] 0 repositories identified with calculated folder sizes in 9 msecs
2015-12-31 11:39:01 [INFO ] Lucene will process indexed branches every 2 minutes.
2015-12-31 11:39:01 [INFO ] Garbage Collector (GC) is disabled.
2015-12-31 11:39:01 [INFO ] Mirror service is disabled.
2015-12-31 11:39:01 [INFO ] Alias 'UTF8', UTF-9 & UTF-18 encodings as UTF-8 in JGit
2015-12-31 11:39:01 [INFO ] Preparing 14 day commit cache. please wait...
2015-12-31 11:39:01 [INFO ] 0 repositories identified with calculated folder sizes in 0 msecs
2015-12-31 11:39:01 [INFO ] built 14 day commit cache of 0 commits across 0 repositories in 0 msecs
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IProjectManager]----
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IFederationManager]----
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.tickets.ITicketService]----
2015-12-31 11:39:01 [INFO ] NullTicketService started
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IGitblit]----
2015-12-31 11:39:01 [INFO ]
2015-12-31 11:39:01 [INFO ] ----[com.gitblit.manager.IServicesManager]----
2015-12-31 11:39:01 [INFO ] Federation passphrase is blank! This server can not be PULLED from. File: /root/Desktop/Docker.txt Page 33 of 37
2015-12-31 11:39:01 [INFO ] Fanout PubSub service is disabled.
2015-12-31 11:39:01 [INFO ] Git Daemon is listening on 0.0.0.0:9418
2015-12-31 11:39:01 [INFO ] Generating RSA-2048 SSH host keypair...
2015-12-31 11:39:03 [INFO ] Generating DSA SSH host keypair...
2015-12-31 11:39:03 [INFO ] SSH Daemon (NIO2) is listening on 0.0.0.0:29418
2015-12-31 11:39:03 [INFO ]
2015-12-31 11:39:03 [INFO ] ----[com.gitblit.manager.IFilestoreManager]----
2015-12-31 11:39:03 [INFO ] No filestore metadata file found
2015-12-31 11:39:03 [INFO ]
2015-12-31 11:39:03 [INFO ] ----[com.gitblit.manager.IPluginManager]----
2015-12-31 11:39:03 [INFO ] PF4J version 1.7.1 in 'deployment' mode
2015-12-31 11:39:03 [INFO ] Enabled plugins: []
2015-12-31 11:39:03 [INFO ] Disabled plugins: []
2015-12-31 11:39:03 [INFO ] No plugins
2015-12-31 11:39:03 [INFO ]
2015-12-31 11:39:03 [INFO ] All managers started.
2015-12-31 11:39:03 [INFO ]
2015-12-31 11:39:04 [INFO ] [GitBlitWebApp] init: Wicket core library initializer
2015-12-31 11:39:04 [INFO ] [GitBlitWebApp] init: Wicket extensions initializer
2015-12-31 11:39:04 [INFO ] [GitBlitWebApp] Started Wicket version 1.4.22 in deployment mode
2015-12-31 11:39:04 [INFO ] Started o.e.j.w.WebAppContext@2e7a9db7{/,file:/test/gitblit-1.7.1/data/temp/webapp/,AVAILABLE}{file:/test/gitblit-1.7.1/gitblit.jar}
2015-12-31 11:39:04 [INFO ] Started ServerConnector@1937dbc8{SSL-HTTP/1.1}{0.0.0.0:8443}
2015-12-31 11:39:04 [INFO ] Started ServerConnector

Once the server is started successfully we can see the main screen as
Use the IPaddress:1337 in the address bar to open the main page. Once the page is opened use the admin / admin for login.

Once login, we need to create a Repository to push our code. In order to create a repository click on the repositories link and we can enter the necessary details as,
I entered the name as “sampleApp” for my testing purpose. I have selected the “Restrict Push” so that any one can push and clone the code. Once changes are done , then save and we can see the next screen as,
We can also see the URL to which we need to push the code.

Push a Project
In order to push a code to the recently configured gitblit repository we need to follow the below steps

[root@vx111a work]# mkdir sampleGit
[root@vx111a work]# git init
Initialized empty Git repository in /work/.git/

[root@vx111a work]# touch index.html
[root@vx111a work]# git add .
[root@vx111a work]# git commit -m "Sample Git Hub Repository on Local Machine"
[master (root-commit) 1f14684] Sample Git Hub Repository on Local Machine
Committer: root root@vx111a.jas.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
2 files changed, 1 insertion(+)
create mode 160000 chef-repo
create mode 100644 index.html

[root@vx111a work]# git status
# On branch master
nothing to commit, working directory clean
Add a remote Origin as
[root@vx111a work]# git remote add origin ssh://admin@172.16.202.95:29418/sampleApp.git

We have added the remote origin with the same URL given during the Gitblit Repository configuration.

Push the Code to the remote Origin as
[root@vx111a work]# git push -u origin master
The authenticity of host '[172.16.202.95]:29418 ([172.16.202.95]:29418)' can't be established.
RSA key fingerprint is a5:60:6f:23:ff:7b:3d:26:b6:b1:75:d7:bd:34:91:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[172.16.202.95]:29418' (RSA) to the list of known hosts.
Password authentication
Password:
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 273 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Updating references: 100% (1/1)
To ssh://admin@172.16.202.95:29418/sampleApp.git
File: /root/Desktop/Docker.txt Page 34 of 37
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

Now the code is pushed to the repository locally.

Check the Code
We can check the code in our gitblit and we can see,
More to Come ,Happy Learning

No comments :

Post a Comment