Skip to content

Commit

Permalink
Consumer API: Endpoint for reading the current major version of the B…
Browse files Browse the repository at this point in the history
…ackbone (#704)

* feat: add version endpoint

* fix: return the actual majorVersion of the backbone

* refactoring

* refactor: rename

* fix: implement another approach for getting the major version of the backbone

* fix: version

* Revert "fix: version"

This reverts commit 14cd86e.

* feat: add exception when version is null or empty

* fix: remove hardcoded version & add version to other dockerfiles

* Revert "fix: remove hardcoded version & add version to other dockerfiles"

This reverts commit 29a32ac.

* fix: remove hardcoded version

* Revert "fix: remove hardcoded version"

This reverts commit 8cb1402.

* fix: remove hardcoded version number

* fix: build arg version

* fix: add run echo command to version

* fix: remove echo

* fix: use publish

* fix: add version to property group

* Revert "fix: add version to property group"

This reverts commit 6a270ca.

* chore: simplify docker file

* chore: add version to dockerfiles

* chore: add version tag to build container image

* refactor: add VersionResponse

* fix: formatting

* chore: change service to singleton

* chore: remove nullable operator

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
HunorTotBagi and mergify[bot] authored Jun 24, 2024
1 parent dace53d commit cd92fba
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .ci/acli/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./Modules/Devices/src/Devices.AdminCli/Dockerfile --tag ghcr.io/nmshd/backbone-admin-cli:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./Modules/Devices/src/Devices.AdminCli/Dockerfile --tag ghcr.io/nmshd/backbone-admin-cli:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/aui/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./AdminApi/src/AdminApi/Dockerfile --tag ghcr.io/nmshd/backbone-admin-ui:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./AdminApi/src/AdminApi/Dockerfile --tag ghcr.io/nmshd/backbone-admin-ui:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/capi/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./ConsumerApi/Dockerfile --tag ghcr.io/nmshd/backbone-consumer-api:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./ConsumerApi/Dockerfile --tag ghcr.io/nmshd/backbone-consumer-api:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/dbm/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./DatabaseMigrator/Dockerfile --tag ghcr.io/nmshd/backbone-database-migrator:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./DatabaseMigrator/Dockerfile --tag ghcr.io/nmshd/backbone-database-migrator:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/eh/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./EventHandlerService/src/EventHandlerService/Dockerfile --tag ghcr.io/nmshd/backbone-event-handler:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./EventHandlerService/src/EventHandlerService/Dockerfile --tag ghcr.io/nmshd/backbone-event-handler:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/fsc/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile --tag ghcr.io/nmshd/backbone-files-sanity-check:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile --tag ghcr.io/nmshd/backbone-files-sanity-check:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/idj/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./Jobs/src/Job.IdentityDeletion/Dockerfile --tag ghcr.io/nmshd/backbone-identity-deletion-jobs:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./Jobs/src/Job.IdentityDeletion/Dockerfile --tag ghcr.io/nmshd/backbone-identity-deletion-jobs:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
2 changes: 1 addition & 1 deletion .ci/sc/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const projectSuffix = $.env["PROJECT_SUFFIX"] ? `.${$.env["PROJECT_SUFFIX"]}` :

const moduleNameCamelCase = toCamelCase(moduleName);

await $`docker build --file ./Modules/${moduleName}/src/${moduleName}.Jobs.SanityCheck${projectSuffix}/Dockerfile --tag ghcr.io/nmshd/backbone-${moduleNameCamelCase}-sanity-check:${tag} .`;
await $`docker build --file ./Modules/${moduleName}/src/${moduleName}.Jobs.SanityCheck${projectSuffix}/Dockerfile --tag ghcr.io/nmshd/backbone-${moduleNameCamelCase}-sanity-check:${tag} --build-arg VERSION=${tag} .`;
2 changes: 1 addition & 1 deletion .ci/sses/buildContainerImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const tag = getRequiredEnvVar("TAG");
const platforms = process.env.PLATFORMS ?? "linux/amd64,linux/arm64";
const push = process.env.PUSH === "1" ? ["--push", "--provenance=true", "--sbom=true"] : "";

await $`docker buildx build --file ./SseServer/src/SseServer/Dockerfile --tag ghcr.io/nmshd/backbone-sse-server:${tag} --platform ${platforms} ${push} .`;
await $`docker buildx build --file ./SseServer/src/SseServer/Dockerfile --tag ghcr.io/nmshd/backbone-sse-server:${tag} --platform ${platforms} --build-arg VERSION=${tag} ${push} .`;
4 changes: 3 additions & 1 deletion AdminApi/src/AdminApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (see https://github.com/dotnet/dotnet-docker/discussions/4527).
# They are copied from https://github.com/ubuntu-rocks/dotnet/issues/21
################################################################################################################
FROM golang:1.22 as chisel
FROM golang:1.22 AS chisel

RUN git clone --depth 1 -b main https://github.com/canonical/chisel /opt/chisel
WORKDIR /opt/chisel
Expand Down Expand Up @@ -92,6 +92,8 @@ RUN dotnet restore "AdminApi/src/AdminApi/AdminApi.csproj"

COPY . .

ARG VERSION

RUN dotnet publish /p:UseAppHost=false --no-restore --configuration Release --output /app/publish "/src/AdminApi/src/AdminApi/AdminApi.csproj"
RUN dotnet publish --configuration Release --output /app/publish/health "HealthCheck/HealthCheck.csproj"

Expand Down
22 changes: 11 additions & 11 deletions ConsumerApi/ConsumerApi.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<UserSecretsId>f114fba8-95dd-4fee-8385-af8e8a343c68</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2"/>
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.2" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.22.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6"/>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1"/>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="ReHackt.Extensions.Options.Validation" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
<PackageReference Include="Serilog" Version="4.0.0"/>
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.0.3" />
<PackageReference Include="Serilog.Enrichers.Demystifier" Version="1.0.2" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1"/>
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Exceptions.EntityFrameworkCore" Version="8.4.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0"/>
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Http" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0"/>
<PackageReference Include="Serilog.Sinks.Seq" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions ConsumerApi/Controllers/VersionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Backbone.ConsumerApi.Controllers;

[Route("api/v1/[controller]")]
public class VersionController : ControllerBase
{
private readonly VersionService _versionService;

public VersionController(VersionService versionService)
{
_versionService = versionService;
}

[HttpGet]
[AllowAnonymous]
[ProducesResponseType(typeof(VersionResponse), StatusCodes.Status200OK)]
public async Task<IActionResult> GetBackboneMajorVersion(CancellationToken cancellationToken)
{
var majorVersion = await _versionService.GetBackboneMajorVersion();
return Ok(new VersionResponse { MajorVersion = majorVersion });
}
}

public class VersionResponse
{
public required string MajorVersion { get; set; }
}
4 changes: 3 additions & 1 deletion ConsumerApi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (see https://github.com/dotnet/dotnet-docker/discussions/4527).
# They are copied from https://github.com/ubuntu-rocks/dotnet/issues/21
################################################################################################################
FROM golang:1.22 as chisel
FROM golang:1.22 AS chisel

RUN git clone --depth 1 -b main https://github.com/canonical/chisel /opt/chisel
WORKDIR /opt/chisel
Expand Down Expand Up @@ -53,6 +53,8 @@ RUN mkdir /rootfs \
WORKDIR /src
COPY . .

ARG VERSION

RUN dotnet restore "ConsumerApi/ConsumerApi.csproj"
RUN dotnet publish --configuration Release --output /app/publish --no-restore "ConsumerApi/ConsumerApi.csproj"
RUN dotnet publish --configuration Release --output /app/publish/health "HealthCheck/HealthCheck.csproj"
Expand Down
2 changes: 2 additions & 0 deletions ConsumerApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config
var parsedConfiguration = services.BuildServiceProvider().GetRequiredService<IOptions<BackboneConfiguration>>().Value;
#pragma warning restore ASP0000

services.AddSingleton<VersionService>();

services.AddSaveChangesTimeInterceptor();

services.AddTransient<DevicesDbContextSeeder>();
Expand Down
17 changes: 17 additions & 0 deletions ConsumerApi/VersionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Backbone.ConsumerApi;

public class VersionService
{
public async Task<string> GetBackboneMajorVersion()
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var version = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion;

if (string.IsNullOrEmpty(version))
throw new InvalidOperationException("The file version information could not be retrieved.");

var majorVersion = version.Split('.', 2)[0];

return await Task.FromResult(majorVersion);
}
}
2 changes: 2 additions & 0 deletions DatabaseMigrator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ RUN dotnet restore "DatabaseMigrator/DatabaseMigrator.csproj"

COPY . .

ARG VERSION

WORKDIR "/src/DatabaseMigrator"
RUN dotnet build "DatabaseMigrator.csproj" -c Release --output /app/build --no-restore

Expand Down
2 changes: 2 additions & 0 deletions EventHandlerService/src/EventHandlerService/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ RUN dotnet restore "EventHandlerService/src/EventHandlerService/EventHandlerServ

COPY . .

ARG VERSION

WORKDIR "/src/EventHandlerService/src/EventHandlerService"
RUN dotnet build "EventHandlerService.csproj" -c Release -o /app/build --no-restore

Expand Down
2 changes: 2 additions & 0 deletions Jobs/src/Job.IdentityDeletion/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ RUN dotnet restore "Jobs/src/Job.IdentityDeletion/Job.IdentityDeletion.csproj"

COPY . .

ARG VERSION

WORKDIR "/src/Jobs/src/Job.IdentityDeletion"
RUN dotnet build "Job.IdentityDeletion.csproj" -c Release --output /app/build --no-restore

Expand Down
3 changes: 3 additions & 0 deletions Modules/Challenges/src/Challenges.Jobs.Cleanup/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /src

ARG VERSION

COPY . .
RUN dotnet restore "Challenges.Jobs.Cleanup/Challenges.Jobs.Cleanup.csproj"

Expand Down
2 changes: 2 additions & 0 deletions Modules/Devices/src/Devices.AdminCli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ RUN dotnet restore "Modules/Devices/src/Devices.AdminCli/Devices.AdminCli.csproj

COPY . .

ARG VERSION

WORKDIR "/src/Modules/Devices/src/Devices.AdminCli"
RUN dotnet publish --no-restore -c Release -o /app/publish "Devices.AdminCli.csproj"

Expand Down
2 changes: 2 additions & 0 deletions Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ RUN dotnet restore "Modules/Files/src/Files.Jobs.SanityCheck/Files.Jobs.SanityCh

COPY . .

ARG VERSION

WORKDIR "/src/Modules/Files/src/Files.Jobs.SanityCheck"
RUN dotnet build "Files.Jobs.SanityCheck.csproj" --configuration Release --output /app/build --no-restore

Expand Down
4 changes: 3 additions & 1 deletion SseServer/src/SseServer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (see https://github.com/dotnet/dotnet-docker/discussions/4527).
# They are copied from https://github.com/ubuntu-rocks/dotnet/issues/21
################################################################################################################
FROM golang:1.22 as chisel
FROM golang:1.22 AS chisel

RUN git clone --depth 1 -b main https://github.com/canonical/chisel /opt/chisel
WORKDIR /opt/chisel
Expand Down Expand Up @@ -53,6 +53,8 @@ RUN mkdir /rootfs \
WORKDIR /src
COPY . .

ARG VERSION

RUN dotnet restore "SseServer/src/SseServer/SseServer.csproj"
RUN dotnet publish --configuration Release --output /app/publish --no-restore "SseServer/src/SseServer/SseServer.csproj"
RUN dotnet publish --configuration Release --output /app/publish/health "HealthCheck/HealthCheck.csproj"
Expand Down

0 comments on commit cd92fba

Please sign in to comment.