Setting up an Amazon EC2 Server to Run TeamCity

This post is a follow-up to my previous post - Intro to Continuous Integration with TeamCity. As I learned, TeamCity is best (for my project) when set up on an Amazon EC2 instance. Since we're using Git (via GitHub) for source control, TeamCity can listen to our GitHub repo and recognize when a commit has been made so it can run any appropriate build procedures.

This post makes the following assumptions:

In this post I will walk you through the following steps:

  1. Setting up an Amazon EC2 account
  2. Configuring and launching an instance
  3. Downloading and installing TeamCity on the instance
  4. Configuring TeamCity to communicate with GitHub*
  5. Saving the instance for later use

* These items will be covered in a later post.

Setting up an Amazon EC2 account

First, sign up for an account here: http://aws.amazon.com/ec2/

Once you have your account and billing in order, you should see Figure 1-1 when you log in. This is the main dashboard. You will spend most of your time with AWS working within this interface.

Figure 1-1 - Amazon EC2 Console Dashboard

Figure 1-1 - Amazon EC2 Console Dashboard

Configuring and launching an instance

From the Console Dashboard, click the "Launch Instance" button. A popup will appear that looks like Figure 2-1. If for some reason you don't see a "Getting Started" section with a "Launch Instance" button on the main dashboard, you can click the "Instances" link in the Navigation panel, then click the "Launch" button inside that screen. It should be to the top left of the main panel.

Figure 2-1 - Request Instances Wizard: Choose an AMI

Figure 2-1 - Request Instances Wizard: Choose an AMI

Click the "Select" button next to Basic 32-bit Amazon Linux AMI 2011.02.1 Basic. Figure 2-2 will appear.

Figure 2-1 - Request Instances Wizard: Instance Details

Figure 2-1 - Request Instances Wizard: Instance Details

