Category: Azure

Azure Blobs from C# and Visual Studio – C# Advent Calendar

This blog post is part of the The Second Annual C# Advent by Matthew Groves which is a C# advent calendar of blog posts by the community which uses C# to cover a topic of your choosing – I chose to show how to use Azure Blob Storage from C# and created a simple console application to upload images from a folder on your local computer and push the images into Azure Blob Storage.

To see all of the other blog posts for the C# advent calendar take a look here

The sample code for this blog post can be found on github

The following will show you how to create and access blobs using C#

  • Log into your Azure account or create a free one
  • Create a new Resource Group and call it something like BlobStorageCSharp
  • Next Add a new Resource, and search for Storage and then select the following highlighted Storage account – blob, file, table, queue)

The code example will show how to create a container which will upload the images into a container in blob storage up into your Azure storage account.

The code makes use of Azure Blob Storage from C# to create a public blob storage container called xmasimages-container if it doesn’t exist already making use of the following:-

And then upload images found in a folder on your local machine and stores the images into the public blob storage container.

You can read more on blob storage container’s and using C# to work with Azure storage

Once the images have been uploaded you could use Azure Storage explorer to view them.

Once you have downloaded and ran the code from my repo above, open up storage explorer and follow the steps below:-

  • Sign into your Azure Subscription
  • Expand Storage Account
  • Expand Blob Containers
  • Locate your container (xmasimages-container)
  • Highlight an image on the right hand side
  • Click Download or double-click and open it using any image viewer.
  • Viola – you’ve uploaded images and now you can view them

It’s a simple demo and there is a lot more you could continue with, so go grab the code, modify and extend it by doing some of the following: –

  • Change the code to make use of Azure Key Vault to store the connection string to your blob storage container
  • Extend the code to list the files within your container

Thanks to Matt Groves for doing the C# advent calendar, mind and check all the other great content here.

Merry Christmas and enjoy!
Gregor

 


Tags:


Azure Devops – OSS Scanning using WhiteSource

Its about time your AzureDevops builds were scanning for OSS vulnerabilities, well your in luck as you can use this Marketplace Extension which is FREE: – https://marketplace.visualstudio.com/azuredevops/

One you add the extension to your Organization you can add it into your build like so:-

This will scan your oss code and give you a detailed report on any vulnerabilities within your Azure Devops repository – #winning.

I have added it to a build I have and here is a sample of the report which you’ll see produced once you’ve added it into the build step.

The report looks like this: –

And below this you’ll see the following: –

An you’ll also see this: –

And this:-

Now you’ll get a report on open source vulnerabilities in your builds 🙂



Azure Devops

In this series of blog posts I will cover Azure Devops, I’ll cover the following

And many more, check back regularly for more on the above.

Please ping me if you have any questions or want something covered which I haven’t mentioned thus far.



Azure DevOps – How to do a fully automated release (Part 3)

Ok so Part 1 covered how to do a manual build of a .NET Core Web App and now I’ll show how to do a manual deployment of the project.

Part 2 covered creating a manual release from the build in Part 1

In Part 3 I’ll cover the magic sauce that make it possible to set up continuous deployment so that when you commit your code its automagically built and deployed.


Automated Builds

  • Ok so start by going to Pipelines and then select Builds
  • Click on Edit to Edit the build we created in Part 1
  • Select Triggers and then click on Enable Continuous Integration and then click Save And Queue like so

 

Once you’ve saved check in a commit and the code will trigger the automated build.


Automated Deployments

  • Ok so start by going to Pipelines and then select Releases
  • Edit the release you had previously created in Part 2
  • Click the lightning icon on the Artifacts part of the release and then click to enable Continuous deployment trigger like so, click Save.

So now if you commit code, you’ll have an automated build and release pipeline using continuous integration and continuous deployment (CI / CD) – way to go!



Azure DevOps – How to do a fully automated release (Part 2)

Ok so Part 1 covered how to do a manual build of a .NET Core Web App and now I’ll show how to do a manual deployment of the project.

Part 2 will cover creating a manual release from the build in Part 1 (I’m assuming your manual build is working)

Before starting this please manually create a Resource Group, App Service Plan and an App Service within the Azure Portal, for this demo I created the following:

Resource Group called BlogPostDemoRG
AppService Plan called BlogPostDemoAppPlan
App Service called BLogPostDemo


  • So back in Azure Devops (devops.azure.com/<your org name here>)
  • Under Pipelines (on the left) click on Releases
  • Choose New Pipeline
  • Choose Azure App Service deployment
  • Click on Artifacts + Add
  • Select the Source and then Click Add
  • At this point you should see something like so


Setup the Stage

  • Enter a Stage Name (leave it as Stage 1 for now), then close the right hand screen
  • Click where it says 1 job, 1 task (it should be red currently as some settings need to be supplied)
  • Add a New Task
  • Choose the Azure App Service Deploy Task
  • Fill in the settings which are red
  • Choose your Azure Subscription
  • Click Authorize and sign in to your Azure Subscription
  • Select your already created App Service (I called my blogpostappdemo)
  • Where it says Package or folder click the ellipses and browse to the drop folder like so

  • Click Ok
  • Click Save to save your changes

Deploy Time

  • At this point you should be able to deploy the code
  • From the Top Click Release, Create a Release
  • Enter Stage 1 as the stages for a trigger change (or whatever you called it in step 4)
  • Select the Artifact from the drop down (artifact is basically which version of the code do you wish to deploy)
  • Click Create
  • In Green header you’ll see that a Release has been created, click on it
  • Underneath the Stage 1 in middle of the screen it’ll say not deployed, select Deploy once you hove over that part
  • Click Deploy, then click where it says In Progress
  • Once the build succeeds go back to the Azure Portal and locate your App Service and click on the url to launch the site

