.NET Zone is brought to you in partnership with:

Hey there! My name is Adam, and I'm a Technical Evangelist at Microsoft where I spend time focusing on Windows, Windows Phone, and Windows Azure. Adam is a DZone MVB and is not an employee of DZone and has posted 30 posts at DZone. You can read more from them at their website. View Full User Profile

Azure CLI Day 8 – site create with GitHub

09.21.2013
| 1702 views |
  • submit to reddit

Bash azure

In my last post I showed you how to create a Windows Azure web site that is integrated with Git from the command line. The benefit of this approach its that you can modify your web site locally, and once you’re happy with it you can push it to Azure using Git. In this post I’ll show you how to use the popular site GitHub to do the same thing.

Once again, just a reminder that I’m using the command line tools on a MacBook Air with OSX (Mountain Lion) installed, and I’m using Google Chrome as my default browser. However, the experience should be identical on Windows and Linux as well.

To follow along with this post you’ll need the following:

Since I’m currently working on a Mac, I thought I’d also use the GitHub for Mac client (http://mac.github.com). If you’re on Windows you can use the GitHub for Windows client (http://windows.github.com). Alternatively you can use the Git CLI as I did in my last post.

Open an instance of your command line (Terminal, Bash, Command Prompt, etc.) and type the following:

azure site create -h

Screen Shot 2013 09 07 at 3 47 53 PM

This should look very familiar as we’ve seen this command in my previous two posts. This time we’re going to use a couple of different options when creating our web site.

  1. –github. This will configure the site to use GitHub for deployments.
  2. –githubusername <username>. Your GitHub username.
  3. –githubpassword <password>. Your GitHub password.
  4. –githubrepository <repository>. The full name of your GitHub repository. The full name of your repository is [username]/[repository name]. For example, my GitHub username is agrocholski and the repository I’m using is called antares101, so the repository’s full name is agrocholski/antares101.

Next type the following, making the appropriate substitutions:

azure site create –location “[YOUR LOCATION]” –github –githubusername “[YOUR GITHUB USER NAME]” –githubpassword “[YOUR GITHUB PASSWORD]” –githubreposrity “[FULL PATH TO YOUR GITHUB REPOSITORY]” “[YOUR WEB SITE NAME]“

In my case I entered:

azure site create –location “West US” –github –githubusername “agrocholski” –githubpassword=”[MY GITHUB PASSWORD]” –githubrepository “agrocholski/antares101 “antares101″

(No “[MY GITHUB PASSWORD]” is not my actual GitHub password.)

Screen Shot 2013 09 09 at 9 15 42 PM

I won’t bore you with screenshots since you’ve seen them before in previous posts, but if you browse to the portal you can see the newly created site, and if you browse to the site itself you can see the default page that an Azure web site gets out of the box.

The next thing to do is to open the GitHub client for your system, in my case a Mac, and clone your empty repository to your local machine.

Screen Shot 2013 09 09 at 9 31 19 PM

If you navigate to the directory on the file system where the repository was cloned, you will see there is nothing in it. Now, open your favorite text/web editor and create a basic html page. Here’s what mine looks like.

Screen Shot 2013 09 09 at 9 38 21 PM

Save this as index.html in the directory where you cloned your web site’s Git repository.

Go back to your repository in the GitHub client and you should see the file you just created. Enter a commit comment and press the commit button.

Screen Shot 2013 09 09 at 9 39 42 PM

At this point your file has been committed to your local version of the repository. To push this to Windows Azure, you simply need to publish your branch to the repository on GitHub by pressing the Publish Branchbutton in the upper right-hand corner.

Screen Shot 2013 09 09 at 9 42 48 PM

If the publishing action is successful you should sees a No unsynced commits message. You can also go to your repository on GitHub and you should see the file.

Screen Shot 2013 09 09 at 9 44 17 PM

Go back to your web site’s dashboard in the Windows Azure management portal and click DEPLOYMENTS

Screen Shot 2013 09 09 at 9 46 08 PM

Check that out! Your changes we’re deployed as soon as you published your changes to GitHub! You can verify this by navigating to your web site. You should now see the following page:

Screen Shot 2013 09 09 at 9 49 00 PM

In my next post I’ll show you how you can get a list of all the Windows Azure web sites you have running.

Did you know you can try Windows Azure for free for 30 days? Just go to http://aka.ms/thecloud and sign up.

Published at DZone with permission of Adam Grocholski, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)