Deploy Your Code Faster: Gitblit in the Cloud

GitMost developers have their public or private Git repositories. For now Git is the most popular version control system designed to handle everything from small to very large projects with speed and efficiency. Moreover it is easy to learn and has a tiny footprint with lightning fast performance. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server.

There are tons of tools that help developers to manage, view and serve such repositories and Gitblit is one of the best. It is designed primarily as a tool for small workgroups who want to host centralized repositories. You can use it as a dumb repository viewer with no administrative controls or user accounts, as a complete Git stack for cloning, pushing, and repository access control. In addition Gitblit can be freely used without any other Git tooling (including actual Git) or it can cooperate with your established tools. BTW administrators can create and manage all repositories, user accounts, and teams from the web UI

Let’s look at how to run Gitblit in the cloud and simplify Java and PHP app deployment using this great tool.

Create an environment

1. Go to Jelastic.com and sign up if you haven’t done it yet or log in with your Jelastic credentials by clicking the Sign In link on the page.

2. While in Jelastic dashboard, click the Create environment button.

3. In the Environment Topology dialog, pick your application server (for example, Tomcat 7). Then type your environment name, for example, gitblit.

gitblit

It will take just a minute for your environment to be created.

gitblit1

Upload Java package

1. Navigate to gitblit.com and download Gitblit WAR file.

gitblit2

2. Upload your Java package to the Deployment manager.

gitblit3

3. Once the package is in Jelastic, deploy it to the environment you have just created.

gitblit4

Now you can open your app in a web browser, log in (the default credentials are admin/admin) and start using it.

gitblit5

gitblit6

Java project deployment

Let’s examine how to deploy your Java project from Gitblit to the cloud in a few minutes.

1. Create your new repository.

gitblit7

2. As you can see your repository is successfully created.

gitblit8

3. Push your project to the repository you have just created, using the next scenario:

  • Clone your empty repository into a newly created directory, using the next command:
git clone http://{env_name}.{hoster_domain}/{db_name}/git/{repository_name}.git
  • Add your project to the newly created directory.
  • Navigate to the folder you have just created and add file contents to the index, in our case we just copied simple Maven based Hello World Application:
git add .
  • Record changes to the repository using for example “Initial commit” as the commit message:
git commit -m "Initial commit"
  • Add your github repo as a remote to your local git repo:
git remote add gitblit http://{env_name}.{hoster_domain}/{db_name}/git/{repository_name}.git
  • Push your project to your Gitblit repository:
git push gitblit master

gitblit9

4. Go back to the Jelastic dashboard and create a new environment for your application: pick your application server (e.g. Tomcat 7), select Maven as your building tool and type the environment name.

gitblit10

6. When your environment is successfully created add your project to Maven.

gitblit11

7. In the dialog, navigate to Git tab: specify your project name and Path to the repository, which you have created earlier, enter the Branch, Login and Password to your repository (it it’s private), name of your Environment and Context in which you will deploy your project.

gitblit12

8. Click Buid and deploy button for your project.

gitblit13

9. As you can see your project was successfully built and deployed and now you can open it in a web browser.

gitblit14

PHP project deployment

Now it’s turn for PHP project.

1. Create a new repository for your PHP project using Gitblit.

gitblit15

2. Push your project to the repository you have just created, using the next scenario:

  • Clone your empty repository into a newly created directory, using the next command:
git clone http://{env_name}.{hoster_domain}/{db_name}/git/{repository_name.git}
  • Add your project to the newly created directory.
  • Navigate to the folder you have just created and add file contents to the index, in our case we just created index.php file with phpinfo() function inside:
git add .
  • Record changes to the repository using for example “Initial commit” as the commit message:
git commit -m "Initial commit"
  • Add your github repo as a remote to your local git repo:
git remote add gitblit http://{env_name}.{hoster_domain}/{db_name}/git/{repository_name.git}
  • Push your project to your Gitblit repository:
git push gitblit master

3. As you can see your project was successfully pushed to Gitblit.

gitblit21

4. Go back to the Jelastic dashboard and create a new environment for your PHP application: pick Nginx (or Apache) as your application server and type the environment name.

gitblit16

5. Add your project to Nginx.

gitblit18

6. In the dialog, navigate to Git tab: specify the Path to the repository, which you have created earlier, enter the Branch, Login and Password to your repository (it it’s private) and the Context in which you will deploy your project.

gitblit19

7. Now you can open your app in a web browser.

gitblit20

As you can see it’s very easy to get your own online project hosting in the cloud. Manage, view, serve your repositories, then build and deploy them automatically without any code changes or additional configurations. Enjoy all the advantages of the cloud!

Feel free to ask any questions!

2 Responses to “Deploy Your Code Faster: Gitblit in the Cloud”

  1. James MogerJames Moger

    Very interesting. I was not aware that Jelastic offered local storage. How much local storage do you get for your repositories? The default settings store data and repositories in the WEB-INF/data folder. What happens on a redeploy? How do you update to a newer Gitblit version while preserving your data?

    Reply
    • Marina Sprava

      Hello James!
      Thanks for your interest to our service. Here are my answers:

      >How much local storage do you get for your repositories?

      It depends on your container, beginning from Jelastic release 1.9 you can simply upload all your files via FTP.

      >The default settings store data and repositories in the WEB-INF/data folder. What happens on a redeploy?

      All the files will be rewritten.
      Actually, I have not tried it earlier but I would suggest you the following scenario:
      -you deploy your application (my-context, for example)
      -also you create folder /webapps/{my_folder}
      -then you store files in my_folder from app which is deployed to my-context
      Due to Jelastic new feature (add-on) FTP(S) (http://jelastic.com/…tp-ftps-support) which allows you establishing remote connection to your app server and have an access to folders, you will be able to download all needed content from context where you want execute new deployment and then upload back all needed content to app server by FTP(S) once deployment is finished.

      >How do you update to a newer Gitblit version while preserving your data?

      You can simply add the files which are needed or redeploy new war archive (using the same approach with downloading and uploading via FTP)

      Reply

Leave a Reply