-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Summary
gordon push --build only injects VERSION as a build arg, using the bare-name form (--build-arg VERSION). Many project Dockerfiles use different variable names (GIT_TAG, GIT_SHA, BUILD_TIME) that Gordon never populates automatically. The make push approach works because Makefiles pass these values explicitly as KEY=VALUE.
Root Cause
File: internal/adapters/in/cli/push.go:467, 490-506
Gordon does two things:
- Sets
VERSION=<resolved>in the subprocess environment - Passes
--build-arg VERSION(bare name — inherits from subprocess env)
It passes nothing else. A Dockerfile like this (real-world example):
ARG GIT_TAG=unknown
ARG GIT_SHA=unknown
ARG BUILD_TIME=unknown
ENV PUBLIC_APP_VERSION=${GIT_TAG}…gets GIT_TAG=unknown because Gordon never injects it. The app binary reports "unknown" at runtime.
Why make push Works
A typical Makefile pre-computes all git values and passes them explicitly as KEY=VALUE:
docker buildx build \
--build-arg GIT_TAG=$(shell git describe --tags --abbrev=0) \
--build-arg GIT_SHA=$(shell git rev-parse --short HEAD) \
--build-arg BUILD_TIME=$(shell date -u +%Y-%m-%dT%H:%M:%SZ) \
--build-arg VERSION=$(VERSION) \
...KEY=VALUE form is also more reliable than bare KEY — it does not depend on env inheritance behaviour across Docker daemon versions.
Proposed Fix
Gordon should automatically inject the following standard git build args into every --build invocation, as explicit KEY=VALUE pairs:
| Build arg | Source | Example |
|---|---|---|
VERSION |
git describe / CI env / --tag flag |
v1.2.3 |
GIT_TAG |
same as VERSION | v1.2.3 |
GIT_SHA |
git rev-parse --short HEAD |
abc1234 |
BUILD_TIME |
time.Now().UTC().Format(time.RFC3339) |
2026-02-24T10:00:00Z |
These should be passed as --build-arg GIT_TAG=v1.2.3 (not bare name), matching the convention used by typical Makefiles. The user-supplied --build-arg flags (via CLI) still take precedence and are appended after, so they can override any of these defaults.
Additional: silent fallback to "latest"
File: internal/adapters/in/cli/push.go:685
func getGitVersion(ctx context.Context) string {
out, err := exec.CommandContext(ctx, "git", "describe", "--tags", "--dirty").Output()
if err != nil {
return "" // silently becomes "latest", no log
}
return strings.TrimSpace(string(out))
}When a repo has no git tags, version silently falls back to "latest" with no warning. A log message should be emitted so the user understands why their image has no version tag.
Affected Files
internal/adapters/in/cli/push.go:467— subprocess env setupinternal/adapters/in/cli/push.go:490—buildImageArgs()— where--build-argflags are assembledinternal/adapters/in/cli/push.go:685—getGitVersion()— silent fallback