Monday, May 6, 2013

How to Automate App Deployment in TeamCity (Part 2)

Please notice that this is a multi-part, step-by-step guide, on how to automate application deployment in TeamCity CI Server. You can find the Part 1 here.

Part 2: Configuring the Web Application in IIS7

To make the point and test what is the current outcome, we need to setup a web site in our IIS server. I’m using IIS7 for this scenario. 

Let’s run through a basic setup so we can actually test.

1. Login into your server machine.
2. Run the IIS Manager.
3. Right click on Sites, and select Add New Website

TC_webdeploy_22

4. Fill in the new website details as you need. In my case I’m naming the site “web.contoso.com”, letting IIS to create the corresponding application pool with the same name. Then enter the correct physical path, which is where the our deploy step is copying the files. I’m going to enter the same web site name as my domain name and leave it with the default IP Address and port.

TC_webdeploy_23

5. Click ok. The new website should be added.
6. Click on the Content View on the center view to make sure the website directory is pointing to the right location and app files are there.

TC_webdeploy_25

7. Now, since I don’t actually own that domain name, what I would do is configure a local domain setup. The site won’t be available publicly, but it will be available locally, so we can test.
8. To make the local domain work, you need to add a hosts record on the server machine. Open the hosts file, which is located at C:\Windows\System32\drivers\etc. Add the “web.contoso.com” record pointing to the localhost IP address:
127.0.0.1 web.contoso.com

TC_webdeploy_24

9. Save the file. If Windows doesn’t allow you to save the file, you need to create a copy somewhere else, do the changes and then replace the original file with the modified one.
10. Now, on the IIS Manager, right click on the website you created, and select Manage Web Site/Browse to open the browser and browse to our web app.

TC_webdeploy_26

11. You will get a 403 HTTP Forbidden error. Basically, there’s no app to serve the web request, and the server won’t allow contents to be listed.

TC_webdeploy_27

If you want to actually test your web app files on your server real quick to make sure the IIS web site setup is correct, you can actually do a simple file system publish from Visual Studio to package and publish your app files.

TC_webdeploy_32

TC_webdeploy_28

TC_webdeploy_29

TC_webdeploy_30

TC_webdeploy_31

TC_webdeploy_39

Then just delete the files on the server’s web site folder and copy the ones you published in your local machine.

TC_webdeploy_33

Ok, so now we know that our basic deploy step is just a basic file copying step. This setup might be useful for other kind of apps, where just copying the compiled files might be enough. However, for our web app, we need to actually do a proper web deploy.

Next Article: Part 3 – Completing the Web Deploy Configuration

No comments:

Post a Comment