Skip to content

Commit 69af61e

Browse files
authored
fix: pass commit hash from the cloud build default variable (#763)
TESTED with both local run of: - make image-push - cloud-build-local command
1 parent 2d2db35 commit 69af61e

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ FROM ${BUILDER_IMAGE} AS builder
88
ENV CGO_ENABLED=0
99
ENV GOOS=linux
1010
ENV GOARCH=amd64
11+
ARG COMMIT_SHA=unknown
1112

1213
# Dependencies
1314
WORKDIR /src
@@ -19,9 +20,8 @@ COPY cmd ./cmd
1920
COPY pkg ./pkg
2021
COPY internal ./internal
2122
COPY api ./api
22-
COPY .git ./.git
2323
WORKDIR /src/cmd/epp
24-
RUN go build -buildvcs=true -o /epp
24+
RUN go build -ldflags="-X sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics.CommitSHA=${COMMIT_SHA}" -o /epp
2525

2626
## Multistage deploy
2727
FROM ${BASE_IMAGE}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CONTAINER_TOOL ?= docker
2121
SHELL = /usr/bin/env bash -o pipefail
2222
.SHELLFLAGS = -ec
2323

24+
GIT_COMMIT_SHA ?= "$(shell git rev-parse HEAD 2>/dev/null)"
2425
GIT_TAG ?= $(shell git describe --tags --dirty --always)
2526
PLATFORMS ?= linux/amd64
2627
DOCKER_BUILDX_CMD ?= docker buildx
@@ -175,6 +176,7 @@ image-build: ## Build the EPP image using Docker Buildx.
175176
--platform=$(PLATFORMS) \
176177
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
177178
--build-arg BUILDER_IMAGE=$(BUILDER_IMAGE) \
179+
--build-arg COMMIT_SHA=${GIT_COMMIT_SHA} \
178180
$(PUSH) \
179181
$(LOAD) \
180182
$(IMAGE_BUILD_EXTRA_OPTS) ./

cloudbuild.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ steps:
1212
- GIT_TAG=$_GIT_TAG
1313
- EXTRA_TAG=$_PULL_BASE_REF
1414
- DOCKER_BUILDX_CMD=/buildx-entrypoint
15+
- GIT_COMMIT_SHA=$COMMIT_SHA
1516
- name: gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20240718-5ef92b5c36
1617
entrypoint: make
1718
args:

pkg/epp/metrics/metrics.go

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package metrics
1818

1919
import (
2020
"context"
21-
"runtime/debug"
2221
"sync"
2322
"time"
2423

@@ -37,7 +36,7 @@ const (
3736

3837
var (
3938
// The git hash of the latest commit in the build.
40-
CommitHash string
39+
CommitSHA string
4140
)
4241

4342
var (
@@ -337,25 +336,7 @@ func RecordSchedulerPluginProcessingLatency(pluginType, pluginName string, durat
337336
}
338337

339338
func RecordInferenceExtensionInfo() {
340-
if CommitHash != "" {
341-
InferenceExtensionInfo.WithLabelValues(CommitHash).Set(1)
339+
if CommitSHA != "" {
340+
InferenceExtensionInfo.WithLabelValues(CommitSHA).Set(1)
342341
}
343342
}
344-
345-
func init() {
346-
info, ok := debug.ReadBuildInfo()
347-
if !ok {
348-
return
349-
}
350-
351-
var Commit = func(i *debug.BuildInfo) string {
352-
for _, setting := range i.Settings {
353-
if setting.Key == "vcs.revision" {
354-
return setting.Value
355-
}
356-
}
357-
return ""
358-
}(info)
359-
360-
CommitHash = Commit
361-
}

0 commit comments

Comments
 (0)