© Les Jackson 2020
L. JacksonThe Complete ASP.NET Core 3 API Tutorialhttps://doi.org/10.1007/978-1-4842-6255-9_13

13. Deploying to Azure

Les Jackson1 
(1)
Melbourne, VIC, Australia
 

Chapter Summary

In this chapter we deploy our API onto Azure for use in the real world. On the way, we create the Azure resources we need and revisit the discussion on runtime environments and configuration.

When Done, You Will

  • Know a bit more about Azure.

  • Have created the Azure resources we need to deploy our API.

  • Update our CI/CD pipeline to deploy our release to Azure.

  • Provide the necessary configuration to get the API working in a Production Environment.

We have a lot to cover – so let’s get going!

Creating Azure Resources

Azure is a huge subject area and could fill many books, many times over, so I’ll be focusing only on the aspects we need to get our API and database up and running in a “production-like” environment – which should be more than enough.

In simple terms, everything in Azure is a “resource,” for example, a database server, virtual machine, web app, etc. So, we need to create a few resources to house our app. There are different ways to create resources in Azure:
  1. 1.

    Create resources manually via the Azure Portal.

     
  2. 2.

    Create resources automatically via Azure Resource Manager Templates.

     
  3. 3.

    Create resources automatically using third-party tools, for example, Terraform.

     
In this chapter, we’ll be manually creating the resources we need as
  • It’s simpler (in our case anyway, see next point).

  • We only have a small number of resources.

  • I think it’s the right approach to learning (our focus is still our API).

Create Our API App

The first resource we are going to create is an API App; this unsurprisingly is where our API code will run. To do so, log-in to Azure (or if you don’t have an account, you’ll need to create one), and click “Create a resource”:
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig1_HTML.jpg
Figure 13-1

Create an Azure Resource

../images/501438_1_En_13_Chapter/501438_1_En_13_Figa_HTML.jpg Again, I’ll mention the point that the following screenshots were correct at the time of writing, but given the fast pace of change in Azure, they may be subject to change.

Fundamentally though, resource creation in Azure is not that difficult, so small UI changes should not stump someone as smart as yourself!

In the “search box” that appears in the new resource page, start to type “API App”; you will be presented with the API App resource type.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig2_HTML.jpg
Figure 13-2

Search for API App

Select “API App,” then click “Create.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig3_HTML.jpg
Figure 13-3

Create the API App

On the Next “page,” enter
  1. 1.

    A name for your API App.1

     
  2. 2.

    Select your subscription (I just have a “pay as you go”).

     
  3. 3.
    A name for your new “Resource Group” – these are just groupings of “resources”; if you don’t have an existing resource group, you’ll need to create one.
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig4_HTML.jpg
    Figure 13-4

    Configure your API App – make sure you configure a free plan!

     

WAIT! Before you click Create, click the App Service plan/location.

Les’ Personal Anecdote

../images/501438_1_En_13_Chapter/501438_1_En_13_Figb_HTML.jpgThe API App resource describes what you are getting; the App Service Plan and Location tells you how that API App will be delivered to you.

For example, do you want your API App

  • Hosted in the United States, Western Europe, Asia, etc.

  • On shared or dedicated hardware

  • Running on certain processor speed, etc.

    By default, if you’ve not used Azure before, you’ll be placed on a Standard plan which can incur costs! (This is a personal anecdote because I did that and was shocked when my test API started costing me money!)

    So be careful of the Service Plan you set up; I detail the free plan next.

After clicking the Service Plan, click “Create new.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig5_HTML.jpg
Figure 13-5

Creating an App Service Plan

On the “New App Service Plan” widget, enter an App Service Plan name, and pick your location, then click the Pricing Tier.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig6_HTML.jpg
Figure 13-6

The Pricing Tier

After, click the Pricing Tier.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig7_HTML.jpg
Figure 13-7

Select the Free option

  1. 1.

    Select the Dev/Test tab.

     
  2. 2.

    Select the “F1” Option (Shared infrastructure/60 minutes compute).

     
  3. 3.

    Click Apply.

     

