Monday 17 October 2022

CICD pipeline for Azure Blob storage with CDN - Part 6 Set up Continues Deployment of our Hero Images

This is more of a continuation of the previous post in which we configured our initial release pipeline and configured our Continuous Deployment trigger. In this post we are going to simply: 

  1. unzip our hero images, 
  2. then copy them over to our Blob storage 

Lets start by adding our delete content form our blob storage task.


Once you've opened the stage view start by renaming your stage to something more readable "Unzip and upload hero images"


once, that's done, click the "+" to add a task to the stage, search for extract files and add the "Extract files" task


Now we are going to have to configure our extract tasks job.


There's only two things you have to do and a third nice to have,
  1. set the display name to something more meaningful.
  2. set destination path: "$(System.DefaultWorkingDirectory)/_pav.content.cdn/unzip"
  3. set Overwrite existing files to true
  4. finally click the Save button
Next let's add another task that will let us copy our hero images to our blob store, click the add task button and search for "Azure file copy"


Add the azure file copy task, here we are going to finally copy our hero images to our azure file storage.


Now set all of your File copy properties. 


save your pipeline and run it, and more likely than not your CD pipeline will fails, with the following descriptive error.



Upload to container: 'container-public-pav-master' in storage account: 'stpavmaster' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme

my favorite parts is "AzCopy.exe exited with non-zero exit code while uploading files to blob storage", luckily for you after struggling with this for days, I learned that it's a permission issue.

Click on the gear at the bottom left and select service connections,


Click on the service connection that you are using in your pipeline.



Next click on the "Manage service Principle" link button. notice that the arrow is pointing to the wrong link button.



Take note of the display name, you're going to have to grant permissions in your azure environment to upload to your blob storage.

Next you'll have to open Access control in your azure portal for your subscription, 



This will open a drop down list, form it choose "Add role assignment" which will now let you add the Blob storage contributor role to your application service connection.


with that selected, hit the next button




Here you'll have to select the member and you'll have to manually paste in the name from a few steps above, select the member and assign the "Storage Blob Data Contributor role" this will let your dev ops site push files to your blob storage.

Now with your permissions set correctly you can create your release and you should be able to push your hero images to your Blob storage.

The blob storage URL for your images should be something along the lines of

https://stpavmaster.blob.core.windows.net/container-public-pav-master/hassan-pasha-AwssoaXCosQ-unsplash.jpg

and you should be able to access that exact same file using your cdn end point

https://cdn-endpoint-pav-master-global.azureedge.net/container-public-pav-master/hassan-pasha-AwssoaXCosQ-unsplash.jpg

and that's it, for the most part, there's two steps I'm leaving out, because I'm just too exhausted.

one you should delete all of the files in your blob storage before pushing them, to ensure that you do not host useless data.

and two you need to purge your cdn endpoint, so that your users aren't being hosted stale data.