Congrats you should now have your first Azure Devops manual build and now your first manual release,  but lets not stop there as this is only us getting warmed up, how about in Part 3 we automate both the build and the release.



Azure DevOps – How to do a fully automated release (Part 1)

I managed to get an automated build of some new code tonight and I ran into some issues which I have now resolved, so here are the steps to create a fully automated build and release of a brand new .net core web app using Visual Studio and Azure DevOps.

Part 1 will cover creating a manual build

  • Create a DevOps Organization
  • Create a brand new .Net Core Web App in Visual Studio( File, New Project, .Net Core, Asp.Net Core Application)
  • Call it anything you like I called my BlogPostDemo
  • Choose Web Application (Model-View-Controller)
  • Click ok
  • Make sure you have the following VS Extension installed – GitHub Extension for Visual Studio
  • Then do File -> Add to Source Control
  • From Team Explorer select Sync
  • Then where it says Push To Azure DevOps -> Click Publish to Git Repo
  • Make sure your Azure DevOps Organisation is selected and give the Repository a name e.g. (BlogPostDemo)
  • Click Publish
  • You should now be able to see this if you click on Repos within Azure Devops

 


Ok so now we have the code in place, let’s do a build and make sure the code builds within the repo in Azure DevOps. To create a release I did the following:-

  • Click on Pipelines and then Builds
  • Click new Pipeline
  • Be careful here, I selected to use the visual designer which you can see here:-


  • Then I left the default choices (Azure Repos Git, BlogPostDemo, BlogPostDemo, master branch), click Continue
  • Then I add a ASP.NET Core Template (this gives you Restore, Build, Test, Publish, Publish Artifact steps for you)
  • Click Save and Queue

It’s important to note that at this stage the build is going to be a manual build, we will come back to it and make it an automated build (and release) later on.

Part 2 will cover doing a manual Release and in Part 3 we will make the whole thing automated.



Azure Governance and Security

Recently came across some very useful links for moving to Azure and thought they may be of some use to others as well, the content below covers things like best practice for subscriptions, resource group usage naming conventions, security and more…


 



Azure Pipelines

Azure DevOps allows you to Continuously build, test, and deploy to any platform and cloud. With Azure DevOps gives you 1,800 free minutes for CI / CD (30 hours per month)

If your project is open source (public Git repo on any Git Service), you get 10 free parallel pipelines per month.


To get started with Azure Pipelines I used https://azuredevopsdemogenerator.azurewebsites.net/ to create a project within Azure DevOps for this walk-through I selected the PartsUnlimited Template. This project is a .Net core application and uses the scrum Azure Board type, full source code can be found on GitHub here – https://github.com/Microsoft/PartsUnlimited

From there I cloned the repo locally and made sure I can run it locally – always a good first step in my opinion.

Now I wish to create a build pipeline so here are the steps I carried out to first of all create a new build pipeline:-

  • Click on Builds under Pipelines on the left hand menu
  • Click New, then select new Build Pipeline
  • I then chose use the visual designer (easier than using yaml in my opinion) as below:-


  • Select Azure Repos Git
  • Select Azure Repos Git and Master branch
  • Choose Azure Web App for ASP.NET and then select Apply
  • Within Tasks I normally delete the Azure App Service Deploy Task (right-click on it remove selected task)
  • You should have something that resembles the screen shot below: –


  • Once your happy with the settings select Save and Queue (If its grayed out you’ve missed a setting – normally in red)
  • Build succeeded and you just created your first Azure DevOps Build – congrats!

After that its time to experiment with other types of projects and build’s, one way to do this is to look at samples and play with them and look at what’s possible. A great resource for doing this is again using the https://azuredevopsdemogenerator.azurewebsites.net/ generator, this time lets use the SmartHotel360 app,  like so: –

  • Click Create project and let that install
  • Once Installed select the Pipelines icon and then choose Builds

  • Now choose Edit and you can see the way this build has been constructed

  • From here you can view the actions and see what each of them is doing
  • Once you have had a look at each step, Click Queue to queue a new build

Read more on Azure Pipelines here: – https://azure.microsoft.com/en-us/services/devops/pipelines/



Document your Azure Architecture


Like me you may need to document your Azure Architecture and over the last few days I have came across some decent materials for doing just that and I thought I should share with you me findings, so here goes: –

 

 


Armed with the above you can go off and create your Azure Architecture documents with ease – enjoy!



What is Azure DevOps?

In this series of blog posts I cover Azure DevOps, formerly known as Visual Studio Team Services (VSTS).

So what is it and more importantly what can I do with it?

Azure DevOps has been split up into 5 main areas which are: –


 

 

 

 

 

 

 


If you want to get a head start with Azure DevOps and get generate a full Azure DevOps instance you can find out how to do this in 5 easy steps in my blog post on how to get started here:- https://gregorsuttie.com/2018/10/31/how-to-get-started-with-azure-devops/

So lets take each one in turn:-

Azure Pipelines – https://gregorsuttie.com/2018/11/11/azure-pipelines/
Azure Boards – Coming soon…
Azure Repos – Coming soon…
Azure Artifacts – Coming Soon…
Azure Test Plans – Coming Soon…


You can read all the docs on Azure DevOps here: – https://docs.microsoft.com/en-us/azure/devops/?view=vsts and follow their twitter account here: – https://twitter.com/AzureDevOps