We have selected the cheapest tier with “Free Compute Minutes,” although please be aware that I cannot be held responsible for any charges on your Azure Account! (After I create and test a resource if I don’t need it – I “stop it” or delete it).

Then click OK.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig8_HTML.jpg
Figure 13-8

You're ready to go

Then click “Create” (ensure your new App Service Plan is selected).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig9_HTML.jpg
Figure 13-9

Free plan has been applied to the API APP

After clicking Create, Azure will go off and create the resource ready for use.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig10_HTML.jpg
Figure 13-10

Deployment will take a few minutes…

You will get notified when the resource is successfully created; if not, click the little “Alarm Bell” icon near the top right-hand side of the Azure portal.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig11_HTML.jpg
Figure 13-11

Notification of Resource Creation

Here you can see the resource was successfully created; now click “Go to resource.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig12_HTML.jpg
Figure 13-12

API App Overview including URI

This just gives us an overview of the resource we created and gives us the ability to stop or even delete it. You can even click the location URL, and it will take you to where the API App resides.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig13_HTML.jpg
Figure 13-13

Default public landing page

As we have not deployed anything, you’ll get a similar landing page as shown in Figure 13-13 (of course for reasons already mentioned, it may look a bit different, but that is of no consequence to us at this point).

Celebration Checkpoint

../images/501438_1_En_13_Chapter/501438_1_En_13_Figc_HTML.jpgYou’ve just created your first Azure resource, one of the primary components of our production solution architecture!

Create Our PostgreSQL Server

Now, there are a number of different ways that you can create a PostgreSQL database on Azure, but I’m going to take a slightly unorthodox route and spin up a PostgreSQL Server in a Container Instance in Azure (think Docker containers).

I’ve taken this approach primarily because the setup is so simple and the cost implications are low. To illustrate my point, compare the estimated costs for
  • Azure Database for PostgreSQL Servers

  • Container Instance running a PostgreSQL Image

Azure Database for PostgreSQL Servers

I’ve configured the most basic example of this that I could.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig14_HTML.jpg
Figure 13-14

Cost estimate for Postgres Server

Container Instance Pricing

../images/501438_1_En_13_Chapter/501438_1_En_13_Fig15_HTML.jpg
Figure 13-15

Container instance pricing

Now, I don’t need to tell you that “you get what you pay for” in this life, so clearly the Azure Database for PostgreSQL option is a purpose-built resource that’s designed to work as a database, whereas the container option I’m taking is in no way optimized for Production performance!

Warning!

../images/501438_1_En_13_Chapter/501438_1_En_13_Figd_HTML.jpgIf you restart the PostgreSQL container instance that we create in the next section, it essentially resets, and you will lose your configuration and data relating to it – just something to bear in mind.

From a learning (and cost!) perspective, I still think this option is acceptable. If, however, you are moving to a “real” Production environment, then you’ll really need to look at something a little more fit for purpose.

So back in Azure, once again click “Create a Resource,” and this time search for “Container Instances.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig16_HTML.jpg
Figure 13-16

Search for Container Instances

Select “Container Instances” from the options drop-down, and you should be displayed the Container Instances detail screen; click “Create” to continue.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig17_HTML.jpg
Figure 13-17

Overview of Container Instances

You’ll get taken to the Basics tab on the creating wizard; fill out the details as relevant to you; however, the image name must be postgres.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig18_HTML.jpg
Figure 13-18

Configure your Container Instance

  1. 1.

    Your subscription.

     
  2. 2.

    Resource group (I’d make this the same as the one you placed the API app into).

     
  3. 3.

    Container name can be anything, but I’d name it something that identified it as a PostgreSQL server.

     
  4. 4.

    Region (I’d make this the same as the one you placed the API app into).

     
  5. 5.

    Image Source: Select Docker Hub (this is where we’ll get our postgres image).

     
  6. 6.

    Image Type: Select Public (the postgres image we use in the next step is publicly available on Docker Hub).

     
  7. 7.

    Image Name: As mentioned earlier, this needs to be the exact name of the image on Docker Hub, so in this case postgres.

     
  8. 8.

    OS Type: Select Linux.

     
  9. 9.

    Size: Leave these as the defaults.

     
