Skip to content

Commit

Permalink
docs: organizando o readme do projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
felipementel committed Dec 15, 2023
1 parent ee7a2fe commit b75a52c
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 13 deletions.
211 changes: 204 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,48 @@ Projeto educacional, criado e mantido através do canal DEPLOY no YouTube.

> Para criar a imagem, a partir do diretório root da aplicação (pasta que contem o arquivo sln)
# pre-requisitos para executar o projeto

1. Docker
2. Um conta no Azure para criar recursos

```
docker build -f ./DEPLOY.Cachorro.Api/Dockerfile -t crcanaldeploydev.azurecr.io/cachorro.api:0.4 .
mnt ❯ c ❯ proj ❯ DEPLOY ❯ DEPLOY.Cachorro $ docker build -f ./DEPLOY.Cachorro.Api/Dockerfile -t crcanaldeploydev.azurecr.io/cachorro.api:latest .
```

dotnet run --project ./src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj ASPNETCORE_ENVIRONMENT=aaa ConnectionStrings:ApplicationInsights="bbb" ConnectionStrings:DefaultConnection="ccc" ConnectionStrings:AppConfiguration="ddd"
ApplicationInsights:ApiKey="eee" KeyVault:VaultUri="fff"

> Para executar o projeto local, utilizando docker
```
docker container run --rm -p 8088:80 -e ConnectionsString__ApplicationInsights="xxxx" -e ApplicationInsights__ApiKey="yyy" felipementel/cachorro-api:0.3
docker container run --rm -p 8088:80 \
-e ASPNETCORE_ENVIRONMENT=aaa \
-e ConnectionStrings__ApplicationInsights="bbb" \
-e ConnectionStrings__DefaultConnection="ccc" \
-e ConnectionStrings__AppConfiguration="ddd" \
-e ApplicationInsights__ApiKey="eee" \
-e KeyVault__VaultUri="fff" \
felipementel/cachorro.api:latest
```

