Creating an online service – Using cloudbees for Continuous Deployment with Basic Service based projects
The previous post discussed getting the basic service application to your local development environment and getting it setup. In this post I’ll describe the process of setting up cloudbees for working with a Basic Service like project, so we can close the loop all the way to production.
We’ll be using cloudbees’ SEND-GRID services to send emails (registration verification process uses it to send a confirmation email), so before going further, go into cloudbees->services, and activate SendGrid. You can pick the free account for now.
Before creating a new git repository in cloudbees, we need to do some housekeeping in Git. Git has a file called .gitignore, which helps tell git what you don’t want to monitor and commit. At the very least, add the following entry:
to the .gitignore file (create the file if it does not exist in your main project directory). This will prevent you from accidentally checking in your targe directory (which is built automatically by the cloudbees CI environment). Now that we have this covered, it’s time to get started.
Setting up a git repository in cloudbees is easy, just pick Repositories->create new repository, give it a name and pick Git as your repository type, and click enter.
Once that repository is done, you need to connect your local repository to the cloudbees one so you can push your code. After creating your repository, you will see some helpful short examples of how to connect to cloudbees (just below the details paragraph). Pick “Migrating to your cloudbees repository”, and follow the steps. Don’t pull/push from legacy, just use the remote rm command to remove the old repository. Alternatively, you can delete the .git directory and start a new git repository from scratch (without the basicservice history). Just follow the “committing an existing project to git” cloudbees instructions to do that instead.
You repository should now be about 0.6MB, and contain the project files.
Once you’ve setup your repository, the next thing you need to do is setup a Build configuration.
Before going to builds, open your repository details, and copy the uri starting with ssh:// (you will need it shortly)
Hit builds, and create a New Job.
Give it a name, and pick “Build a maven 2/3 project”. Hit next.
Mark “one click deployment”, select “Oracle 1.7 latest” as your JDK, unclick “restrict where this project can run”, select “git” as your repository.
In the git url paste the ssh:// url you copied earlier. Put two stars (**) in the branches to build input field.
In build->goals and options put: clean install
In post steps, select “run only if build succeeds”, in the build settings, mark the email notification and add your email so you get notified of checkins and builds.
Pick “abort the build if it’s stuck” and pick whatever makes sense to you (I chose elastic)
Add a post-build-action and deploy-to-cloudbees, add web application and pick “maven artifact selection”. Add an application id (your project name is fine). Click “Advanced”, and enter production in the “Environment” field.
Don’t worry about the “not found” warning, click save.
Click build Now, and when an available worker is ready your project will start building. Click the running build and then console Output to see the process in action. When the build is complete, you should see something like:
[cloudbees-deployer] Deployed to application id your_account/your_project [cloudbees-deployer] Can be accessed at http://yourproject.youraccount.cloudbees.net
Click it and start playing around with your production online service!
One last small thing left to do: setup our domain. We’ll cover this in the next post.
I recently had to take my cloudbees hosted repository hosted on, well, cloudbees, and move it to github. This was a bit tricky for someone will little knowledge of ssh and git (me), so hopefully if you’re in my situation this will help. Note that this was done on a Mac OSX, should be similar for other unix based OS’s but probably slightly different for Windows.
I’ve used green color to represent terminal commands, so if you see something in green, it obviously needs to go into terminal…
First create a new account and repository on github.
Once you do that, you need to setup your ssh connection to git (you can also connect using http, but I’ll stick to SSH for now). There’s a pretty good explanation by git-hub here, which I followed (well, some of it), but basically here’s what you need to do:
- Go to command terminal, and enter the following command which will copy your ssh public key to the clipboard
pbcopy < ~/.ssh/id_rsa.pub
- If id_rsa.pub was not found, you need to generate a new ssh key locally, follow the git-hub tutorial mentioned above to do that.
- Go to your github account settings->ssh keys, and click “add SSH key”. Give it a name and paste your key.
- In terminal, enter
- This should give you a print of your key hash, make sure it is identical to what you see in your git-hub listing. It should look like this:
- In terminal, go to your repository directory (e.g. ~/code/basicservice/)
- make sure you have a git repository there:
- Create a new repository on git-hub, don’t initialize it with README
- Push your repository to git-hub
git push email@example.com:<youraccount>/<your-repository>.git master
you can get the git url from your git repository page, make sure you click on SSH to get the right url, or just replace <youraccount>/<your-repository> with your data.
- That’s it. Your repository is now hosted on git-hub as well, you can now drop the cloudbees repo and start using git-hub. To make it push both to cloudbees and to github simultaneously (if you want to keep both) you need to add some configuration, and I’ll pass on that right now. You can check out this post for help on that.