When you’re happy click “Next: Networking >.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig19_HTML.jpg
Figure 13-19

Networking

And supply the following details in the Networking Tab.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig20_HTML.jpg
Figure 13-20

Networking configuration

  1. 1.

    Select “Public” for a public IP Address (note this can change if the container restarts).

     
  2. 2.

    Add a DNS name label as the IP Address can change if the container restarts.

     
  3. 3.

    Add the standard 5432 TCP port for PostgreSQL.

     
When you’re happy, click “Next: Advanced >.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig21_HTML.jpg
Figure 13-21

Onto Advanced Settings

And enter the following details on the Advanced tab.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig22_HTML.jpg
Figure 13-22

Setup Environment variables

  1. 1.

    Set the Restart Policy to “On Failure.”

     
  2. 2.

    Create an “environment variable” for the Postgres password for the default database; the Key you should use for this is

     
POSTGRES_PASSWORD
The choice of password (the value) is up to you. In my case, I used
pa55w0rd!
Warning!

../images/501438_1_En_13_Chapter/501438_1_En_13_Fige_HTML.jpgAs you can see our PostgreSQL password is in plain text; again this is not a production-suitable solution. We are using it for (cheap!) testing purposes only.

If you pop back to Chapter 7 where we set up an instance of PostgreSQL locally using Docker Desktop, there is a bit more of a discussion on these settings – so we don’t need to go over old ground here. Just a point of note, however, the environment variable for the PostgreSQL DB password (POSTGRES_PASSWORD) is exactly the same as the one we used when setting up our local Docker instance.

Click “Review and Create” (we can skip the “Tags” tab).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig23_HTML.jpg
Figure 13-23

Validation Passed

You should see “Validation Passed” at the top of the screen; when you’re happy, click Create, and in a similar way to the API App, Azure will go off and create your resource.

You’ll get notified when both your resources are set up: by clicking All resources, you can see everything we have created.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig24_HTML.jpg
Figure 13-24

Resources up and running

Connect and Create Our DB User

As before we want to create a dedicated user to connect in and use our database, the exercise is also a great opportunity to test that our PostgreSQL container instance is up and running.

First, we need to get the Fully Qualified Domain Name (FDQN) of the container instance, so in Azure find your container instance resource, and select it; this will display a number of details, most important of which is our FDQN.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig25_HTML.jpg
Figure 13-25

Location of the API

Make a note of the FDQN, and move over to DBeaver, and create a new connection to a PostgreSQL instance – this is exactly the same as when we connected into our local instance, the only differences being the host and possibly the password for the postgres user (depending on what you set in the container instance environment variables).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig26_HTML.jpg
Figure 13-26

Connect to the Azure instance

Remember to tick “Show all databases” on the PostgreSQL tab.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig27_HTML.jpg
Figure 13-27

Ensure Show all Databases is ticked

You can test the connection or press Finish to setup our connection to our Azure-based instance.

Again, we’ll just repeat the user creation steps in Chapter 7:
  • Open a New SQL Editor Window.

  • Enter and run the following SQL (you can change the password obviously!):

create user cmddbuser with encrypted password 'pa55w0rd!' createdb;

And again, check that the role was created and that it has create database rights.

Along with the FDQN, set aside the user ID and password for later.

Revisit Our Dev Environment

We’ve covered a lot of ground since Chapter 8, but it’s worth doing a bit of a review.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig28_HTML.jpg
Figure 13-28

Revisit configuration

  • We set our environment in launchSettings.json (in the ASPNETCORE_ENVIRONEMENT variable).

  • Our Connection Strings can sit in appsettings.json or the environment specific variants of that file, for example, appsettings.Development.json. This is where our Development connection string sits.

  • “Secret” information, such as Database log-in credentials, can be broken out into Secrets.json via The Secret Manager tool. Meaning, we don’t check in sensitive data to our code repository.

Also, remember that we chose to build our full connection string in our Startup class using
  • Non-sensitive Connection String stored in appSettings.Development.json).

  • Our User ID, stored in a User Secret called UserID.

  • Our Password, stored in a User Secret called Password.

Setting Up Config in Azure

