diff --git a/.scripts/Invoke-Setup.ps1 b/.scripts/Invoke-Setup.ps1 index 0764521..f9243fe 100644 --- a/.scripts/Invoke-Setup.ps1 +++ b/.scripts/Invoke-Setup.ps1 @@ -11,10 +11,10 @@ $ErrorActionPreference = "Stop" $IMAGE_NAME = "multi-arch-container-dotnet" $REPOSITORY = "$DOCKERHUB_USERNAME/$IMAGE_NAME" $REPO_ROOT = git rev-parse --show-toplevel -$GIT_REPO = $REPO_ROOT | Split-Path -Leaf -$GIT_TAG = "latest-dev" +$GIT_REPOSITORY = $REPO_ROOT | Split-Path -Leaf $GIT_BRANCH = $(git branch --show-current) $GIT_COMMIT = $(git rev-parse HEAD) +$GIT_TAG = "latest-dev" $GITHUB_WORKFLOW = "n/a" $GITHUB_RUN_ID = 0 $GITHUB_RUN_NUMBER = 0 diff --git a/Dockerfile b/Dockerfile index 1f77d2d..b4533a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,14 +18,14 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final WORKDIR /app COPY --from=build /app/publish . -ARG GIT_REPO -ENV GIT_REPO=$GIT_REPO -ARG GIT_TAG -ENV GIT_TAG=$GIT_TAG +ARG GIT_REPOSITORY +ENV GIT_REPOSITORY=$GIT_REPOSITORY ARG GIT_BRANCH ENV GIT_BRANCH=$GIT_BRANCH ARG GIT_COMMIT ENV GIT_COMMIT=$GIT_COMMIT +ARG GIT_TAG +ENV GIT_TAG=$GIT_TAG ARG GITHUB_WORKFLOW=n/a ENV GITHUB_WORKFLOW=$GITHUB_WORKFLOW diff --git a/Dockerfile.singlearch b/Dockerfile.singlearch index b7665d4..27d7b01 100644 --- a/Dockerfile.singlearch +++ b/Dockerfile.singlearch @@ -9,14 +9,14 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final WORKDIR /app COPY --from=build /app/publish . -ARG GIT_REPO -ENV GIT_REPO=$GIT_REPO -ARG GIT_TAG -ENV GIT_TAG=$GIT_TAG +ARG GIT_REPOSITORY +ENV GIT_REPOSITORY=$GIT_REPOSITORY ARG GIT_BRANCH ENV GIT_BRANCH=$GIT_BRANCH ARG GIT_COMMIT ENV GIT_COMMIT=$GIT_COMMIT +ARG GIT_TAG +ENV GIT_TAG=$GIT_TAG ARG GITHUB_WORKFLOW ENV GITHUB_WORKFLOW=$GITHUB_WORKFLOW diff --git a/README.md b/README.md index 8304d49..abfaa62 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ First clone the repository (ideally by opening it as [vscode devcontainer](https #!/bin/sh #set variables to emulate running in the workflow/pipeline -GIT_REPO=$(basename `git rev-parse --show-toplevel`) +GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`) GIT_BRANCH=$(git branch --show-current) GIT_COMMIT=$(git rev-parse HEAD) GIT_TAG="latest-dev" @@ -92,13 +92,12 @@ docker buildx create --name multiarchcontainerdotnet --use #https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md docker buildx build \ -t $IMAGE_NAME \ - -t "$GIT_REPO:latest" \ --label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \ --label "IMAGE_NAME=$IMAGE_NAME" \ - --build-arg GIT_REPO=$GIT_REPO \ - --build-arg GIT_TAG=$GIT_TAG \ + --build-arg GIT_REPOSITORY=$GIT_REPOSITORY \ --build-arg GIT_BRANCH=$GIT_BRANCH \ --build-arg GIT_COMMIT=$GIT_COMMIT \ + --build-arg GIT_TAG=$GIT_TAG \ --build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \ --build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \ --build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \ @@ -109,13 +108,13 @@ docker buildx build \ #Preview matching images #https://docs.docker.com/engine/reference/commandline/images/ -docker images $GIT_REPO +docker images $GIT_REPOSITORY read -p "Hit ENTER to run the '$IMAGE_NAME' image..." #Run the multi-architecture container image #https://docs.docker.com/engine/reference/commandline/run/ -docker run --rm -it --name $GIT_REPO $IMAGE_NAME +docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME #userprofile=$(wslpath "$(wslvar USERPROFILE)") #export KUBECONFIG=$userprofile/.kube/config diff --git a/build.ps1 b/build.ps1 index 287c769..30a8a68 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,14 +3,14 @@ $ErrorActionPreference = "Stop" #set variables to emulate running in the workflow/pipeline $REPO_ROOT = git rev-parse --show-toplevel -$GIT_REPO = $REPO_ROOT | Split-Path -Leaf -$GIT_TAG = "latest-dev" +$GIT_REPOSITORY = $REPO_ROOT | Split-Path -Leaf $GIT_BRANCH = $(git branch --show-current) $GIT_COMMIT = $(git rev-parse HEAD) +$GIT_TAG = "latest-dev" $GITHUB_WORKFLOW = "n/a" $GITHUB_RUN_ID = 0 $GITHUB_RUN_NUMBER = 0 -$IMAGE_NAME = "$($GIT_REPO):$($GIT_TAG)" +$IMAGE_NAME = "$($GIT_REPOSITORY):$($GIT_TAG)" #Note: you cannot export a buildx container image into a local docker instance with multiple architecture manifests so for local testing you have to select just a single architecture. #$PLATFORM = "linux/amd64,linux/arm64,linux/arm/v7" $PLATFORM = "linux/amd64" @@ -23,11 +23,10 @@ docker buildx create --name multiarchcontainerdotnet --use #https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md docker buildx build ` -t $IMAGE_NAME ` - -t "$($GIT_REPO):latest" ` - --build-arg GIT_REPO=$GIT_REPO ` - --build-arg GIT_TAG=$GIT_TAG ` + --build-arg GIT_REPOSITORY=$GIT_REPOSITORY ` --build-arg GIT_BRANCH=$GIT_BRANCH ` --build-arg GIT_COMMIT=$GIT_COMMIT ` + --build-arg GIT_TAG=$GIT_TAG ` --build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW ` --build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID ` --build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER ` @@ -38,13 +37,13 @@ docker buildx build ` #Preview matching images #https://docs.docker.com/engine/reference/commandline/images/ -docker images $GIT_REPO +docker images $GIT_REPOSITORY Write-Host "Hit ENTER to run the '$IMAGE_NAME' image..." pause #Run the multi-architecture container image #https://docs.docker.com/engine/reference/commandline/run/ -docker run --rm -it --name $GIT_REPO $IMAGE_NAME +docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME #kubectl run -i --tty --attach multi-arch-container-dotnet --image=ghcr.io/f2calv/multi-arch-container-dotnet --image-pull-policy='Always' \ No newline at end of file diff --git a/build.sh b/build.sh index d0e3e42..637d5e0 100644 --- a/build.sh +++ b/build.sh @@ -1,14 +1,14 @@ #!/bin/sh #set variables to emulate running in the workflow/pipeline -GIT_REPO=$(basename `git rev-parse --show-toplevel`) +GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`) GIT_BRANCH=$(git branch --show-current) GIT_COMMIT=$(git rev-parse HEAD) GIT_TAG="latest-dev" GITHUB_WORKFLOW="n/a" GITHUB_RUN_ID=0 GITHUB_RUN_NUMBER=0 -IMAGE_NAME="$GIT_REPO:$GIT_TAG" +IMAGE_NAME="$GIT_REPOSITORY:$GIT_TAG" #Note: you cannot export a buildx container image into a local docker instance with multiple architecture manifests so for local testing you have to select just a single architecture. #$PLATFORM="linux/amd64,linux/arm64,linux/arm/v7" PLATFORM="linux/amd64" @@ -21,13 +21,12 @@ docker buildx create --name multiarchcontainerdotnet --use #https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md docker buildx build \ -t $IMAGE_NAME \ - -t "$GIT_REPO:latest" \ --label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \ --label "IMAGE_NAME=$IMAGE_NAME" \ - --build-arg GIT_REPO=$GIT_REPO \ - --build-arg GIT_TAG=$GIT_TAG \ + --build-arg GIT_REPOSITORY=$GIT_REPOSITORY \ --build-arg GIT_BRANCH=$GIT_BRANCH \ --build-arg GIT_COMMIT=$GIT_COMMIT \ + --build-arg GIT_TAG=$GIT_TAG \ --build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \ --build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \ --build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \ @@ -38,13 +37,13 @@ docker buildx build \ #Preview matching images #https://docs.docker.com/engine/reference/commandline/images/ -docker images $GIT_REPO +docker images $GIT_REPOSITORY read -p "Hit ENTER to run the '$IMAGE_NAME' image..." #Run the multi-architecture container image #https://docs.docker.com/engine/reference/commandline/run/ -docker run --rm -it --name $GIT_REPO $IMAGE_NAME +docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME #userprofile=$(wslpath "$(wslvar USERPROFILE)") #export KUBECONFIG=$userprofile/.kube/config diff --git a/charts/multi-arch-container-dotnet/templates/deployment.yaml b/charts/multi-arch-container-dotnet/templates/deployment.yaml index e3b95e5..56419a6 100644 --- a/charts/multi-arch-container-dotnet/templates/deployment.yaml +++ b/charts/multi-arch-container-dotnet/templates/deployment.yaml @@ -40,6 +40,21 @@ spec: - name: http containerPort: {{ .Values.service.port }} protocol: TCP + env: + - name: "GIT_REPOSITORY" + value: {{ .Values.git.repository | default "" | quote }} + - name: "GIT_BRANCH" + value: {{ .Values.git.branch | default "" | quote }} + - name: "GIT_COMMIT" + value: {{ .Values.git.commit | default "" | quote }} + - name: "GIT_TAG" + value: {{ .Values.image.tag | default .Chart.AppVersion }} + - name: "GITHUB_WORKFLOW" + value: {{ .Values.github.workflow | default "" | quote }} + - name: "GITHUB_RUN_ID" + value: {{ .Values.github.run_id | int64 | default 0 | quote }} + - name: "GITHUB_RUN_NUMBER" + value: {{ .Values.github.run_number | int64 | default 0 | quote }} livenessProbe: {{- toYaml .Values.livenessProbe | nindent 12 }} readinessProbe: diff --git a/src/multi-arch-container-dotnet/Program.cs b/src/multi-arch-container-dotnet/Program.cs index a9bb0c8..64532d0 100644 --- a/src/multi-arch-container-dotnet/Program.cs +++ b/src/multi-arch-container-dotnet/Program.cs @@ -16,8 +16,8 @@ Log.Information("App '{appName}' on [Process Architecture: {arch}, OSArchitecture: {osArch}, OSDescription: {os}].", AppDomain.CurrentDomain.FriendlyName, RuntimeInformation.ProcessArchitecture, RuntimeInformation.OSArchitecture, RuntimeInformation.OSDescription); - Log.Information("Git information; name '{GIT_REPO}', branch '{GIT_BRANCH}', commit '{GIT_COMMIT}', tag '{GIT_TAG}'", - appSettings.GIT_REPO, appSettings.GIT_BRANCH, appSettings.GIT_COMMIT, appSettings.GIT_TAG); + Log.Information("Git information; name '{GIT_REPOSITORY}', branch '{GIT_BRANCH}', commit '{GIT_COMMIT}', tag '{GIT_TAG}'", + appSettings.GIT_REPOSITORY, appSettings.GIT_BRANCH, appSettings.GIT_COMMIT, appSettings.GIT_TAG); Log.Information("GitHub information; workflow '{GITHUB_WORKFLOW}', run id '{GITHUB_RUN_ID}', run number '{GITHUB_RUN_NUMBER}'", appSettings.GITHUB_WORKFLOW, appSettings.GITHUB_RUN_ID, appSettings.GITHUB_RUN_NUMBER); @@ -29,7 +29,7 @@ public class AppSettings { public AppSettings() { - GIT_REPO = Environment.GetEnvironmentVariable(nameof(GIT_REPO)) ?? "n/a"; + GIT_REPOSITORY = Environment.GetEnvironmentVariable(nameof(GIT_REPOSITORY)) ?? "n/a"; GIT_BRANCH = Environment.GetEnvironmentVariable(nameof(GIT_BRANCH)) ?? "n/a"; GIT_COMMIT = Environment.GetEnvironmentVariable(nameof(GIT_COMMIT)) ?? "n/a"; GIT_TAG = Environment.GetEnvironmentVariable(nameof(GIT_TAG)) ?? "n/a"; @@ -37,7 +37,7 @@ public AppSettings() GITHUB_RUN_ID = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_ID)) ?? "n/a"; GITHUB_RUN_NUMBER = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_NUMBER)) ?? "n/a"; } - public string? GIT_REPO { get; } + public string? GIT_REPOSITORY { get; } public string? GIT_BRANCH { get; } public string? GIT_COMMIT { get; } public string? GIT_TAG { get; } diff --git a/src/multi-arch-container-dotnet/Properties/launchSettings.json b/src/multi-arch-container-dotnet/Properties/launchSettings.json index a73d2e6..51ee5c8 100644 --- a/src/multi-arch-container-dotnet/Properties/launchSettings.json +++ b/src/multi-arch-container-dotnet/Properties/launchSettings.json @@ -3,7 +3,7 @@ "multi-arch-container-dotnet": { "commandName": "Project", "environmentVariables": { - "GIT_REPO": "multi-arch-container-dotnet" + "GIT_REPOSITORY": "multi-arch-container-dotnet" } } }