Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gc actions #27

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 47 additions & 30 deletions .github/workflows/push-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,90 @@ on:
- main
workflow_dispatch:

env:
imageName: cachorro.api
dotnetVersion: 7.x
csprojFolder: ./src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj

jobs:
build:
name: Analyze by SonarCloud
runs-on: windows-latest
build-and-sonar:
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v3
distribution: "zulu"

- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.dotnetVersion }}

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner

- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
if: ${{ steps.cache-sonar-scanner.outputs.cache-hit != 'true' }}
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
mkdir -p .sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path .sonar/scanner

- name: Install dotnet-coverage
shell: powershell
- name: Install SonarCloud scanner
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage

dotnet tool install --global dotnet-reportgenerator-globaltool

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"felipementel_DEPLOY.Cachorro.Api" /o:"felipementel" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/Migrations/**"
dotnet run --project src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj --no-incremental
dotnet-coverage collect "dotnet test src" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

dotnet-sonarscanner begin /k:"felipementel_DEPLOY.Cachorro.Api" /o:"felipementel" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/Migrations/**"
dotnet restore ${{ env.csprojFolder }}
dotnet build ${{ env.csprojFolder }} --no-incremental
dotnet-coverage collect 'dotnet test ./src/' -f xml -o 'coverage.xml'
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

docker:
name: Push image to Registry
needs: [build]
needs: build-and-sonar
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
uses: docker/setup-buildx-action@v1
with:
version: latest
buildkitd-flags: --debug

- name: Login to Docker Hub
uses: docker/login-action@v3
Expand All @@ -89,13 +107,12 @@ jobs:
version=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' ./src/DEPLOY.Cachorro.Api/DEPLOY.Cachorro.Api.csproj)
echo "tag=$version" >> "$GITHUB_OUTPUT"

- name: Build and push
- name: Build and push docker
uses: docker/build-push-action@v5
with:
context: ./src/
file: ./src/DEPLOY.Cachorro.Api/Dockerfile
push: true
platforms: ${{ matrix.platforms }}
tags: |
felipementel/cachorro.api:latest
felipementel/cachorro.api:${{ steps.get-version.outputs.tag }}
felipementel/${{ env.imageName }}:latest
felipementel/${{ env.imageName }}:${{ steps.get-version.outputs.tag }}
63 changes: 39 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ git config --local user.name "Felipe Augusto"
git config --local user.email [email protected]
```

```

git fetch origin --prune

```

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)
Expand All @@ -29,8 +35,10 @@ Projeto educacional, criado e mantido através do canal DEPLOY no YouTube.

> Para executar o projeto local:

```
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

Expand All @@ -47,25 +55,10 @@ 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
```

Expand Down Expand Up @@ -167,7 +160,7 @@ Data Source=127.0.0.1,1433;Initial Catalog=Cachorro;User Id=sa;Password=Abcd1234
<br/>
<br/>

# Link de documentações citadas durante a criaçao do projeto
## Link de documentações citadas durante a criaçao do projeto

```
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet
Expand All @@ -179,13 +172,27 @@ https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetc

```

```
https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/app-user

```

```

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

```
### Github
```
https://docs.github.com/en/actions

ILogger
```

```
https://github.com/marketplace/actions/reportgenerator
```

### ILogger

```

Expand All @@ -205,7 +212,7 @@ https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger?tabs=dotnet6

```

Application Insights
### Application Insights

```

Expand All @@ -221,7 +228,7 @@ https://learn.microsoft.com/en-us/azure/azure-monitor/app/live-stream?tabs=dotne

```

Key Vault
### Key Vault

```

Expand All @@ -237,15 +244,23 @@ https://learn.microsoft.com/en-us/dotnet/azure/sdk/dependency-injection?tabs=web
https://learn.microsoft.com/pt-br/aspnet/core/security/key-vault-configuration?view=aspnetcore-3.1
```

Configuration
### Configuration

```

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

```

Azure App Configuration
### SonarQube

```

https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-parameters/

```

### Azure App Configuration

```

Expand All @@ -261,7 +276,7 @@ https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-c

```

Docker Commands
### Docker Commands

```

Expand Down Expand Up @@ -329,7 +344,7 @@ docker container run --rm --name sonar-canal-deploy -p 9044:9000 sonarqube:10.3.

```

Comandos Azure Key Vault
### Comandos Azure Key Vault

```

Expand All @@ -349,7 +364,7 @@ az keyvault secret show --name CachorroConnectionString --vault-name kv-canaldep

```

Comandos Azure Container Instance
### Comandos Azure Container Instance

```

Expand Down
Loading