Skip to content

Commit

Permalink
feat: the biggest update
Browse files Browse the repository at this point in the history
  • Loading branch information
felipementel committed Oct 11, 2024
1 parent 3ad4cb7 commit 17826ab
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 30 deletions.
26 changes: 15 additions & 11 deletions .github/workflows/AzureContainerApps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/[email protected]
Expand All @@ -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' }}
Expand All @@ -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: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/AzureFunction.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -93,7 +94,7 @@ jobs:
uses: Azure/[email protected]
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
Expand Down
26 changes: 15 additions & 11 deletions .github/workflows/AzureWebApp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/[email protected]
Expand All @@ -68,15 +72,15 @@ jobs:
id: get-version
shell: bash
run: |
version=$(sed -n 's/.*<Version>\(.*\)<\/Version>.*/\1/p' ./src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj)
version=$(sed -n 's/.*<Version>\(.*\)<\/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' }}
Expand All @@ -92,15 +96,15 @@ jobs:
- name: Deploy to Azure Web App
uses: azure/[email protected]
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: |
[
{
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.8.1" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion src/AzureContainerApps/DEPLOY.CarApp.API/Domain/Car.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using Swashbuckle.AspNetCore.Annotations;
using System.Text.Json.Serialization;

namespace DEPLOY.CarApp.API.Domain
{
Expand Down Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down
13 changes: 11 additions & 2 deletions src/AzureContainerApps/DEPLOY.CarApp.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarOptions>(options => options.Title = "Canal DEPLOY Scalar");

Expand Down
2 changes: 1 addition & 1 deletion src/AzureFunction/DEPLOY.BikeApp.Function/Function1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Function1(ILogger<Function1> 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.");
Expand Down
3 changes: 2 additions & 1 deletion src/AzureWebApp/DEPLOY.FoodApp.API/DEPLOY.FoodApp.API.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand All @@ -14,6 +14,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.8" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.8.1" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions src/AzureWebApp/DEPLOY.FoodApp.API/Domain/Food.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Swashbuckle.AspNetCore.Annotations;
using System.Text.Json.Serialization;

namespace DEPLOY.FoodApp.API.Domain
Expand Down Expand Up @@ -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; }
Expand Down
5 changes: 4 additions & 1 deletion src/AzureWebApp/DEPLOY.FoodApp.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context>(options =>
{
Expand Down
1 change: 1 addition & 0 deletions tests/k6-loadtesting
Submodule k6-loadtesting added at e93a25

0 comments on commit 17826ab

Please sign in to comment.