Skip to content

Commit

Permalink
feat: add the release tag into the container as env var and display i…
Browse files Browse the repository at this point in the history
…n the AppInfo json response

Merge pull request #242 from DFE-Digital/Feature/update-app-info
  • Loading branch information
killij authored Sep 1, 2023
2 parents c2ca209 + e39c576 commit c794a3c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 31 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
RELEASE_TAG: ${{ github.event.release.tag_name }}

jobs:
build:
Expand All @@ -29,10 +30,10 @@ jobs:

steps:
# Checkout the release tag version
- name: Checkout repository ${{ github.event.release.tag_name }}
- name: Checkout repository ${{ env.RELEASE_TAG }}
uses: actions/checkout@v3
with:
ref: ${{ github.event.release.tag_name }}
ref: ${{ env.RELEASE_TAG }}

# Get git commit hash
- name: Get short hash
Expand Down Expand Up @@ -80,9 +81,9 @@ jobs:
with:
context: Childrens-Social-Care-CPD
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{ github.event.release.tag_name }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{ env.RELEASE_TAG }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest
labels: ${{ steps.meta.outputs.labels }}
build-args: VCSREF=${{ env.sha_short }}
build-args: VCSREF=${{ env.sha_short }},VCSTAG=${{ env.RELEASE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,18 @@ public void AppInfo_Includes_Git_Hash()
// assert
actual.GitShortHash.Should().Be(value);
}

[Test]
public void AppInfo_Includes_App_Version()
{
// arrange
var value = "foo";
_applicationConfiguration.AppVersion.Returns(value);

// act
var actual = _controller.AppInfo().Value as ApplicationInfo;

// assert
actual.Version.Should().Be(value);
}
}
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class ApplicationConfiguration : IApplicationConfiguration
{
private static string ValueOrStringEmpty(string key) => Environment.GetEnvironmentVariable(key) ?? string.Empty;
public string AppInsightsConnectionString => ValueOrStringEmpty("CPD_INSTRUMENTATION_CONNECTIONSTRING");
public string AppVersion => ValueOrStringEmpty("VCS-TAG");
public string AzureEnvironment => ValueOrStringEmpty("CPD_AZURE_ENVIRONMENT");
public string ClarityProjectId => ValueOrStringEmpty("CPD_CLARITY");
public string ContentfulDeliveryApiKey => ValueOrStringEmpty("CPD_DELIVERY_KEY");
Expand Down
38 changes: 19 additions & 19 deletions Childrens-Social-Care-CPD/Controllers/AppInfoController.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
using Childrens_Social_Care_CPD.Models;
using Microsoft.AspNetCore.Mvc;

namespace Childrens_Social_Care_CPD.Controllers
namespace Childrens_Social_Care_CPD.Controllers;

public class AppInfoController : Controller
{
public class AppInfoController : Controller
{
private readonly IApplicationConfiguration _applicationConfiguration;
private readonly IApplicationConfiguration _applicationConfiguration;

public AppInfoController(IApplicationConfiguration applicationConfiguration)
{
_applicationConfiguration = applicationConfiguration;
}
public AppInfoController(IApplicationConfiguration applicationConfiguration)
{
_applicationConfiguration = applicationConfiguration;
}

[HttpGet]
[Route("CPD/AppInfo")]
public JsonResult AppInfo()
[HttpGet]
[Route("CPD/AppInfo")]
public JsonResult AppInfo()
{
var applicationInfo = new ApplicationInfo()
{
var applicationInfo = new ApplicationInfo()
{
Environment = _applicationConfiguration.AzureEnvironment,
ContentfulEnvironment = _applicationConfiguration.ContentfulEnvironment,
GitShortHash = _applicationConfiguration.GitHash
};
Environment = _applicationConfiguration.AzureEnvironment,
ContentfulEnvironment = _applicationConfiguration.ContentfulEnvironment,
GitShortHash = _applicationConfiguration.GitHash,
Version = _applicationConfiguration.AppVersion,
};

return Json(applicationInfo);
}
return Json(applicationInfo);
}
}
2 changes: 2 additions & 0 deletions Childrens-Social-Care-CPD/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ WORKDIR /app
COPY --from=publish /app/publish .
ARG VCSREF=0
ENV VCS-REF=$VCSREF
ARG VCSTAG=0.0.0
ENV VCS-TAG=$VCSTAG
ENTRYPOINT ["dotnet", "Childrens-Social-Care-CPD.dll"]
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/IApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public interface IApplicationConfiguration
{
string AppInsightsConnectionString { get; }
string AppVersion { get; }
string AzureEnvironment { get; }
string ClarityProjectId { get; }
string ContentfulDeliveryApiKey { get; }
Expand Down
14 changes: 6 additions & 8 deletions Childrens-Social-Care-CPD/Models/ApplicationInfo.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Newtonsoft.Json;
namespace Childrens_Social_Care_CPD.Models;

namespace Childrens_Social_Care_CPD.Models
public class ApplicationInfo
{
public class ApplicationInfo
{
public string Environment { get; set; }
public string ContentfulEnvironment { get; set; }
public string GitShortHash { get; set; }
}
public string ContentfulEnvironment { get; set; }
public string Environment { get; set; }
public string GitShortHash { get; set; }
public string Version { get; set; }
}

0 comments on commit c794a3c

Please sign in to comment.