aaa = Development|Production
bbb = ConnectionString do Application Insights
ccc = Connection String (Azure SQL Database ou https://hub.docker.com/_/microsoft-azure-sql-edge)
ddd = Connection string do App Configuration
eee = ApiKey gerada dentro do Application Insights
fff = URI do Azure KeyVault

Comando para subir o banco de dados local:

```
docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=Abcd1234%' -e 'MSSQL_PID=Developer' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge:2.0.0
```

Caso queira testar com outra tag, utilize os comandos abaixo para obter a lista de tags

```
https://mcr.microsoft.com/v2/azure-sql-edge/tags/list
```

# Testes de unidade
Expand All @@ -55,44 +89,59 @@ dotnet test
```

2. Geração de relatório de testes

1.1 A partir da pasta src execute o comando:

```
dotnet test --collect:"XPlat Code Coverage" --logger "console;verbosity=detailed"
dotnet test --collect:"XPlat Code Coverage" --logger "console;verbosity=detailed" --results-directory .\DEPLOY.Cachorro.Api.Tests\TestResults\XPlatCodeCoverage\
```

ou
e depois execute:

```
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
reportgenerator -reports:.\DEPLOY.Cachorro.Api.Tests\TestResults\XPlatCodeCoverage\**\coverage.cobertura.xml -targetdir:./DEPLOY.Cachorro.Api.Tests/TestResults/XPlatCodeCoverage/CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
```

1.2 A partir da pasta src execute o comando:
ou

```
$var = (Get-Date).ToString("yyyyMMdd-HHmmss"); dotnet-coverage collect "dotnet test" -f xml -o ".\DEPLOY.Cachorro.Api.Tests\TestResults\DotnetCoverageCollect\$var\coverage.cobertura.xml"
```

```
reportgenerator -reports:C:/Proj/DEPLOY/DEPLOY.Cachorro/src/DEPLOY.Cachorro.Api.Tests/TestResults/**/*cobertura.xml -targetdir:C:/Proj/DEPLOY/DEPLOY.Cachorro/src/DEPLOY.Cachorro.Api.Tests/coveragereport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
reportgenerator -reports:.\DEPLOY.Cachorro.Api.Tests\TestResults\DotnetCoverageCollect\**\coverage.cobertura.xml -targetdir:./DEPLOY.Cachorro.Api.Tests/TestResults/DotnetCoverageCollect/CoverageReport -reporttypes:"Html;SonarQube;JsonSummary;Badges" -verbosity:Verbose -title:Cachorro.API -tag:canal-deploy
```

1.2 A partir da pasta src execute o comando:

---

# EntityFramework Commands

```
dotnet tool install --global dotnet-ef
```

```
dotnet ef migrations add InitDatabaseAPI -s DEPLOY.Cachorro.Api -p DEPLOY.Cachorro.Repository -c DEPLOY.Cachorro.Repository.CachorroDbContext --output-dir Migrations/API -v
```

```
dotnet ef database update InitDatabaseAPI --startup-project DEPLOY.Cachorro.Api --project DEPLOY.Cachorro.Repository --context DEPLOY.Cachorro.Repository.CachorroDbContext --verbose
```

Connection String

```
Data Source=127.0.0.1,1433;Initial Catalog=Cachorro;User Id=sa;Password=Abcd1234%;Integrated Security=False;MultipleActiveResultSets=True;TrustServerCertificate=true;
```

<br/>
Expand All @@ -104,37 +153,185 @@ Data Source=127.0.0.1,1433;Initial Catalog=Cachorro;User Id=sa;Password=Abcd1234
# Link de documentações citadas durante a criaçao do projeto

```
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet
```

```
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0
```

```
https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-7.0&tabs=windows
```

ILogger

```
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0
```

```
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test
```

```
https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger?tabs=dotnet6
```

Application Insights

```
https://learn.microsoft.com/pt-br/azure/azure-monitor/app/asp-net-core?tabs=netcorenew%2Cnetcore6
```

Live Stream / Live Metrics

```
https://learn.microsoft.com/en-us/azure/azure-monitor/app/live-stream?tabs=dotnet6
```

Configurations

```
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-7.0
```

Docker Commands

```
docker container rm -f $(docker ps -a -q)
```

```
docker volume rm $(docker volume ls -q)\
```

```
docker image rm -f $(docker image ls -a -q)
```

```
docker system prune
```

```
docker image ls
```

```
docker tag 430f5d9f4229 crcanaldeploydev.azurecr.io/cachorro.api:latest
```

```
docker push crcanaldeploydev.azurecr.io/cachorro.api:latest
```

```
docker push ghcr.io/felipementel/cachorro.api:latest
```

```
docker container run -p 8088:80 crcanaldeploydev.azurecr.io/cachorro.api:latest
```

```
docker container run --rm --name sonar-canal-deploy -p 9044:9000 sonarqube:10.3.0-community
```

Comandos Azure Key Vault

```
az keyvault secret show --name CachorroConnectionString --vault-name kv-canaldeploy-dev
```

```
@Microsoft.KeyVault(SecretUri=https://kv-canaldeploy-dev.vault.azure.net/secrets/ConnectionStrings--ApplicationInsights/)
```

```
@Microsoft.KeyVault(VaultName=kv-canaldeploy-dev;SecretName=ConnectionStrings--ApplicationInsights)
```

Comandos Azure Container Instance

```
az container logs --resource-group rg-canaldeploy-dev --name api-cachorro
```

```
az container exec -g g-canaldeploy-dev --name cachorro.api --exec-command "/bin/bash"
```

/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml

```
```

#git
#github
#github-actions
#sonar-qube
#wsl-2
#docker
#docker-compose
#docker-hub
#donet
#ef-core
#entity-framework-core
#x-unit
#postman
#azure
#azure-application-ingishts
#azure-sql-database
#azure-app-configuration
#azure-container-registry
#azure-container-instance
#azure-container-apps
#azure-key-vault
10 changes: 10 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ services:
ports:
- 1433:1433

sonarqube:
image: sonarqube:10.3.0-community
hostname: sonar-canal-deploy
container_name: sonar-canal-deploy
restart: always
networks:
- cachorro-net
ports:
- 9044:9000

networks:
cachorro-net:
driver: bridge
2 changes: 1 addition & 1 deletion src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<ApplicationInsightsResourceId>/subscriptions/f4574f09-7fab-45bd-8eb5-508b8c6aa04a/resourceGroups/rg-canaldeploy-dev/providers/microsoft.insights/components/appi-cachorroapi-dev</ApplicationInsightsResourceId>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public static void AddTelemetriaExtension(
services
.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = configuration.GetSection("ConnectionsString:ApplicationInsights").Value;
options.ConnectionString = configuration.GetSection("ConnectionStrings:ApplicationInsights").Value;
})
.ConfigureTelemetryModule<QuickPulseTelemetryModule>((module, o) =>
{
module.AuthenticationApiKey = configuration.GetSection("ApplicationInsights:ApiKey").Value;
});
});

services
.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
{
module.EnableSqlCommandTextInstrumentation = true;
module.EnableSqlCommandTextInstrumentation = true;
});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/DEPLOY.Cachorro.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.Azure;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using Azure.Identity;

namespace DEPLOY.Cachorro.Api
{
Expand Down

0 comments on commit b75a52c

Please sign in to comment.