When you deploy a .NET Core app as an Azure API App, it sits on top of a configuration layer that we access via the .NET Core Configuration API in exactly the same way as we have done to date with our local Development environment. In setting up our production environment, we will
  • Require some simple config settings in our API App.

  • Require no code changes in our app; there would be something very wrong if we needed to change our code to move into production – that should all be handled by configuration.

Configure Our Connection String

OK, so go back to your list of Azure resources, and select your API App Service. On the resulting screen, select Configuration in the Settings section as shown here.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig29_HTML.jpg
Figure 13-29

Application settings and connection strings in the API app

You’ll see there are two sections here for use to play with:
  1. 1.

    Application Settings

     
  2. 2.

    Connection Strings

     
We are going to add our Production Connection string to the (surprise, surprise) Connection Strings settings of our API App. Looking at the Development connection string I have in appsettings.Development.json
Host=localhost;Port=5432;Database=CmdAPI;Pooling=true;
Not that much needs to change, except the Host attribute. We simply substitute that for the PostgreSQL Container Instance FDQN that you should have set aside from the section earlier. So, I now have the following (yours will look different depending on your container instance name and location of course):
Host= pgserver.australiaeast.azurecontainer.io;
Port=5432;Database=CmdAPI;Pooling=true;
To add this string to our API App Connection String settings, click + New connection string. In the resulting form, enter
  1. 1.

    Connection String Name (this should be the same name as our development connection string – I cannot stress that enough!).

     
  2. 2.

    The connection string we generated earlier (note we’ll be configuring our User ID and Password separately below).

     
  3. 3.
    Set the type to Custom.
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig30_HTML.jpg
    Figure 13-30

    Add the connection string; be careful to name it correctly

    Warning!../images/501438_1_En_13_Chapter/501438_1_En_13_Figf_HTML.jpgYou do have the option of “PostgreSQL” for the connection string type – however, I’ve had significant issues trying to use this – so use it at your peril!

     
Click OK, and you’ll see the connection string has been added to our collection.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig31_HTML.jpg
Figure 13-31

Again, ensure it's named correctly

Configure Our DB User Credentials

We’re going to add our Production User ID and Password configuration items in a very similar way, except this time, we’ll add these items to the Application Settings section of our API App Configuration. To add our User ID, click + New application setting. In the resulting form, enter
  1. 1.

    Name: This should be the same as our User Secret name for User ID.

     
  2. 2.

    Value: This is the user account you set up on the PostgreSQL Container Instance earlier.

     
For example, if you’ve been following the tutorial step by step these should be
  • Name: UserID

  • Value: cmddbuser

So, add them as an Application Setting as follows.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig32_HTML.jpg
Figure 13-32

Create User ID Application Setting

Again, just be careful that the User ID attribute name is exactly the same as the local user secret name and what your app is expecting to ingest when it creates the connection string as shown next.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig33_HTML.jpg
Figure 13-33

Make sure you name it correctly

Click OK, and you’ll see the new UserID application setting.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig34_HTML.jpg
Figure 13-34

UserID added to Application Settings

Learning Opportunity

../images/501438_1_En_13_Chapter/501438_1_En_13_Figg_HTML.jpgAdd a second Application setting for our Password. This should follow the same process as UserID.

Warning!

../images/501438_1_En_13_Chapter/501438_1_En_13_Figh_HTML.jpgStoring passwords in Application Settings possibly isn’t the best location for them, one reason being that you can see what they are in plain text. Even though Azure is “secured,” that is, only authorized users will have access to it – plain text passwords are just generally not a great idea.

In a real production environment, you’d want to opt for something like Azure Key Vault or a third-party product such a Vault.2 I feel that detailing that here would just be taking us too far out the way of what we want to achieve today.

Configure Our Environment

Finally, we want to set our runtime environment to “Production”; we do this simply by adding another Application setting as follows:
  • Name: ASPNETCORE_ENVIRONMENT

  • Value: Production

See Figure 13-35.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig35_HTML.jpg
Figure 13-35

Specifying our environment

