Showing posts with label git. Show all posts
Showing posts with label git. Show all posts
Thursday, June 15, 2017

Creating a Website in Microsoft Azure with GitHub deployment

Microsoft Azure is a scalable, cloud-based web hosting solution.


Setting up a new Web App


  1. Create a Subscription
    • This is the billing account to use. You can use an existing one or create a new one.
    • To create a new Subscription account, in the Azure portal left sidebar, click on Subscriptions > Add
    • Select the payment account to use
  2. Create a new Web App and App Service Plan
    • The App Service Plan is the container for Web Apps. You can have multiple Web Apps in a single App Service Plan. Plans vary in bandwidth and are priced in tiers.
    • In the left sidebar again, click on App Services > Add
    • Select Web App > Create
      • Fill in App name -- this will be used for your Azure URL on *.azurewebsites.net
      • Select Subscription that you created previously
      • Resource Group can be new, or you can use an existing one if there is one for that App Service
      • App Service Plan: Create new is default, but only use if there isn't one already; otherwise use one that's already there.
      • Click Create and Azure will begin deploying the new site. After 1-2 minutes, you should see an Alert that deployment is complete
      • Now if you go to App Services the new web app will be there. If you select it and click Overview you will see URL, FTP and other info.
  3. Select/Change Service Plan ***Azure will select Standard by default, so you need to manually change it if you want a free/cheaper plan
    • Go to App Services > Scale Up and view the current plan or select a different plan

Setting up a Staging Environment

You can create a separate Web App for staging in the same App Service Plan, or you can create a Deployment Slot in the existing production Web App. Personally I think it is cleaner to use Deployment Slots, to minimize the number of Web Apps. Originally Deployment Slots were meant to be a pre-production environment that you can swap out with the real production environment. For example, you could deploy code changes to the Deployment Slot, then once it's working "Swap" the Deployment Slot and it will immediately update the Production environment. However I think this a different type of workflow than what I usually do with Git and having staging and master branches that deploy to the environments. I don't plan on using the Swap functionality, but many others like using it.


  1. To create a deployment slot, select the App Service and click on Deployment slots > Add Slot
  2. Name it, i.e. "staging" -- this will create a new subdomain on the *.azurewebsites.net site by adding the slot name to the existing Azure domain
  3. Under Configuration Source, select to clone from the existing Web App
  4. Click OK to create the new deployment slot


Setting up GitHub Deployment

At the moment, it's not possible to use an external Git repository for Azure and have staging and master branches that automatically deploy to Azure. GitHub is the suggested method of source control for now. First, create the GitHub repository and the master and staging branches. Once created, go back into Azure to connect the Web App to the repository.

  1. Select the App Service (or App Service's Deployment Slot) > Deployment option
  2. Under Choose Source, select GitHub. You may be prompted to log into GitHub; if so, log in using devservices (Credentials in 1Pass under GitHub)
  3. Select Authorization, Organization, Project, and Branch.
  4. Click OK to create the Deployment option.
  5. Depending on how many files are in the repo, it make take a few minutes or longer to finish building the site. You can check the deployment status under Web App > Deployment options


Wednesday, May 10, 2017

Undoing a merge in Sourcetree/Git

Merging some changes into your master branch, then realizing you need an undo function, is stressful. Fortunately, whether or not you've pushed your merge, you can still reverse what you did. There's no actual "undo" in Git, but you can either reset the master branch, or reverse your changes.

If you haven't pushed to the origin master branch yet, you can reset the master branch to the previous commit before the merge. You'll want to reset using "Hard" mode so that your working copy of master will have the changes removed.

Sourcetree: 
Right-click the previous commit on the master branch, select "Reset current branch to this commit" and select "Hard" mode.

Git Command Line:
git reset --hard XXXXXXX (insert the Commit ID)

If your merge to master has been pushed, then you will need to do a reverse commit in the feature branch, which reverts everything in that commit, merge to master, then push master again. Later on, if you want to re-merge what was in the feature branch to master once again, you will have to reverse commit the reversion itself in the feature branch. This will reinstate the changes you had removed.