Skip to content

Commit

Permalink
F2calv/2024 05 env var updates (#39)
Browse files Browse the repository at this point in the history
* GIT_REPO -> GIT_REPOSITORY

* tidy

* add env vars
  • Loading branch information
f2calv authored May 23, 2024
1 parent 74592c3 commit 602acfd
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .scripts/Invoke-Setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile.singlearch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 \
Expand All @@ -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
Expand Down
15 changes: 7 additions & 8 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 `
Expand All @@ -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'
13 changes: 6 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 \
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions charts/multi-arch-container-dotnet/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/multi-arch-container-dotnet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,15 +29,15 @@ 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";
GITHUB_WORKFLOW = Environment.GetEnvironmentVariable(nameof(GITHUB_WORKFLOW)) ?? "n/a";
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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"multi-arch-container-dotnet": {
"commandName": "Project",
"environmentVariables": {
"GIT_REPO": "multi-arch-container-dotnet"
"GIT_REPOSITORY": "multi-arch-container-dotnet"
}
}
}
Expand Down

0 comments on commit 602acfd

Please sign in to comment.