Click OK and you should now have added four production configuration settings:
  1. 1.

    Application settings: ASPNETCORE_ENVIRONMENT

     
  2. 2.

    Application settings: Password

     
  3. 3.

    Application settings: UserID

     
  4. 4.

    Connection string: PostgreSQLConnection

     
I’ve shown my setup as it appears in Azure in Figure 13-36.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig36_HTML.jpg
Figure 13-36

Newly created Application Settings

Again, I know I keep repeating myself, but you need to make sure the Names of these configuration items are the same as their Development counterparts, as that is what our application is expecting – please double-check these! The values of these items I have to leave up to you to get correct!

Warning!
../images/501438_1_En_13_Chapter/501438_1_En_13_Figi_HTML.jpgEvery time you make a configuration change, you need to save it - see Figure 13-37.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig37_HTML.jpg
Figure 13-37

Make sure you save!

Make sure you click Save to apply your changes (when starting out with this stuff, I didn’t and spent a lot time trying to understand what was wrong!).

Celebration Checkpoint

../images/501438_1_En_13_Chapter/501438_1_En_13_Figj_HTML.jpgYou have just set up all your Azure Resources and have configured them ready for our deployment!

Completing Our Pipeline

At last! We create the final piece of the puzzle in our CI/CD pipeline: Deploy.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig38_HTML.jpg
Figure 13-38

The pipeline

A quick recap on our CI/CD Pipeline so far
  • We created what Azure DevOps calls a Build Pipeline that does the following:
    • Builds our projects

    • Runs our unit tests

    • Packages our release

What we now need to do in Azure DevOps is create a Release Pipeline that takes our package and releases and deploys it to Azure. So basically, our full CI/CD Pipeline = Azure DevOps Build Pipeline + Azure DevOps Release Pipeline.

Creating Our Azure DevOps Release Pipeline

Back in Azure DevOps, click Pipelines ➤ Releases.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig39_HTML.jpg
Figure 13-39

Release Pipeline

The click New Pipeline.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig40_HTML.jpg
Figure 13-40

Create a new Release Pipeline

On the next screen, select and Apply the Azure App Service deployment template.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig41_HTML.jpg
Figure 13-41

Select Azure App Service deployment

In the “Stage” widget
  1. 1.

    Change the stage name to “Deploy API to Prod Azure” (or whatever you like so long as it’s meaningful).

     
  2. 2.
    Click the Job/Task link in the designer.
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig42_HTML.jpg
    Figure 13-42

    Name the stage and fix up the task errors

     
Here, we need to
  1. 1.

    Select our Azure subscription (you will need to “authorize” Azure DevOps to use Azure).

    ../images/501438_1_En_13_Chapter/501438_1_En_13_Figk_HTML.jpgWarning! If you’ve got an active pop-up blocker, this can cause you some issues here as the authentication window needs to “pop up.” Depending on your setup, you’ll need to allow pop-ups for this site in order to cleanly authenticate Azure DevOps to use Azure.

     
  2. 2.

    App Type (remember this is an API App)

     
  3. 3.
    App Service Name (all of your API Apps will be retrieved from Azure – select the one you created earlier)
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig43_HTML.jpg
    Figure 13-43

    Fix up the errors and remember to save!

     
Don’t forget to Save. When you do, you’ll be presented with the following.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig44_HTML.jpg
Figure 13-44

Add a comment if you need to

Just click OK.

Click back on the “Pipeline” tab, then on Add (to add an artifact).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig45_HTML.jpg
Figure 13-45

Adding an artifact for deployment

Here, you will need to provide
  1. 1.

    The Project (this should be preselected)

     
  2. 2.

    The Source Pipeline (this is our Build pipeline we created previously)

     
  3. 3.
    Default version (select “Latest” from the drop-down)
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig46_HTML.jpg
    Figure 13-46

    Configure the artifact

     
Click Add. Then click the lightning bolt on the newly created Artifact node.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig47_HTML.jpg
Figure 13-47

Select triggers

In the resulting pop-up, ensure that Continuous deployment trigger is enabled, then click Save.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig48_HTML.jpg
Figure 13-48

Enable the Continuous deployment trigger

Note

It is this setting that switches us from Continuous Delivery to Continuous Deployment.

