From 17826ab9e0f7ce54b203af56509402b8546e8c5b Mon Sep 17 00:00:00 2001 From: Felipe Augusto Date: Fri, 11 Oct 2024 17:25:57 -0300 Subject: [PATCH] feat: the biggest update --- .github/workflows/AzureContainerApps.yaml | 26 +++++++++++-------- .github/workflows/AzureFunction.yaml | 5 ++-- .github/workflows/AzureWebApp.yaml | 26 +++++++++++-------- README.md | 25 ++++++++++++++++++ .../DEPLOY.CarApp.API.csproj | 1 + .../DEPLOY.CarApp.API/Domain/Car.cs | 5 +++- .../DEPLOY.CarApp.API/Program.cs | 13 ++++++++-- .../DEPLOY.BikeApp.Function/Function1.cs | 2 +- .../DEPLOY.FoodApp.API.csproj | 3 ++- .../DEPLOY.FoodApp.API/Domain/Food.cs | 3 +++ src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs | 5 +++- tests/k6-loadtesting | 1 + 12 files changed, 85 insertions(+), 30 deletions(-) create mode 160000 tests/k6-loadtesting diff --git a/.github/workflows/AzureContainerApps.yaml b/.github/workflows/AzureContainerApps.yaml index 9c35d30..f4f9ade 100644 --- a/.github/workflows/AzureContainerApps.yaml +++ b/.github/workflows/AzureContainerApps.yaml @@ -27,7 +27,12 @@ on: - 'src/AzureContainerApps/**' env: - imageName: apim-car-app + app_path: ./src/AzureContainerApps/DEPLOY.CarApp.API + app_root: ./src/AzureContainerApps + image_name: apim-car-api + resource_group: rg-apim-canal-deploy-apps-lab + app_name: ca-apim-car-app-lab + aca_env: cae-apim-canal-deploy-apps-lab jobs: build: @@ -54,7 +59,7 @@ jobs: run: dotnet --version - name: Install dependencies - run: dotnet restore src/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj + run: dotnet restore ${{ env.app_path }}/**.csproj - name: Build and push Docker image uses: docker/login-action@v3.3.0 @@ -72,10 +77,10 @@ jobs: - name: Build and push Docker image run: | - docker buildx build -f ./src/AzureContainerApps/DEPLOY.CarApp.API/Dockerfile -t ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ./src/AzureContainerApps - docker tag ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.imageName }}:latest - docker push ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} - docker push ${{ github.actor }}/${{ env.imageName }}:latest + docker buildx build -f ${{ env.app_path }}/Dockerfile -t ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ env.app_root }} + docker tag ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.image_name }}:latest + docker push ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} + docker push ${{ github.actor }}/${{ env.image_name }}:latest deploy: if: ${{ github.event_name != 'pull_request' }} @@ -91,12 +96,11 @@ jobs: - name: Deploy to Azure Container App uses: azure/container-apps-deploy-action@v2 with: - # appSourcePath: ${{ github.workspace }}/src/AzureContainerApps/ - containerAppName: ca-apim-car-app-lab - containerAppEnvironment: cae-apim-canal-deploy-apps-lab + containerAppName: ${{ env.app_name }} + containerAppEnvironment: ${{ env.aca_env }} registryUrl: docker.io - imageToDeploy: docker.io/felipementel/${{ env.imageName }}:${{ needs.build.outputs.imageTag }} - resourceGroup: rg-apim-canal-deploy-apps-lab + imageToDeploy: docker.io/${{ github.actor }}/${{ env.imageName }}:${{ needs.build.outputs.imageTag }} + resourceGroup: ${{ env.resourceGroup }} targetPort: 8080 location: brazilsouth environmentVariables: | diff --git a/.github/workflows/AzureFunction.yaml b/.github/workflows/AzureFunction.yaml index 3d14145..9cba1ff 100644 --- a/.github/workflows/AzureFunction.yaml +++ b/.github/workflows/AzureFunction.yaml @@ -28,10 +28,11 @@ on: env: AZURE_FUNCTIONAPP_PACKAGE_PATH: 'src/AzureFunction' + app_name: func-apim-bike-api-lab jobs: build: - environment: lab + # environment: lab runs-on: ubuntu-latest strategy: matrix: @@ -93,7 +94,7 @@ jobs: uses: Azure/functions-action@v1.5.2 id: deploy-function-app with: - app-name: 'func-apim-bike-app' # -lab + app-name: ${{ env.APP_NAME }} slot-name: 'production' publish-profile: ${{ secrets.FUNCTION_PUBLISH_PROFILE }} package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output diff --git a/.github/workflows/AzureWebApp.yaml b/.github/workflows/AzureWebApp.yaml index 4b2a712..3f51720 100644 --- a/.github/workflows/AzureWebApp.yaml +++ b/.github/workflows/AzureWebApp.yaml @@ -27,11 +27,15 @@ on: - 'src/AzureWebApp/**' env: - imageName: apim-food-app + app_path: ./src/AzureWebApp/DEPLOY.FoodApp.API + app_root: ./src/AzureWebApp + image_name: apim-food-api + resource_group: rg-apim-canal-deploy-apps-lab + app_name: app-apim-food-app-lab jobs: build: -# environment: lab + # environment: lab runs-on: ubuntu-latest strategy: matrix: @@ -55,7 +59,7 @@ jobs: run: dotnet --version - name: Install dependencies - run: dotnet restore src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj + run: dotnet restore ${{ env.app_path }}/*.csproj - name: Build and push Docker image uses: docker/login-action@v3.3.0 @@ -68,15 +72,15 @@ jobs: id: get-version shell: bash run: | - version=$(sed -n 's/.*\(.*\)<\/Version>.*/\1/p' ./src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj) + version=$(sed -n 's/.*\(.*\)<\/Version>.*/\1/p' ${{ env.app_path }}/*.csproj) echo "tag=$version" >> "$GITHUB_OUTPUT" - name: Build and push Docker image run: | - docker buildx build -f ./src/AzureWebApp/DEPLOY.FoodApp.API/Dockerfile -t ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ./src/AzureWebApp - docker tag ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.imageName }}:latest - docker push ${{ github.actor }}/${{ env.imageName }}:${{ steps.get-version.outputs.tag }} - docker push ${{ github.actor }}/${{ env.imageName }}:latest + docker buildx build -f ${{ env.app_path }}/Dockerfile -t ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ env.app_root }} + docker tag ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} ${{ github.actor }}/${{ env.image_name }}:latest + docker push ${{ github.actor }}/${{ env.image_name }}:${{ steps.get-version.outputs.tag }} + docker push ${{ github.actor }}/${{ env.image_name }}:latest deploy: if: ${{ github.event_name != 'pull_request' }} @@ -92,15 +96,15 @@ jobs: - name: Deploy to Azure Web App uses: azure/webapps-deploy@v3.0.1 with: - app-name: app-apim-food-app-lab + app-name: ${{ env.app_name }} slot-name: production publish-profile: ${{ secrets.WEBAPP_PUBLISH_PROFILE }} - images: docker.io/${{ github.actor }}/${{ env.imageName }}:${{ needs.build.outputs.imageTag }} + images: docker.io/${{ github.actor }}/${{ env.image_name }}:${{ needs.build.outputs.imageTag }} - name: Set Web App ACR authentication uses: Azure/appservice-settings@v1 with: - app-name: app-apim-food-app-lab + app-name: app-settings-json: | [ { diff --git a/README.md b/README.md index 2ce62aa..fc0b9fe 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,31 @@ https://www.youtube.com/watch?v=n6uTmKUHXyI&list=PLf7uDG4xdAJ0CzqQuYT69WzQnT5HoHAoU&ab_channel=DEPLOY ``` +# Criar um novo projeto + +``` +export subscriptionId=acd12345-6789-1011-1213-141516171819 +``` + +``` +export appDisplayName=userCanalDEPLOY-APIM +``` + +``` +az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/$subscriptionId" --display-name $appDisplayName --sdk-auth +``` + +adaptar resposta para esse padrao + +``` +{ + "appId": "1234", + "displayName": "userCanalDEPLOY-APIM", + "password": "abcd123", + "tenant": "5678" +} +``` + ### Open API Specification ``` diff --git a/src/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj b/src/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj index 503588d..97a2560 100644 --- a/src/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj +++ b/src/AzureContainerApps/DEPLOY.CarApp.API/DEPLOY.CarApp.API.csproj @@ -15,6 +15,7 @@ + diff --git a/src/AzureContainerApps/DEPLOY.CarApp.API/Domain/Car.cs b/src/AzureContainerApps/DEPLOY.CarApp.API/Domain/Car.cs index 7388019..d5d25a2 100644 --- a/src/AzureContainerApps/DEPLOY.CarApp.API/Domain/Car.cs +++ b/src/AzureContainerApps/DEPLOY.CarApp.API/Domain/Car.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using Swashbuckle.AspNetCore.Annotations; +using System.Text.Json.Serialization; namespace DEPLOY.CarApp.API.Domain { @@ -27,6 +28,7 @@ public Car(string make, string model, long year) UpdatedAt = DateTime.Now; } + [SwaggerSchema(ReadOnly = true)] public Guid Id { get; init; } public string Make { get; init; } @@ -37,6 +39,7 @@ public Car(string make, string model, long year) public bool Sold { get; private set; } + [SwaggerSchema(ReadOnly = true)] public DateTime CreatedAt { get; init; } public DateTime UpdatedAt { get; private set; } diff --git a/src/AzureContainerApps/DEPLOY.CarApp.API/Program.cs b/src/AzureContainerApps/DEPLOY.CarApp.API/Program.cs index e95a5eb..941c14d 100644 --- a/src/AzureContainerApps/DEPLOY.CarApp.API/Program.cs +++ b/src/AzureContainerApps/DEPLOY.CarApp.API/Program.cs @@ -12,9 +12,18 @@ public static void Main(string[] args) var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); - // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + + builder.Services.AddRouting(opt => + { + opt.LowercaseUrls = true; + opt.LowercaseQueryStrings = true; + }); + builder.Services.AddEndpointsApiExplorer(); - builder.Services.AddSwaggerGen(); + builder.Services.AddSwaggerGen(options => + { + options.EnableAnnotations(); + }); builder.Services.Configure(options => options.Title = "Canal DEPLOY Scalar"); diff --git a/src/AzureFunction/DEPLOY.BikeApp.Function/Function1.cs b/src/AzureFunction/DEPLOY.BikeApp.Function/Function1.cs index 2cadc45..a70f9ec 100644 --- a/src/AzureFunction/DEPLOY.BikeApp.Function/Function1.cs +++ b/src/AzureFunction/DEPLOY.BikeApp.Function/Function1.cs @@ -14,7 +14,7 @@ public Function1(ILogger logger) _logger = logger; } - [Function("Function1")] + [Function("bike")] public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req) { _logger.LogInformation("C# HTTP trigger function processed a request."); diff --git a/src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj b/src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj index a7e8c06..1befcd2 100644 --- a/src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj +++ b/src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -14,6 +14,7 @@ + diff --git a/src/AzureWebApp/DEPLOY.FoodApp.API/Domain/Food.cs b/src/AzureWebApp/DEPLOY.FoodApp.API/Domain/Food.cs index c73176d..7590181 100644 --- a/src/AzureWebApp/DEPLOY.FoodApp.API/Domain/Food.cs +++ b/src/AzureWebApp/DEPLOY.FoodApp.API/Domain/Food.cs @@ -1,3 +1,4 @@ +using Swashbuckle.AspNetCore.Annotations; using System.Text.Json.Serialization; namespace DEPLOY.FoodApp.API.Domain @@ -28,12 +29,14 @@ public Food( UpdatedAt = DateTime.Now; } + [SwaggerSchema(ReadOnly = true)] public Guid Id { get; init; } public decimal Price { get; init; } public FoodType Type { get; init; } + [SwaggerSchema(ReadOnly = true)] public DateTime CreatedAt { get; init; } public DateTime UpdatedAt { get; private set; } diff --git a/src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs b/src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs index 8e59f5b..270452c 100644 --- a/src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs +++ b/src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs @@ -32,7 +32,10 @@ public static void Main(string[] args) }); builder.Services.AddEndpointsApiExplorer(); - builder.Services.AddSwaggerGen(); + builder.Services.AddSwaggerGen(options => + { + options.EnableAnnotations(); + }); builder.Services.AddDbContext(options => { diff --git a/tests/k6-loadtesting b/tests/k6-loadtesting new file mode 160000 index 0000000..e93a253 --- /dev/null +++ b/tests/k6-loadtesting @@ -0,0 +1 @@ +Subproject commit e93a253cab52cbd525a18c0bb85efa10b6174c92