In this guide you will learn how to:
- Set up your repo and getting up and running in GitHub Codespaces.
- Connect the repo to Azure and deploy your application.
- View the live app's logs and metrics in the Azure Portal.
Codespaces is a Github feature that enables you to run a full development environment in the cloud. It uses VS Code in the browser to host dev containers. The template comes complete with all the necessary tools and extensions for developing your application.
Note: You can also run the template locally, by cloning the repo.
These steps will help you create your own repository and open it in Codespaces:
-
Click the green button Use this template to create a copy of this repository.
-
Change the Owner to your GitHub account and enter a unique repository name.
-
Click Create repository from template.
-
Ensure you are in the newly create repository when continuing this quickstart.
-
Click on the green Code button and select Open with Codespaces.
Note: This feature is in private preview, so if you do not see the option, learn how to run your app in a dev container.
-
Create a new Codespace if one does not already exist.
-
The repo will open inside of VS Code in your browser.
-
Once Codespaces is open, hit F5 to start the application. This will run the
Debug webAPI
launch task. -
When VS Code prompts you, select Open in Browser in the lower right. This will take you to the Swagger page exposed by the Web API where you can test the different routes.
Note If your browser is blocking the pop-up, you'll have to restart the debug task with Ctrl+Shift+F5.
The template sets up your deployment process by implementing GitHub workflows to deploy your application to Azure. More information on deployment can be found in the conceptual documentation. Now that your app is running in Codespaces, let's get it hosted in Azure!
GitHub workflows will use a Service Principal to authenticate to Azure and deploy the application to your subscription.
These steps will help you create a Service Principal and hook it up to your GitHub repo.
-
Create a new Azure subscription or use an existing one.
-
Create a new terminal (
Ctrl + Shift + `
) in Codespaces. -
Log into your Azure account with
az login
and follow the prompts. -
List your available subscriptions with
az account list
and set the default by name or ID withaz account set -s <subName or subID>
-
Enter
az account show
to verify the correct subscription is selected. -
Enter
az ad sp create-for-rbac --sdk-auth --role Contributor --scopes /subscriptions/{subscriptionId}
to create a service principal, replacingsubscriptionId
with your own subscription ID.Note: This Service Principal will have subscription-wide contributor rights. This gives access to all resources in the subscription.
-
Copy the full JSON output including
{}
. -
On GitHub.com, navigate to your repository and go to Settings > Secrets > New repository secret. Click here for more information on creating a GitHub secret.
-
Add a new secret named
AZURE_CREDENTIALS
and paste the full JSON output.
The build and release workflow will build, test, and deploy the application using the configuration in config.yaml
.
These steps will help you start the build workflow manually.
- From GitHub in the browser, select the Actions tab in your repo.
- Select the Build and Release workflow.
- Open the Run workflow dropdown and select Run workflow.
Once your app is successfully deployed, your Web API is running in an App Service and now communicates with an instance of Azure SQL Database. Your app is live!
These steps will help you open a running instance of your application in the cloud.
-
Once the deploy workflow is successfully completed, go to the Azure Portal and login.
-
Click the top-middle search bar and search for Subscriptions under the Services category.
-
Select the default subscription you chose during Connect your repository to Azure.
-
On the left hand side navigation, scroll down and select Resource groups.
-
Select the resource group that contains
rg-{gitHub repository name}
. This should be the resource group created by the template deployment. -
Select the App Service resource.
-
In the Essentials section, click the URL to open your deployed application.
We've set up an Application Insights resource with your deployment, so you can monitor and view the logs of your app in real time.
These steps will help you view the health, logs, and metrics of your app.
-
From the Azure Portal, navigate to your subscription and select the resource group that begins with
test
(directions in the previous section). -
Select the Application Insights resource that contains
insights
. -
From the Overview tab, observe the key diagnostics of your cloud application.
-
Click on Application Dashboard to get a comprehensive view of your app's performance and reliability.
Great job, you did it! Now that your application is up and running, you may want to:
- Did you find a bug or think of an idea to improve this template? Submit an issue. We love your feedback!