Skip to content

Commit dc0c801

Browse files
authored
F2calv/2024 05 env var updates (#85)
* GIT_REPO -> GIT_REPOSITORY * tidy * revert * add env vars
1 parent 3657b1c commit dc0c801

File tree

6 files changed

+43
-31
lines changed

6 files changed

+43
-31
lines changed

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ fi \
7979
FROM gcr.io/distroless/cc AS final
8080
COPY --from=build /app/target/final/release/multi-arch-container-rust .
8181

82-
ARG GIT_REPO
83-
ENV APP_GIT_REPO=$GIT_REPO
84-
ARG GIT_TAG
85-
ENV APP_GIT_TAG=$GIT_TAG
82+
ARG GIT_REPOSITORY
83+
ENV APP_GIT_REPOSITORY=$GIT_REPOSITORY
8684
ARG GIT_BRANCH
8785
ENV APP_GIT_BRANCH=$GIT_BRANCH
8886
ARG GIT_COMMIT
8987
ENV APP_GIT_COMMIT=$GIT_COMMIT
88+
ARG GIT_TAG
89+
ENV APP_GIT_TAG=$GIT_TAG
9090

9191
ARG GITHUB_WORKFLOW
9292
ENV APP_GITHUB_WORKFLOW=$GITHUB_WORKFLOW

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ First clone the repository (ideally by opening it as [vscode devcontainer](https
6363
#!/bin/sh
6464

6565
#set variables to emulate running in the workflow/pipeline
66-
GIT_REPO=$(basename `git rev-parse --show-toplevel`)
66+
GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`)
6767
GIT_BRANCH=$(git branch --show-current)
6868
GIT_COMMIT=$(git rev-parse HEAD)
6969
GIT_TAG="latest-dev"
7070
GITHUB_WORKFLOW="n/a"
7171
GITHUB_RUN_ID=0
7272
GITHUB_RUN_NUMBER=0
73-
IMAGE_NAME="$GIT_REPO:$GIT_TAG"
73+
IMAGE_NAME="$GIT_REPOSITORY:$GIT_TAG"
7474
#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.
7575
#$PLATFORM="linux/amd64,linux/arm64,linux/arm/v7"
7676
PLATFORM="linux/amd64"
@@ -83,13 +83,12 @@ docker buildx create --name multiarchcontainerrust --use
8383
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md
8484
docker buildx build \
8585
-t $IMAGE_NAME \
86-
-t "$GIT_REPO:latest" \
8786
--label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
8887
--label "IMAGE_NAME=$IMAGE_NAME" \
89-
--build-arg GIT_REPO=$GIT_REPO \
90-
--build-arg GIT_TAG=$GIT_TAG \
88+
--build-arg GIT_REPOSITORY=$GIT_REPOSITORY \
9189
--build-arg GIT_BRANCH=$GIT_BRANCH \
9290
--build-arg GIT_COMMIT=$GIT_COMMIT \
91+
--build-arg GIT_TAG=$GIT_TAG \
9392
--build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \
9493
--build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \
9594
--build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
@@ -100,13 +99,13 @@ docker buildx build \
10099

101100
#Preview matching images
102101
#https://docs.docker.com/engine/reference/commandline/images/
103-
docker images $GIT_REPO
102+
docker images $GIT_REPOSITORY
104103

105104
read -p "Hit ENTER to run the '$IMAGE_NAME' image..."
106105

107106
#Run the multi-architecture container image
108107
#https://docs.docker.com/engine/reference/commandline/run/
109-
docker run --rm -it --name $GIT_REPO $IMAGE_NAME
108+
docker run --rm -it --name $GIT_REPOSITORY $IMAGE_NAME
110109

111110
#userprofile=$(wslpath "$(wslvar USERPROFILE)")
112111
#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 multiarchcontainerrust --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-rust --image=ghcr.io/f2calv/multi-arch-container-rust --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 multiarchcontainerrust --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-rust/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/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ async fn main() -> std::io::Result<()> {
3333
);
3434

3535
log::info!(
36-
"Git information; name '{:?}', branch '{:?}', commit '{:?}', tag '{:?}'",
37-
app_settings.git_repo,
36+
"Git information; repository '{:?}', branch '{:?}', commit '{:?}', tag '{:?}'",
37+
app_settings.git_repository,
3838
app_settings.git_branch,
3939
app_settings.git_commit,
4040
app_settings.git_tag,
@@ -66,7 +66,7 @@ fn get_configuration() -> Result<AppSettings, ConfigError> {
6666

6767
#[derive(Debug, serde::Deserialize)]
6868
struct AppSettings {
69-
git_repo: Option<String>,
69+
git_repository: Option<String>,
7070
git_branch: Option<String>,
7171
git_commit: Option<String>,
7272
git_tag: Option<String>,
@@ -79,8 +79,8 @@ impl std::fmt::Display for AppSettings {
7979
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8080
write!(
8181
f,
82-
"git_repo='{:?}', git_branch='{:?}'",
83-
self.git_repo, self.git_branch
82+
"git_repository='{:?}', git_branch='{:?}'",
83+
self.git_repository, self.git_branch
8484
)
8585
}
8686
}

0 commit comments

Comments
 (0)