Skip to content

Commit

Permalink
Add stamped version to docker releases
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch-b committed Jan 12, 2025
1 parent 4d493f3 commit 5393289
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get the current date and time
id: date
run: echo "::set-output name=date::$(date +'%Y.%m')"

- name: Get the short SHA
id: git_sha
run: echo "::set-output name=sha::$(git rev-parse --short HEAD)"

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand All @@ -46,7 +54,7 @@ jobs:
images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.WEB_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=sha,format=short
type=sha,format=short,enable={{is_default_branch}}
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value={{date 'YYYY'}}{{date 'MM'}},enable={{is_default_branch}}
Expand All @@ -61,4 +69,7 @@ jobs:
tags: ${{ steps.meta-web.outputs.tags }}
labels: ${{ steps.meta-web.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max
build-args: |
BUILD_VERSION=${{ steps.date.outputs.date }}
GIT_SHA=${{ steps.git_sha.outputs.sha }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public record OpenWishSettings
{
public EmailConfigSettings? EmailConfig { get; set; } = null!;
public OpenAISettings? OpenAI { get; set; } = null!;
public string? AppVersion { get; set; } = null!;
public string? BaseUri { get; set; } = null!;
public bool OwnDatabaseUpgrades { get; set; }
}
3 changes: 3 additions & 0 deletions src/OpenWish.Shared/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenWish.Shared.Services;

namespace OpenWish.Shared.Extensions;

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddOpenWishSharedServices(this IServiceCollection services, IConfiguration configuration)
{
services.TryAddSingleton<IAppVersionService>(new AppVersionService(configuration["APP_VERSION"] ?? $"{DateTimeOffset.UtcNow.ToLocalTime():yyyy.MM.dd.HHmm}"));
return services;
}
}
14 changes: 14 additions & 0 deletions src/OpenWish.Shared/Services/AppVersionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace OpenWish.Shared.Services;

public interface IAppVersionService
{
string GetAppVersion();
}

public class AppVersionService(string versionNumber) : IAppVersionService
{
public string GetAppVersion()
{
return versionNumber;
}
}
7 changes: 7 additions & 0 deletions src/OpenWish.Web/Components/Layout/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

@inject NavigationManager NavigationManager
@inject IBaseUriService BaseUriService
@inject IAppVersionService AppVersionService

<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
Expand Down Expand Up @@ -66,6 +67,12 @@
</div>
</NotAuthorized>
</AuthorizeView>

<div class="nav-item px-3">
<p class="nav-link">
<span>@AppVersionService.GetAppVersion()</span>
</p>
</div>
</nav>
</div>

Expand Down
11 changes: 11 additions & 0 deletions src/OpenWish.Web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
ARG TARGETPLATFORM
ARG TARGETARCH
ARG BUILD_CONFIGURATION=Release
ARG BUILD_VERSION=UNKNOWN
ARG GIT_SHA=UNKNOWN

WORKDIR /src

Expand All @@ -36,7 +38,16 @@ RUN dotnet publish "OpenWish.Web/OpenWish.Web.csproj" \
--arch $TARGETARCH
# --self-contained false



RUN echo "${BUILD_VERSION}.${GIT_SHA}" > /app/version.txt

FROM base AS final
WORKDIR /app
COPY --from=build /app/publish .
COPY --from=build /app/version.txt .

# Set the environment variable for the version number
ENV APP_VERSION=$(cat /app/version.txt)

ENTRYPOINT ["dotnet", "OpenWish.Web.dll"]

0 comments on commit 5393289

Please sign in to comment.