Demo project using dotnet core MVC application calling a rest API. This project will be published on Azure WebApp.
The rest api is very simple, just a method to simulate the weather forecast.
This folder contains all source files for application
- ProjetoDemo.WebApi: dotnet 6 rest api
- ProjetoDemo.WebApp: dotnet 6 web application (mvc)
- ProjetoDemo.UnitTest: xunit test project
This folder contains the bicep files to create Azure environments
- main.bicep: file for creating azure web app
-
Install .NET 6 - https://dotnet.microsoft.com/en-us/download/dotnet/6.0
-
Install Visual Studio Community or Visual Studio Code - https://visualstudio.microsoft.com/free-developer-offers/
-
Open the solution file src/ProjetoDemo.sln
-
Configure Visual Studio to run multiple projects. Right click in ProjetoDemo solution -> Properties -> Startup Project. Select the option Multiple startup projects and select the projects ProjetoDemo.WebApi and ProjetoDemo.WebApp
- Run the application press F5
If you want to publish this application to Azure using GitHub actions, follow these steps
- Create resource group for application
# set variables
$rgName = 'rg-MyProjectDemo'
$location ='eastus'
# login
az login
# set the correct subscription
az account set --subscription '11111111-2222-3333-4444-55555555'
$SubscriptionId = az account show --query id --output tsv
# check the subscription
az account show
# create resource group
az group create --name $rgName --location $location
- Create service principal to access the Resource Group with contributor role
az ad sp create-for-rbac --name spnProjetoDemo --role contributor --scopes /subscriptions/$SubscriptionId/resourceGroups/$rgName --sdk-auth
- Configure the GitHub secrets, select Settings > Secrets > New secret. Paste the entire JSON output from the Azure CLI command into the secret's value field. Name the secret AZURE_CREDENTIALS.
- Start the GitHub Action 01-ProjetoDemo_IAC to run the bicep file and create the Azure environment
- Go to the Azure portal and verify that the resources were created successfully.
- Get the publish profile for Web Api
az webapp deployment list-publishing-profiles --resource-group $rgName --name wapp-MyProjectDemo-api --xml
-
Store the publish profile into a GitHub secret, select Settings > Secrets > New secret. Paste the entire XML output from the Azure CLI command into the secret's value field. Name the secret AZURE_PUBLISH_PROFILE_API.
-
Get the publish profile for Web App
az webapp deployment list-publishing-profiles --resource-group $rgName --name wapp-MyProjectDemo-app --xml
-
Store the publish profile into a GitHub secret, select Settings > Secrets > New secret. Paste the entire XML output from the Azure CLI command into the secret's value field. Name the secret AZURE_PUBLISH_PROFILE_APP.
-
Run the GitHub Action 02-ProjetoDemo_Build_Deploy to build, test and deploy the application to Azure
Other option is running this application using container Docker.
- Generate docker images locally
cd .\src\
docker build -t projetodemo.webapp -f .\ProjetoDemo.WebApp\Dockerfile .
docker build -t projetodemo.webapi -f .\ProjetoDemo.WebApi\Dockerfile .
- Docker compose locally
cd .\src\
docker-compose -f .\docker-compose.yml up
-
Create GibHub secrets for ACR login and ACR password
-
Runn the GH action 03-ProjetoDemo_IAC_Container to create the Azure Environment
-
Run the GitHub Action 04-ProjetoDemo_Container to build and push docker images do ACR
Let me know and I'll be glad to invite you !!!, then ...
- Clone this repository:
git clone https://github.com/lsprado/ProjetoDemo.git
- Create your feature branch:
git checkout -b features/my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin features/my-new-feature
- Submit a pull request 😄