You’ll get asked to supply a comment when turning this on; do so if you like.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig49_HTML.jpg
Figure 13-49

Again, add a comment if you want to

Click Releases; you’ll see that we have a new pipeline but no release; this is because the pipeline has not yet been executed.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig50_HTML.jpg
Figure 13-50

Release Pipeline created

Pull the Trigger – Continuously Deploy

OK, the moment of truth. If we have set everything up correctly, all we need to do now to test our entire CI/CD pipeline end to end is to perform another code commit to GitHub, which will trigger the Build Pipeline. Then, as we’ve just configured, the Release Pipeline will be triggered by the Build Pipeline, which will deploy our API App to Azure.

Wait! What About EF Migrations?

Just before you do that – cast your mind back to Chapter 7 where we set up our DB Context and performed a database migration at the command line:
dotnet ef database update

Nowhere in our CI/CD pipeline have we accounted for this step, where we tell Azure it has to create the necessary schema in our PostgreSQL DB. There are a few ways we can do this, but the simplest is to update the Configure method in the Startup class.

This approach means that migrations will be applied when the app is started for the first time.

In VS Code, open the Startup class, and make the following alterations to the Configure method:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, CommandContext context)
{
  context.Database.Migrate();
  if (env.IsDevelopment())
  {
    app.UseDeveloperExceptionPage();
  }
  app.UseMvc();
}
For clarity, the Configure method changes are highlighted in Figure 13-51.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig51_HTML.jpg
Figure 13-51

Migrate Database

Save your changes and Add, Commit, and Push your code as usual; this should trigger the build pipeline.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig52_HTML.jpg
Figure 13-52

Pipeline triggered again

When the Build Pipeline finished executing (successfully), click “Releases.”
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig53_HTML.jpg
Figure 13-53

Release pipeline attempting to deploy

You’ll see the Release Pipeline attempting to deploy to Azure And eventually it should deploy (you may need to navigate away from the Release Pipeline and back again).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig54_HTML.jpg
Figure 13-54

Deployed!

And now the moment of truth; let’s see if our API is working; first obtain the base app URL from Azure:
  • Click All resources.

  • Select you API App (App Service type).
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig55_HTML.jpg
    Figure 13-55

    Get the URI for your API App

Note: Yours will be named differently.

Now fire up Postman, and prepare to make a GET request to retrieve all our commands (we won’t have any yet).
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig56_HTML.jpg
Figure 13-56

Call the API on Azure from Postman

Remember to append: /api/commands to the base URL

Then click Send.

If the deployment and Azure configuration were successful, you’ll get an empty payload response and an OK 200 Status.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig57_HTML.jpg
Figure 13-57

Success – but we have no data

Celebration Checkpoint

../images/501438_1_En_13_Chapter/501438_1_En_13_Figl_HTML.jpgRad!3 Our API is deployed and working in our Production Azure environment; moreover, it’s there via process of Continuous Integration/Continuous Deployment!

Double-Check

Just to double-check everything, let’s make a POST request to create some data.

Using the following JSON string:
{
    "howTo": "Create an EF migration",
    "platform": "Entity Framework Core Command Line",
    "commandLine": "dotnet ef migrations add"
}
Create a new Postman request and set
  1. 1.

    Request Verb to POST.

     
  2. 2.

    The request URL is correct (e.g., https://commadapi.azurewebsites.net/api/commands).

     
  3. 3.

    Click Body.

     
  4. 4.

    Select Raw and JSON for the request body format.

     
  5. 5.
    Paste the JSON into the body payload window.
    ../images/501438_1_En_13_Chapter/501438_1_En_13_Fig58_HTML.jpg
    Figure 13-58

    POSTing Data to out Azure hosted API

     
Finally, if you’re brave enough, click “Send” to make the request.
../images/501438_1_En_13_Chapter/501438_1_En_13_Fig59_HTML.jpg
Figure 13-59

201 Success!

And again, we have success!

Celebration Checkpoint

../images/501438_1_En_13_Chapter/501438_1_En_13_Figm_HTML.jpgRevel in the enormity of what you have just done! Not many people can say that have deployed an API on to the cloud via a CI/CD pipeline.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.178