Skip to content

Commit fd353e5

Browse files
committed
Set version via ldflags in ko
1 parent b3e7b5b commit fd353e5

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ build: build-images build-atectl
4040

4141
.PHONY: build-images
4242
build-images:
43-
GOFLAGS='"-ldflags=$(LDFLAGS)"' \
4443
$(KO) build \
44+
--ldflags="$(LDFLAGS)" \
4545
./cmd/ateapi \
4646
./cmd/atelet \
4747
./cmd/podcertcontroller \
@@ -57,8 +57,7 @@ build-atenet:
5757

5858
.PHONY: build-demos
5959
build-demos:
60-
GOFLAGS='"-ldflags=$(LDFLAGS)"' \
61-
$(KO) build ./demos/counter
60+
$(KO) build --ldflags="$(LDFLAGS)" ./demos/counter
6261

6362
.PHONY: test
6463
test:
@@ -70,6 +69,12 @@ e2e: build build-demos
7069

7170
.PHONY: fmt verify-fmt
7271

72+
# Prints the Go ldflags (used for scripts to do version stamping).
73+
ldflags:
74+
@for flag in $(LDFLAGS); do \
75+
echo $$flag; \
76+
done
77+
7378
# Formats all Go files in the project
7479
fmt:
7580
@./hack/update/gofmt.sh

hack/install-ate.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,25 @@ run_kubectl_ate() {
110110
}
111111

112112
run_ko() {
113+
# Build up a set of ldflags to pass to ko.
114+
local ldflags=()
115+
mapfile -t ldflags < <(make ldflags)
116+
for i in "${!ldflags[@]}"; do
117+
ldflags[i]="--ldflags=${ldflags[i]}"
118+
done
119+
113120
# Only ko subcommands that delegate to kubectl (apply, create, delete, run)
114121
# accept args after `--`. ko build, resolve, deps, login etc. reject
115122
# `--context=...` as an unknown subcommand and abort the install.
116123
case "${1:-}" in
117124
apply|create|delete|run)
118-
./hack/run-tool.sh ko "$@" ${KUBECTL_CONTEXT:+-- --context="${KUBECTL_CONTEXT}"}
125+
./hack/run-tool.sh ko "$@" \
126+
"${ldflags[@]}" \
127+
${KUBECTL_CONTEXT:+-- --context="${KUBECTL_CONTEXT}"}
119128
;;
120129
*)
121-
./hack/run-tool.sh ko "$@"
130+
./hack/run-tool.sh ko "$@" \
131+
"${ldflags[@]}"
122132
;;
123133
esac
124134
}

0 commit comments

Comments
 (0)