Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Thursday, August 29, 2013

Configuring ssh for Jenkins for Git on Ubuntu

I ran into some problems configuring ssh for my jenkins box. It turns out that when installing jenkins on ubuntu via the package manager that jenkins is setup to run as its own user. So, Jenkins did not have access to my .ssh directory. Of course this made perfect sense once I stopped and thought about it.

Anyhow, I could not find a clear answer in one place so posted here. This assumes that you have an ssh key defined for your Git service of choice. I used the same key for myself and my Jenkins user. You can of course create your own ssh key for the Jenkins User.

1. Setup the Git settings for the Jenkins account - assume the identity of the Jenkins user and configure:

sudo su jenkins
jenkins@lubuntu:~$ git config --global user.email "some email address"
jenkins@lubuntu:~$ git config --global user.name "some name you associate with jenkins"
exit

2. cd to your user home directory and copy the .ssh key info into the Jenkins account.

cd /home//ssh
sudo cp id_rsa /var/lib/jenkins/.ssh/
sudo cp id_rsa.pub /var/lib/jenkins/.ssh/
sudo jenkins:nogroup chown /var/lib/jenkins/.ssh/id_rsa
sudo jenkins:nogroup chown /var/lib/jenkins/.ssh/id_rsa.pub

3. Assume the identity of Jenkins again, cd to the Jenkins directory, create a temporary directory, clone your repository from the Git repository, fix any issues this reveals then delete the temporary directory:

sudo su jenkins
cd /var/lib/jenkins
mkdir junk
cd junk
git clone git clone git@bitbucket.org:butbucket user name/user’s repository.git
cd ..
rm rf junk

4. Kick off your Jenkins build and verify that the Source Code Management plugin works.

Tuesday, March 5, 2013

Publishing Java to Heroku Cloud Service

Heroku is a jvm-based cloud service. They have scaling appliations and many of the features you expect to see in the cloud. The big thing for me is that it is simple setup, simple to understand, simple billing and lastly - simple to deploy to. Since I am very big on minimalism - Heroku is a huge win in the jvm based cloud arena.

You actually publish to the Heroku Cloud using git with just a handful of commands once you get the initial setup out of the way. Since the modern jvm culture loves git, using git to publish is very natural for jvm development.

Prerequisites


  1. Your project must be built via mvn. This can be done outside your ide of choice so won’t impact any notion of project files your ide may have.
  2. You need git. git is a version control system and has versions for all the major operating systems..  If you are running linux you probably already have it. If you need to install it, go here. http://git-scm.com/downloads
  3. You need a heroku account. http://heroku.com



Setup

  1. Install heroku Toolbelt to get Foreman, the Heroku command line client.
    1. https://toolbelt.heroku.com/
  2. Create a .Procfile.
    1. This file contains the command you want Heroku to execute immediately after the deploy is complete. So this is your java -jar command. Be sure to include any required parameters. This file has a single line:
      1. web: java -jar target/sebsApi-1.0.jar server configuration.yaml
    2. Heroku uses the Celadon Ceadar stack to manage jvm polyglot apps. That’s what the ‘web:’ flag is. Find more info here: https://devcenter.heroku.com/articles/cedar
    3. This file should be in your application’s root along side the pom.
  3. Create a system.properties file.
    1. This file is a a typical java properties file that describes unique config information for your app. This is where you can specify the java version:
      1. java.runtime.version=1.7
    2. This file should be in your application’s root, along side the pom.
  4. Store the app in locally in Git (if not done already).
    1. git init
    2. git add .
    3. git commit -m “some message”
  5. Add the Git remote for Heroku
    1. If you do not already have a heroku app, you need to create it.
      1. heroku create
      2. git remote -v
    2. If you already have the app created (available in the Heroku app dashboard) and you need to add a your Git local to the Heroku remote:
      1. heroku git:remote -a <app name>

Publish


  1. git push heroku master
  2. If you are new to git, be sure to commit before pushing. Any changes to local files must be committed to the local git repository before they can be pushed to the remote.

Verify

  1. Scale up a single web process (Dyno).
  2. Heroku calls their processes Dynos. You must have at least one running for your app to be available.
    1. heroku ps:scale web=1
  3. Check the status of the running Dyno:
    1. heroku ps
  4. View the website in a browser:
    1. heroku open

Other useful infos

Viewing the logs: heroku logs

Heroku assigns a port to the app. I don’t know the logic behind how it selects the port, but it is likely that it will be different every time you deploy. This makes sense when you think about scaling and multiple Dynos to support your app. So you will need to pass in an environment variable for the port as parameter in the Procfile if your app supports it:

In my case, for DropWizard:
web: java $JAVA_OPTS -Ddw.http.port=$PORT -Ddw.http.adminPort=$PORT -jar -jar target/sebsApi-1.0.jar server configuration.yaml






References

https://devcenter.heroku.com/articles/java#deploy-your-application-to-heroku
https://devcenter.heroku.com/articles/cedar
http://gary-rowe.com/agilestack/2012/10/09/how-to-deploy-a-dropwizard-project-to-heroku/