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

feat: add API versioning to Docker build and Swagger documentation #43

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
build-args: |
API_VERSION=${{ steps.sanitize-version.outputs.version }}
file: ./src/Bmb.Payment.Api/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
7 changes: 5 additions & 2 deletions src/Bmb.Payment.Api/Bmb.Payment.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
<Version>1.0.0</Version>
<Product>Payment API</Product>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand All @@ -18,7 +20,7 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
<PackageReference Include="Bmb.Auth" Version="0.0.1" />
<PackageReference Include="Bmb.Tools" Version="0.0.4" />
<PackageReference Include="MassTransit" Version="8.2.5" />
<PackageReference Include="MassTransit.AmazonSQS" Version="8.2.5" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3"/>
Expand All @@ -29,7 +31,8 @@
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="7.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Bmb.Payment.Api/Controllers/PaymentsController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bmb.Auth;
using Bmb.Payment.Api.Model;
using Bmb.Payment.Controllers.Contracts;
using Bmb.Payment.Controllers.Dto;
using Bmb.Tools.Auth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

Expand Down
3 changes: 2 additions & 1 deletion src/Bmb.Payment.Api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN dotnet restore src/Bmb.Payment.Api

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "src/Bmb.Payment.Api/Bmb.Payment.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
ARG API_VERSION
RUN dotnet publish "src/Bmb.Payment.Api/Bmb.Payment.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$API_VERSION


FROM base AS final
Expand Down
40 changes: 5 additions & 35 deletions src/Bmb.Payment.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.Json.Serialization;
using Bmb.Auth;
using Bmb.Payment.Masstransit;
using Bmb.Payment.DI;
using Bmb.Tools.Auth;
using Bmb.Tools.OpenApi;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Serilog;
using Serilog.Events;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
Expand All @@ -23,6 +22,7 @@ public static void Main(string[] args)
ILogger<Program>? logger = null;
try
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
builder.Host.UseSerilog((context, configuration) =>
configuration
.MinimumLevel.Debug()
Expand All @@ -35,7 +35,6 @@ public static void Main(string[] args)
builder.Services.ConfigureJwt(builder.Configuration);
builder.Services.AddAuthorization();
builder.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));

// Add CORS services to the DI container.
builder.Services.AddCors(options =>
{
Expand All @@ -52,36 +51,7 @@ public static void Main(string[] args)
builder.Services.AddPaymentBus();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "BMB Payment API", Version = "v1", Extensions =
{
{
"x-logo",
new OpenApiObject
{
{
"url",
new OpenApiString(
"https://avatars.githubusercontent.com/u/165858718?s=384")
},
{
"background",
new OpenApiString(
"#FF0000")
}
}
}
}
});

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
builder.Services.ConfigBmbSwaggerGen();

var jwtOptions = builder.Configuration
.GetSection("JwtOptions")
Expand All @@ -108,7 +78,7 @@ public static void Main(string[] args)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseBmbSwaggerUi();
}

app.UseSerilogRequestLogging();
Expand Down