Skip to content

Commit 602acfd

Browse files
authored
F2calv/2024 05 env var updates (#39)
* GIT_REPO -> GIT_REPOSITORY * tidy * add env vars
1 parent 74592c3 commit 602acfd

File tree

9 files changed

+48
-36
lines changed

9 files changed

+48
-36
lines changed

.scripts/Invoke-Setup.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ $ErrorActionPreference = "Stop"
1111
$IMAGE_NAME = "multi-arch-container-dotnet"
1212
$REPOSITORY = "$DOCKERHUB_USERNAME/$IMAGE_NAME"
1313
$REPO_ROOT = git rev-parse --show-toplevel
14-
$GIT_REPO = $REPO_ROOT | Split-Path -Leaf
15-
$GIT_TAG = "latest-dev"
14+
$GIT_REPOSITORY = $REPO_ROOT | Split-Path -Leaf
1615
$GIT_BRANCH = $(git branch --show-current)
1716
$GIT_COMMIT = $(git rev-parse HEAD)
17+
$GIT_TAG = "latest-dev"
1818
$GITHUB_WORKFLOW = "n/a"
1919
$GITHUB_RUN_ID = 0
2020
$GITHUB_RUN_NUMBER = 0

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
1818
WORKDIR /app
1919
COPY --from=build /app/publish .
2020

21-
ARG GIT_REPO
22-
ENV GIT_REPO=$GIT_REPO
23-
ARG GIT_TAG
24-
ENV GIT_TAG=$GIT_TAG
21+
ARG GIT_REPOSITORY
22+
ENV GIT_REPOSITORY=$GIT_REPOSITORY
2523
ARG GIT_BRANCH
2624
ENV GIT_BRANCH=$GIT_BRANCH
2725
ARG GIT_COMMIT
2826
ENV GIT_COMMIT=$GIT_COMMIT
27+
ARG GIT_TAG
28+
ENV GIT_TAG=$GIT_TAG
2929

3030
ARG GITHUB_WORKFLOW=n/a
3131
ENV GITHUB_WORKFLOW=$GITHUB_WORKFLOW

Dockerfile.singlearch

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
99
WORKDIR /app
1010
COPY --from=build /app/publish .
1111

12-
ARG GIT_REPO
13-
ENV GIT_REPO=$GIT_REPO
14-
ARG GIT_TAG
15-
ENV GIT_TAG=$GIT_TAG
12+
ARG GIT_REPOSITORY
13+
ENV GIT_REPOSITORY=$GIT_REPOSITORY
1614
ARG GIT_BRANCH
1715
ENV GIT_BRANCH=$GIT_BRANCH
1816
ARG GIT_COMMIT
1917
ENV GIT_COMMIT=$GIT_COMMIT
18+
ARG GIT_TAG
19+
ENV GIT_TAG=$GIT_TAG
2020

2121
ARG GITHUB_WORKFLOW
2222
ENV GITHUB_WORKFLOW=$GITHUB_WORKFLOW

README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ First clone the repository (ideally by opening it as [vscode devcontainer](https
7272
#!/bin/sh
7373

7474
#set variables to emulate running in the workflow/pipeline
75-
GIT_REPO=$(basename `git rev-parse --show-toplevel`)
75+
GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`)
7676
GIT_BRANCH=$(git branch --show-current)
7777
GIT_COMMIT=$(git rev-parse HEAD)
7878
GIT_TAG="latest-dev"
@@ -92,13 +92,12 @@ docker buildx create --name multiarchcontainerdotnet --use
9292
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md
9393
docker buildx build \
9494
-t $IMAGE_NAME \
95-
-t "$GIT_REPO:latest" \
9695
--label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
9796
--label "IMAGE_NAME=$IMAGE_NAME" \
98-
--build-arg GIT_REPO=$GIT_REPO \
99-
--build-arg GIT_TAG=$GIT_TAG \
97+
--build-arg GIT_REPOSITORY=$GIT_REPOSITORY \
10098
--build-arg GIT_BRANCH=$GIT_BRANCH \
10199
--build-arg GIT_COMMIT=$GIT_COMMIT \
100+
--build-arg GIT_TAG=$GIT_TAG \
102101
--build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \
103102
--build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \
104103
--build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
@@ -109,13 +108,13 @@ docker buildx build \
109108

110109
#Preview matching images
111110
#https://docs.docker.com/engine/reference/commandline/images/
112-
docker images $GIT_REPO
111+
docker images $GIT_REPOSITORY
113112

114113
read -p "Hit ENTER to run the '$IMAGE_NAME' image..."
115114

116115
#Run the multi-architecture container image
117116
#https://docs.docker.com/engine/reference/commandline/run/
118-
docker run --rm -it --name $GIT_REPO $IMAGE_NAME
117+
docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME
119118

120119
#userprofile=$(wslpath "$(wslvar USERPROFILE)")
121120
#export KUBECONFIG=$userprofile/.kube/config

build.ps1

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ $ErrorActionPreference = "Stop"
33

44
#set variables to emulate running in the workflow/pipeline
55
$REPO_ROOT = git rev-parse --show-toplevel
6-
$GIT_REPO = $REPO_ROOT | Split-Path -Leaf
7-
$GIT_TAG = "latest-dev"
6+
$GIT_REPOSITORY = $REPO_ROOT | Split-Path -Leaf
87
$GIT_BRANCH = $(git branch --show-current)
98
$GIT_COMMIT = $(git rev-parse HEAD)
9+
$GIT_TAG = "latest-dev"
1010
$GITHUB_WORKFLOW = "n/a"
1111
$GITHUB_RUN_ID = 0
1212
$GITHUB_RUN_NUMBER = 0
13-
$IMAGE_NAME = "$($GIT_REPO):$($GIT_TAG)"
13+
$IMAGE_NAME = "$($GIT_REPOSITORY):$($GIT_TAG)"
1414
#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.
1515
#$PLATFORM = "linux/amd64,linux/arm64,linux/arm/v7"
1616
$PLATFORM = "linux/amd64"
@@ -23,11 +23,10 @@ docker buildx create --name multiarchcontainerdotnet --use
2323
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md
2424
docker buildx build `
2525
-t $IMAGE_NAME `
26-
-t "$($GIT_REPO):latest" `
27-
--build-arg GIT_REPO=$GIT_REPO `
28-
--build-arg GIT_TAG=$GIT_TAG `
26+
--build-arg GIT_REPOSITORY=$GIT_REPOSITORY `
2927
--build-arg GIT_BRANCH=$GIT_BRANCH `
3028
--build-arg GIT_COMMIT=$GIT_COMMIT `
29+
--build-arg GIT_TAG=$GIT_TAG `
3130
--build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW `
3231
--build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID `
3332
--build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER `
@@ -38,13 +37,13 @@ docker buildx build `
3837

3938
#Preview matching images
4039
#https://docs.docker.com/engine/reference/commandline/images/
41-
docker images $GIT_REPO
40+
docker images $GIT_REPOSITORY
4241

4342
Write-Host "Hit ENTER to run the '$IMAGE_NAME' image..."
4443
pause
4544

4645
#Run the multi-architecture container image
4746
#https://docs.docker.com/engine/reference/commandline/run/
48-
docker run --rm -it --name $GIT_REPO $IMAGE_NAME
47+
docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME
4948

5049
#kubectl run -i --tty --attach multi-arch-container-dotnet --image=ghcr.io/f2calv/multi-arch-container-dotnet --image-pull-policy='Always'

build.sh

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/sh
22

33
#set variables to emulate running in the workflow/pipeline
4-
GIT_REPO=$(basename `git rev-parse --show-toplevel`)
4+
GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`)
55
GIT_BRANCH=$(git branch --show-current)
66
GIT_COMMIT=$(git rev-parse HEAD)
77
GIT_TAG="latest-dev"
88
GITHUB_WORKFLOW="n/a"
99
GITHUB_RUN_ID=0
1010
GITHUB_RUN_NUMBER=0
11-
IMAGE_NAME="$GIT_REPO:$GIT_TAG"
11+
IMAGE_NAME="$GIT_REPOSITORY:$GIT_TAG"
1212
#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.
1313
#$PLATFORM="linux/amd64,linux/arm64,linux/arm/v7"
1414
PLATFORM="linux/amd64"
@@ -21,13 +21,12 @@ docker buildx create --name multiarchcontainerdotnet --use
2121
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md
2222
docker buildx build \
2323
-t $IMAGE_NAME \
24-
-t "$GIT_REPO:latest" \
2524
--label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
2625
--label "IMAGE_NAME=$IMAGE_NAME" \
27-
--build-arg GIT_REPO=$GIT_REPO \
28-
--build-arg GIT_TAG=$GIT_TAG \
26+
--build-arg GIT_REPOSITORY=$GIT_REPOSITORY \
2927
--build-arg GIT_BRANCH=$GIT_BRANCH \
3028
--build-arg GIT_COMMIT=$GIT_COMMIT \
29+
--build-arg GIT_TAG=$GIT_TAG \
3130
--build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \
3231
--build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \
3332
--build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
@@ -38,13 +37,13 @@ docker buildx build \
3837

3938
#Preview matching images
4039
#https://docs.docker.com/engine/reference/commandline/images/
41-
docker images $GIT_REPO
40+
docker images $GIT_REPOSITORY
4241

4342
read -p "Hit ENTER to run the '$IMAGE_NAME' image..."
4443

4544
#Run the multi-architecture container image
4645
#https://docs.docker.com/engine/reference/commandline/run/
47-
docker run --rm -it --name $GIT_REPO $IMAGE_NAME
46+
docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME
4847

4948
#userprofile=$(wslpath "$(wslvar USERPROFILE)")
5049
#export KUBECONFIG=$userprofile/.kube/config

charts/multi-arch-container-dotnet/templates/deployment.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ spec:
4040
- name: http
4141
containerPort: {{ .Values.service.port }}
4242
protocol: TCP
43+
env:
44+
- name: "GIT_REPOSITORY"
45+
value: {{ .Values.git.repository | default "" | quote }}
46+
- name: "GIT_BRANCH"
47+
value: {{ .Values.git.branch | default "" | quote }}
48+
- name: "GIT_COMMIT"
49+
value: {{ .Values.git.commit | default "" | quote }}
50+
- name: "GIT_TAG"
51+
value: {{ .Values.image.tag | default .Chart.AppVersion }}
52+
- name: "GITHUB_WORKFLOW"
53+
value: {{ .Values.github.workflow | default "" | quote }}
54+
- name: "GITHUB_RUN_ID"
55+
value: {{ .Values.github.run_id | int64 | default 0 | quote }}
56+
- name: "GITHUB_RUN_NUMBER"
57+
value: {{ .Values.github.run_number | int64 | default 0 | quote }}
4358
livenessProbe:
4459
{{- toYaml .Values.livenessProbe | nindent 12 }}
4560
readinessProbe:

src/multi-arch-container-dotnet/Program.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
Log.Information("App '{appName}' on [Process Architecture: {arch}, OSArchitecture: {osArch}, OSDescription: {os}].",
1717
AppDomain.CurrentDomain.FriendlyName, RuntimeInformation.ProcessArchitecture, RuntimeInformation.OSArchitecture, RuntimeInformation.OSDescription);
1818

19-
Log.Information("Git information; name '{GIT_REPO}', branch '{GIT_BRANCH}', commit '{GIT_COMMIT}', tag '{GIT_TAG}'",
20-
appSettings.GIT_REPO, appSettings.GIT_BRANCH, appSettings.GIT_COMMIT, appSettings.GIT_TAG);
19+
Log.Information("Git information; name '{GIT_REPOSITORY}', branch '{GIT_BRANCH}', commit '{GIT_COMMIT}', tag '{GIT_TAG}'",
20+
appSettings.GIT_REPOSITORY, appSettings.GIT_BRANCH, appSettings.GIT_COMMIT, appSettings.GIT_TAG);
2121

2222
Log.Information("GitHub information; workflow '{GITHUB_WORKFLOW}', run id '{GITHUB_RUN_ID}', run number '{GITHUB_RUN_NUMBER}'",
2323
appSettings.GITHUB_WORKFLOW, appSettings.GITHUB_RUN_ID, appSettings.GITHUB_RUN_NUMBER);
@@ -29,15 +29,15 @@ public class AppSettings
2929
{
3030
public AppSettings()
3131
{
32-
GIT_REPO = Environment.GetEnvironmentVariable(nameof(GIT_REPO)) ?? "n/a";
32+
GIT_REPOSITORY = Environment.GetEnvironmentVariable(nameof(GIT_REPOSITORY)) ?? "n/a";
3333
GIT_BRANCH = Environment.GetEnvironmentVariable(nameof(GIT_BRANCH)) ?? "n/a";
3434
GIT_COMMIT = Environment.GetEnvironmentVariable(nameof(GIT_COMMIT)) ?? "n/a";
3535
GIT_TAG = Environment.GetEnvironmentVariable(nameof(GIT_TAG)) ?? "n/a";
3636
GITHUB_WORKFLOW = Environment.GetEnvironmentVariable(nameof(GITHUB_WORKFLOW)) ?? "n/a";
3737
GITHUB_RUN_ID = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_ID)) ?? "n/a";
3838
GITHUB_RUN_NUMBER = Environment.GetEnvironmentVariable(nameof(GITHUB_RUN_NUMBER)) ?? "n/a";
3939
}
40-
public string? GIT_REPO { get; }
40+
public string? GIT_REPOSITORY { get; }
4141
public string? GIT_BRANCH { get; }
4242
public string? GIT_COMMIT { get; }
4343
public string? GIT_TAG { get; }

src/multi-arch-container-dotnet/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"multi-arch-container-dotnet": {
44
"commandName": "Project",
55
"environmentVariables": {
6-
"GIT_REPO": "multi-arch-container-dotnet"
6+
"GIT_REPOSITORY": "multi-arch-container-dotnet"
77
}
88
}
99
}

0 commit comments

Comments
 (0)