From here I changed the Instance Type drop down to "Micro (t1.micro, 613MB)" just because I was testing and I believe the Micro instances are free. Leave all the other options set to default and click "Continue". You should now see Figure 2-3. (Update/Note: Micro instances are free for now, I'm not sure where I read this but they will eventually charge for using it. It may be a startup trial or something. Also, there is a specific reason why we're using a Micro instance which I will explain later. Also I've found out that our TeamCity system will require another larger instance for another reason which I will explain later.)

Figure 2-3 - Request Instance Wizard: Instance Details

Figure 2-3 - Request Instance Wizard: Instance Details

Leave all the defaults, click "Continue". See Figure 2-4.

Figure 2-4 - Request Instance Wizard: Instance Details

Figure 2-4 - Request Instance Wizard: Instance Details

I added "TeamCity Server" to the value of the first Name/Value pair. I'm not sure where this information is surfaced later but it seems fitting for now. Click "Continue". See Figure 2-5.

Figure 2-5 - Request Instance Wizard: Create Key Pair

Figure 2-5 - Request Instance Wizard: Create Key Pair

Here again, I don't know what the purpose of the name is / where it gets surfaced later / etc. I just followed the recommendation and set the name for my key pair to "TeamCityKey". Follow the rest of the instructions (you will download a .pem file for later use). Click "Continue" when it becomes available. See Figure 2-6.

Figure 2-6 - Request Instance Wizard: Configure Firewall

Figure 2-6 - Request Instance Wizard: Configure Firewall

By default, I believe SSH is added as a rule. If it is not, select it from the drop down and click "Add Rule". Also, select HTTP from the drop down and click "Add Rule". This restricts connections to those two types so our other services won't have a problem connecting. Use whatever Group Name and Description you want, or leave the defaults like me. Click "Continue". See Figure 2-7.

Figure 2-7 - Request Instance Wizard: Review

Figure 2-7 - Request Instance Wizard: Review

This is the final review before spinning up the new instance. If everything looks good, click "Launch". You should now see Figure 2-8.

Figure 2-8 - Launch Instance Wizard

Figure 2-8 - Launch Instance Wizard

You can either read about all the other AWS features, or just click "Close" like me. You should now see a table row with your instance info and a status of "running". See Figure 2-9.

Figure 2-9 - Instance running

Figure 2-9 - Instance running

Once the status switches from "pending" to "running", right click anywhere on the row, you will see a popup (Figure 2-10), click "Connect" and you will see Figure 2-11.

Figure 2-10 - Running instance option menu

Figure 2-10 - Running instance option menu

Figure 2-11 - Connect Help - Secure Shell (SSH)

Figure 2-11 - Connect Help - Secure Shell (SSH)

This part screwed me up. IMO these instructions are painful. It's stuff like this that bother me. In hindsight, now that I have done this I think "that was a stupid mistake" and probably have the same unhelpful mentality as people around me who just said "oh that's easy" when I asked for help. I fortunately do have at least one friend who took the time to talk me through it despite my bitching and moaning.

So here are the easy instructions - copy that line of code in the example, paste it into your SSH client (PuTTY, Terminal, etc.) and hit enter. If this doesn't work, read through those 4 instructions again, specifically step 3 regarding setting the file permissions. You might just have to run chmod 400 on it first. Another possible error (the one I encountered) was this message:

Please login as the ec2-user user rather than the root user

To remedy this, just change the "root@" part of your command line to "ec2-user@" like this:

ssh -i {YourKeyName}.pem ec2-user@ec2-xxx-xx-xx-xxx.compute-1.amazonaws.com

If this goes well, you should see a little EC2 ascii art, and a blank commmand line. You will likely find yourself in /home/ec2-user/.

FINALLY we can move onto the next step...

Downloading and installing TeamCity on the instance

Now that we have the EC2 instance up and running, we can move back to my previous post which elaborates on downloading and installation:
Intro to Continuous Integration with TeamCity: Downloading and installing TeamCity.

Please read make sure you understand the concepts described there before continuing.

Saving the instance for later use

One thing about Amazon EC2 is that whenever you stop an instance, you lose everything. This includes any downloads, installations, configurations, etc. In order to avoid losing all the effort you put into setting up this server you'll need to create an image.

To do this, right click on your instance name, and in the subsequent popup box click "Create Image (EBS AMI)". You should see Figure 3-1.

Figure 3-1 - Create Image

Figure 3-1 - Create Image

Type in an Image Name and Description and click "Create This Image". You should now see Figure 3-2.

Figure 3-2 - Create Image

Figure 3-2 - Create Image

Click "Close". Now if you click "AMIs" in the Navigation panel, you should see your new image processing. See Figure 3-3.

Figure 3-3 - Saved image

Figure 3-3 - Saved image

At this point the next step will be to set up one more EC2 instance for the TeamCity Build Agent to run on. To briefly elaborate, we will save an image of the larger instance, and instruct the micro instance to spin it up when a repo change is detected. I will absolutely document the process of configuring TeamCity to do just that in another post.

In closing

Hopefully this has provided you with some helpful info. If you've got any questions please drop them in the comments below. They're more likely to get answered there either by me or someone else as this is a fairly highly trafficked blog.

Thanks for reading!

Helpful Articles

http://www.dennisplucinik.com/blog/2011/03/25/intro-to-continuous-integration-with-teamcity

http://www.jadurham.com/codevault/amazon-cloud-aws/17-ec2-a-teamcity-youtrack-a-ssl.html
http://confluence.jetbrains.net/display/TCD6/Installing+and+Configu...uringtheTeamCityServer-installingWithTomcat
http://www.jetbrains.com/teamcity/features/amazon_ec2.html

Related Books

  1. Pingback: Intro to Continuous Integration with TeamCity | Dennis Plucinik's Web Design Blog

  2. Very useful article, thanks!

  3. Igor says:

    Hi!
    I’ve just start using TeamCity v7.2 and got a problem with setting up a cloud client.
    TeamCity agent can not recognize my Amazon instance as Amazon EC2 instance.
    Here is log:

    [2012-04-04 22:30:12,698] INFO – t.AmazonInstanceMetadataReader – Amazon is not available. Amazon EC2 integration is not active: Failed to connect to http://169.254.169.254/2009-04-04. Read timed outRead timed out
    [2012-04-04 22:30:12,699] INFO – .amazon.agent.AmazonProperties – Fetched AmazonEC2 instance metadata:
    [2012-04-04 22:30:12,702] INFO – zon.agent.AmazonMetadataChecks – Amazon EC instance metadata contains no keys
    [2012-04-04 22:30:12,702] WARN – .amazon.agent.AmazonProperties – Fetched Amazon EC2 instance metadata does not contain required values. Probably this agent was not started inside Amazon EC2. Is proxy server used?

  4. Was looking for someone with TC in the cloud, and here you are. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>