From 1e9e513b6df5b148497d51eab9cbe7cd1d484cd6 Mon Sep 17 00:00:00 2001 From: Felipe Augusto <14238257+felipementel@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:17:52 -0300 Subject: [PATCH 1/2] feat: update github actions to run all steps in Linux --- .github/workflows/push-image.yaml | 77 +++++++++++++++++++------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/.github/workflows/push-image.yaml b/.github/workflows/push-image.yaml index 22dabee..6e61438 100644 --- a/.github/workflows/push-image.yaml +++ b/.github/workflows/push-image.yaml @@ -8,28 +8,37 @@ 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 @@ -37,43 +46,52 @@ jobs: 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 @@ -89,13 +107,12 @@ jobs: version=$(sed -n 's/.*\(.*\)<\/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 }} From e1c763e9488585812d0d21cdfd5de36e9c422b58 Mon Sep 17 00:00:00 2001 From: Felipe Augusto <14238257+felipementel@users.noreply.github.com> Date: Wed, 20 Dec 2023 17:21:00 -0300 Subject: [PATCH 2/2] docs: update references --- README.md | 63 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 58f7d87..9b7ea3b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,12 @@ git config --local user.name "Felipe Augusto" git config --local user.email felipementel@hotmail.com ``` +``` + +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) @@ -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 @@ -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 ``` @@ -167,7 +160,7 @@ 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 +## Link de documentações citadas durante a criaçao do projeto ``` https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet @@ -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 ``` @@ -205,7 +212,7 @@ https://learn.microsoft.com/en-us/azure/azure-monitor/app/ilogger?tabs=dotnet6 ``` -Application Insights +### Application Insights ``` @@ -221,7 +228,7 @@ https://learn.microsoft.com/en-us/azure/azure-monitor/app/live-stream?tabs=dotne ``` -Key Vault +### Key Vault ``` @@ -237,7 +244,7 @@ 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 ``` @@ -245,7 +252,15 @@ https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=a ``` -Azure App Configuration +### SonarQube + +``` + +https://docs.sonarsource.com/sonarcloud/advanced-setup/analysis-parameters/ + +``` + +### Azure App Configuration ``` @@ -261,7 +276,7 @@ https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-c ``` -Docker Commands +### Docker Commands ``` @@ -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 ``` @@ -349,7 +364,7 @@ az keyvault secret show --name CachorroConnectionString --vault-name kv-canaldep ``` -Comandos Azure Container Instance +### Comandos Azure Container Instance ```