diff --git a/.ci/acli/buildContainerImage.js b/.ci/acli/buildContainerImage.js index ac6bbe00cc..a3b6d250d3 100755 --- a/.ci/acli/buildContainerImage.js +++ b/.ci/acli/buildContainerImage.js @@ -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} .`; diff --git a/.ci/aui/buildContainerImage.js b/.ci/aui/buildContainerImage.js index b5c8bf2097..0ddf6b5a2d 100755 --- a/.ci/aui/buildContainerImage.js +++ b/.ci/aui/buildContainerImage.js @@ -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} .`; diff --git a/.ci/capi/buildContainerImage.js b/.ci/capi/buildContainerImage.js index fd2e1cf8eb..ec58f122c3 100755 --- a/.ci/capi/buildContainerImage.js +++ b/.ci/capi/buildContainerImage.js @@ -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} .`; diff --git a/.ci/dbm/buildContainerImage.js b/.ci/dbm/buildContainerImage.js index f962b2ba8f..7595a119a2 100755 --- a/.ci/dbm/buildContainerImage.js +++ b/.ci/dbm/buildContainerImage.js @@ -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} .`; diff --git a/.ci/eh/buildContainerImage.js b/.ci/eh/buildContainerImage.js index 24a74c0ae4..c871b7a7c9 100755 --- a/.ci/eh/buildContainerImage.js +++ b/.ci/eh/buildContainerImage.js @@ -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} .`; diff --git a/.ci/fsc/buildContainerImage.js b/.ci/fsc/buildContainerImage.js index b6649f033d..1f87ebb582 100755 --- a/.ci/fsc/buildContainerImage.js +++ b/.ci/fsc/buildContainerImage.js @@ -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} .`; diff --git a/.ci/idj/buildContainerImage.js b/.ci/idj/buildContainerImage.js index 1a5d297228..53b93f2ee1 100755 --- a/.ci/idj/buildContainerImage.js +++ b/.ci/idj/buildContainerImage.js @@ -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} .`; diff --git a/.ci/sc/buildContainerImage.js b/.ci/sc/buildContainerImage.js index c8baad6ef5..d34b868a82 100755 --- a/.ci/sc/buildContainerImage.js +++ b/.ci/sc/buildContainerImage.js @@ -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} .`; diff --git a/.ci/sses/buildContainerImage.js b/.ci/sses/buildContainerImage.js index 451c86f5f8..09acb431cd 100755 --- a/.ci/sses/buildContainerImage.js +++ b/.ci/sses/buildContainerImage.js @@ -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} .`; diff --git a/AdminApi/src/AdminApi/Dockerfile b/AdminApi/src/AdminApi/Dockerfile index 85d483cb4c..62e60b3f87 100644 --- a/AdminApi/src/AdminApi/Dockerfile +++ b/AdminApi/src/AdminApi/Dockerfile @@ -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 @@ -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" diff --git a/ConsumerApi/ConsumerApi.csproj b/ConsumerApi/ConsumerApi.csproj index dca1b7e851..d9a8ae9d8f 100644 --- a/ConsumerApi/ConsumerApi.csproj +++ b/ConsumerApi/ConsumerApi.csproj @@ -1,35 +1,35 @@ - + f114fba8-95dd-4fee-8385-af8e8a343c68 - + - + - - + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive true - + - + - + - + diff --git a/ConsumerApi/Controllers/VersionController.cs b/ConsumerApi/Controllers/VersionController.cs new file mode 100644 index 0000000000..6209cfe038 --- /dev/null +++ b/ConsumerApi/Controllers/VersionController.cs @@ -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 GetBackboneMajorVersion(CancellationToken cancellationToken) + { + var majorVersion = await _versionService.GetBackboneMajorVersion(); + return Ok(new VersionResponse { MajorVersion = majorVersion }); + } +} + +public class VersionResponse +{ + public required string MajorVersion { get; set; } +} diff --git a/ConsumerApi/Dockerfile b/ConsumerApi/Dockerfile index 0b1d69673f..dcedd262f5 100644 --- a/ConsumerApi/Dockerfile +++ b/ConsumerApi/Dockerfile @@ -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 @@ -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" diff --git a/ConsumerApi/Program.cs b/ConsumerApi/Program.cs index 07c93fe6a0..d72d151eb1 100644 --- a/ConsumerApi/Program.cs +++ b/ConsumerApi/Program.cs @@ -132,6 +132,8 @@ static void ConfigureServices(IServiceCollection services, IConfiguration config var parsedConfiguration = services.BuildServiceProvider().GetRequiredService>().Value; #pragma warning restore ASP0000 + services.AddSingleton(); + services.AddSaveChangesTimeInterceptor(); services.AddTransient(); diff --git a/ConsumerApi/VersionService.cs b/ConsumerApi/VersionService.cs new file mode 100644 index 0000000000..82ebf925a1 --- /dev/null +++ b/ConsumerApi/VersionService.cs @@ -0,0 +1,17 @@ +namespace Backbone.ConsumerApi; + +public class VersionService +{ + public async Task 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); + } +} diff --git a/DatabaseMigrator/Dockerfile b/DatabaseMigrator/Dockerfile index a238fe3f98..eef5e1c4c0 100644 --- a/DatabaseMigrator/Dockerfile +++ b/DatabaseMigrator/Dockerfile @@ -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 diff --git a/EventHandlerService/src/EventHandlerService/Dockerfile b/EventHandlerService/src/EventHandlerService/Dockerfile index 0251c884d5..55c21828ce 100644 --- a/EventHandlerService/src/EventHandlerService/Dockerfile +++ b/EventHandlerService/src/EventHandlerService/Dockerfile @@ -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 diff --git a/Jobs/src/Job.IdentityDeletion/Dockerfile b/Jobs/src/Job.IdentityDeletion/Dockerfile index 79929f117c..c1e8498575 100644 --- a/Jobs/src/Job.IdentityDeletion/Dockerfile +++ b/Jobs/src/Job.IdentityDeletion/Dockerfile @@ -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 diff --git a/Modules/Challenges/src/Challenges.Jobs.Cleanup/Dockerfile b/Modules/Challenges/src/Challenges.Jobs.Cleanup/Dockerfile index 8cdaa4d3ef..b8fd8e4792 100644 --- a/Modules/Challenges/src/Challenges.Jobs.Cleanup/Dockerfile +++ b/Modules/Challenges/src/Challenges.Jobs.Cleanup/Dockerfile @@ -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" diff --git a/Modules/Devices/src/Devices.AdminCli/Dockerfile b/Modules/Devices/src/Devices.AdminCli/Dockerfile index 4f8a6ee45b..4ba061917a 100644 --- a/Modules/Devices/src/Devices.AdminCli/Dockerfile +++ b/Modules/Devices/src/Devices.AdminCli/Dockerfile @@ -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" diff --git a/Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile b/Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile index 3f58e56abc..ddea1b4f44 100644 --- a/Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile +++ b/Modules/Files/src/Files.Jobs.SanityCheck/Dockerfile @@ -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 diff --git a/SseServer/src/SseServer/Dockerfile b/SseServer/src/SseServer/Dockerfile index 75b793e3c6..08711f9140 100644 --- a/SseServer/src/SseServer/Dockerfile +++ b/SseServer/src/SseServer/Dockerfile @@ -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 @@ -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"