dotnet new webapp
dotnet new gitignore
dotnet run
dotnet publish --configuration Release --output out
dotnet .\o ut\< name-of-project> .dll
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish --configuration release --output out
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT [ "dotnet" , "<name-of-project>.dll" ]
docker build --tag aspnetrazor .
docker run --detach --publish 5550:80 aspnetrazor
Build and push Docker workflow
name : .NET Continuous Delivery
on : push
jobs :
build-container :
name : Build and push Docker container image
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v3
name : Checkout code
- uses : docker/build-push-action@v2
name : Build Docker container imagte
with :
context : .
push : false
- uses : docker/login-action@v1
name : Login to container registry
with :
registry : <resource-name>.azurecr.io
username : ${{ secrets.DOCKER_REGISTRY_IDENTITY }}
password : ${{ secrets.DOCKER_REGISTRY_TOKEN }}
- uses : docker/build-push-action@v2
name : Build Docker container imagte
with :
context : .
push : true
tags : |
<resource-name>.azurecr.io/aspnetrazor:${{ github.run_number }}
<resource-name>.azurecr.io/aspnetrazor:latest
deploy-template :
name : Deploy Bicep template to Azure
runs-on : ubuntu-latest
needs : build-container
steps :
$id =(az group show --name < resource-group-name> --query ' id' --output tsv)
echo $id
az ad sp create-for-rbac --name < aad-app-name> --sdk-auth --role contributor --scopes $id
- uses : azure/login@v1
name : Login to Azure CLI
with :
creds : ${{ secrets.AZURE_CREDENTIALS }}
- run : |
az account show
name : Show account details
param location string = resourceGroup().location
resource registry 'Microsoft.ContainerRegistry/registries@2021-12-01-preview' = {
name: '<name-of-acr-resource>'
location: location
sku: {
name: 'Standard'
}
properties: {
adminUserEnabled: true
}
}
az deployment group create \
--resource-group < resource-group-name> \
--template-file < filename> .bicep
param appName string = uniqueString(resourceGroup().id)
resource container 'Microsoft.ContainerInstance/containerGroups@2021-10-01' = {
name: appName
location: location
properties: {
osType: 'Linux'
imageRegistryCredentials: [
{
server: '<acr-resource-name>.azurecr.io'
username: '<acr-resource-name>'
password: '<acr-password>'
}
]
containers: [
{
name: 'webfrontend'
properties: {
image: '<acr-resource-name>.azurecr.io/aspnetrazor:latest'
ports: [
{
port: 80
protocol: 'TCP'
}
]
resources: {
requests: {
cpu: 1
memoryInGB: 2
}
}
}
}
]
ipAddress: {
type: 'Public'
dnsNameLabel: appName
ports: [
{
port: 80
protocol: 'TCP'
}
]
}
}
}
- uses : actions/checkout@v3
name : Checkout code
with :
repository : <organization>/<repository>
- run : |
az deployment group create \
--resource-group <resource-group-name> \
--template-file <template-file>.bicep
name : Deploy template