On a pipeline that I was creating I wanted to push multiple docker images on an Azure container registry based on a list. In order to do that I used the docker@2 task on a loop providing the images that I had to push as a parameter. Code is attached below.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This task will run steps based on the images you provide on the parameters list. An important note is that you need to have the image named accordingly in order to get a successful result. For example if you need to push on geralexgr.azurecr.io you will need to have your images named as below.
In this article I will demonstrate how you can write a simple .NET console application to write data inside a blob container on an Azure storage account.
Storage accounts support the below four data structures.
For the cases of an application, I had to write every x seconds data on a file in order to get the coordinates of an app. For this purpose I selected a storage account container on which I will store the Latitude and Longitude in a .json format.
Inside my storage account I created a container which I will use named application.
Inside application container I created a file named locations.json. This will be the file that will get updated from the mobile app.
My console app consists of two .cs files. One is the location class which will be my model for the serialization.
public class Location
{
public Double Latitude { get; set; }
public Double Longitude { get; set; }
}
And the main code which consists of two functions. The RetrieveBlobContents function can read the stream content of a requested file from the blob. As I have specific names for my scenario, I hard coded them on the application. My containerName is application and the file which I want to read is called locations.json
The WriteContentOnBlob function will serialize a random Location object and will update the file every 5 seconds. The result is accomplished by writing a file locally and pushing this local file on the blob storage. The content of the file will be first extracted on the current directory/data folder.
Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Azure Cosmos DB is a database solution provided from Microsoft Azure that provides 99.999% SLA for enterprise level solutions.
In this article I will demonstrate how you can write a simple .NET application to insert and fetch data from a Cosmos DB.
First things first, you should have already a cosmos DB created. Then you will need to navigate in the keys section on Azure and retrieve your connection keys.
Using data explorer on Azure you can easily create new Databases and Containers. Containers are like Tables, but they also include other entities like Stored Procedures Triggers and User Defined Functions.
In my test I created a new Database named Data on which I created the table Locations. In this location table I wanted to append some location entries, that they will contain Longitude and Latitude.
That is why I created a class inside my Console App named Location
public class Location
{
public Double Longtitude { get; set; }
public Double Latitude { get; set; }
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
}
My Program.cs is shown below:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On the GetStartedDemoAsync the connection with the Cosmos DB is initialized using the connection strings and the database and container names. Its important to use the connectionMode Gateway because you will maybe face connection issues.
The function AddItemsToContainerAsync is used to insert values on the database. A common issue happens with the PartitionKey that is mandatory to be used on the CreateItemAsync function. In my case I use a random Guid value for it. You should define a JsonProperty on your model with the PartitionKey value and provide a value along with your data. On my Location loc constructor I append a new Guid as the Id value.
The QueryItemsAsync is used to retrieve the database values in a structure as your model.
The partition key is used to distribute your data into logical partition for scalability reasons. You should consider choosing an better value that is not random in order to take advantage of the Cosmos DB indexing engine.
Inside Task Main I used a while loop in order to insert some data on the cosmos DB database. As I do not have an external API source for the locations, the same location is added over and over again.
In this article I will demonstrate how one can create different environments for development needs through terraform modules. Modules provide great extensibility and code reuse. In this example I will use an appservice resource on Azure cloud.
The result of the deployment will be two different resource groups with two app services. The code of the demonstration is located at the bottom of the page.
You should first init your module. Navigate to the module folder and perform init
cd modules; terraform init
cd .. ; terraform init
Then validate your terraform code
terraform validate
The last step is to apply your configuration
terraform apply
You may encounter an error during the creation of the resources because of the app service name. It should be globally unique.
Change your name and perform a terraform apply again. Terraform will read your .tfstate file and will only implement the differences on infrastructure.
After the successful run you will see the green result output from terraform cli.
On Azure there should be two resource groups created. One for prod environment and one for test.
Inside each resource group there should be a different app service the one that it is created through the module according with the settings provided.