Skip to content

Commit 17b0730

Browse files
authored
[release-v1.16] Fix image generator and builds (#541)
1 parent 23cec8d commit 17b0730

File tree

13 files changed

+216
-70
lines changed

13 files changed

+216
-70
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# limitations under the License.
1616

1717
CGO_ENABLED=0
18-
GOOS=linux
18+
GOOS ?=
19+
GOARCH ?=
1920
TEST_IMAGES=./test/test_images/helloworld knative.dev/serving/test/test_images/grpc-ping knative.dev/serving/test/test_images/multicontainer/servingcontainer knative.dev/serving/test/test_images/multicontainer/sidecarcontainer
2021
TEST=
2122
TEST_IMAGE_TAG ?= latest
@@ -28,6 +29,10 @@ build:
2829
GOFLAGS='' ./hack/build.sh -f
2930
.PHONY: build
3031

32+
build-with-platform:
33+
GOFLAGS='' ./hack/build.sh -p $(GOOS) $(GOARCH)
34+
.PHONY: build-with-platform
35+
3136
build-cross:
3237
GOFLAGS='' ./hack/build.sh -x
3338
.PHONY: build-cross

hack/build.sh

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -o pipefail
2020
set -o errexit
2121
set -o nounset
2222

23-
source_dirs="cmd pkg test tools"
23+
source_dirs="cmd pkg test lib tools"
2424

2525
# Store for later
2626
if [ -z "${1-}" ]; then
@@ -75,6 +75,15 @@ run() {
7575
exit 0
7676
fi
7777

78+
# platform mode: Only to build target platform for cross-compilation
79+
if $(has_flag --platform -p); then
80+
# Extract GOOS and GOARCH from command-line arguments
81+
GOOS="${ARGS[1]}"
82+
GOARCH="${ARGS[2]}"
83+
go_build_with_goos_goarch "$GOOS" "$GOARCH"
84+
exit 0
85+
fi
86+
7887
# Run only tests
7988
if has_flag --test -t; then
8089
go_test
@@ -139,13 +148,32 @@ source_lint() {
139148
go_build() {
140149
echo "🚧 Compile"
141150
# Env var exported by hack/build-flags.sh
142-
go build -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
151+
go build -mod=vendor -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
143152

144153
if file kn | grep -q -i "Windows"; then
145154
mv kn kn.exe
146155
fi
147156
}
148157

158+
go_build_with_goos_goarch() {
159+
GOOS="${1}"
160+
GOARCH="${2}"
161+
162+
if [ -z "${GOOS}" ] || [ -z "${GOARCH}" ]; then
163+
echo "❌ Missing GOOS or GOARCH. Please provide both GOOS and GOARCH as arguments."
164+
exit 1
165+
fi
166+
167+
echo "🚧 Compile for GOOS=${GOOS} GOARCH=${GOARCH}"
168+
169+
# Env var exported by hack/build-flags.sh
170+
GOOS="${GOOS}" GOARCH="${GOARCH}" go build -mod=vendor -ldflags "${KN_BUILD_LD_FLAGS:-}" -o kn ./cmd/...
171+
172+
if $(file kn | grep -q -i "Windows"); then
173+
mv kn kn.exe
174+
fi
175+
}
176+
149177
go_test() {
150178
local test_output
151179
test_output="$(mktemp /tmp/kn-client-test-output.XXXXXX)"
@@ -179,7 +207,7 @@ check_license() {
179207
local check_output
180208
check_output="$(mktemp /tmp/kn-client-licence-check.XXXXXX)"
181209
for ext in "${extensions_to_check[@]}"; do
182-
find . -name "*.$ext" -a \! -path "./.*" -a \! -path "./third_party/*" -print0 |
210+
find . -name "*.$ext" -a \! -path "./vendor/*" -a \! -path "./.*" -a \! -path "./third_party/*" -print0 |
183211
while IFS= read -r -d '' path; do
184212
for rword in "${required_keywords[@]}"; do
185213
if ! grep -q "$rword" "$path"; then
@@ -287,19 +315,19 @@ cross_build() {
287315

288316
export CGO_ENABLED=0
289317
echo " 🐧 kn-linux-amd64"
290-
GOOS=linux GOARCH=amd64 go build -ldflags "${ld_flags}" -o ./kn-linux-amd64 ./cmd/... || failed=1
318+
GOOS=linux GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-amd64 ./cmd/... || failed=1
291319
echo " 💪 kn-linux-arm64"
292-
GOOS=linux GOARCH=arm64 go build -ldflags "${ld_flags}" -o ./kn-linux-arm64 ./cmd/... || failed=1
320+
GOOS=linux GOARCH=arm64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-arm64 ./cmd/... || failed=1
293321
echo " 🍏 kn-darwin-amd64"
294-
GOOS=darwin GOARCH=amd64 go build -ldflags "${ld_flags}" -o ./kn-darwin-amd64 ./cmd/... || failed=1
322+
GOOS=darwin GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-darwin-amd64 ./cmd/... || failed=1
295323
echo " 🍎 kn-darwin-arm64"
296-
GOOS=darwin GOARCH=arm64 go build -ldflags "${ld_flags}" -o ./kn-darwin-arm64 ./cmd/... || failed=1
324+
GOOS=darwin GOARCH=arm64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-darwin-arm64 ./cmd/... || failed=1
297325
echo " 🎠 kn-windows-amd64.exe"
298-
GOOS=windows GOARCH=amd64 go build -ldflags "${ld_flags}" -o ./kn-windows-amd64.exe ./cmd/... || failed=1
326+
GOOS=windows GOARCH=amd64 go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-windows-amd64.exe ./cmd/... || failed=1
299327
echo " Z kn-linux-s390x"
300-
GOOS=linux GOARCH=s390x go build -ldflags "${ld_flags}" -o ./kn-linux-s390x ./cmd/... || failed=1
328+
GOOS=linux GOARCH=s390x go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-s390x ./cmd/... || failed=1
301329
echo " P kn-linux-ppc64le"
302-
GOOS=linux GOARCH=ppc64le go build -ldflags "${ld_flags}" -o ./kn-linux-ppc64le ./cmd/... || failed=1
330+
GOOS=linux GOARCH=ppc64le go build -mod=vendor -ldflags "${ld_flags}" -o ./kn-linux-ppc64le ./cmd/... || failed=1
303331

304332
return ${failed}
305333
}
@@ -336,6 +364,7 @@ Usage: $(basename "${BASH_SOURCE[0]}") [... options ...]
336364
with the following options:
337365
338366
-f --fast Only compile (without dep update, formatting, testing, doc gen)
367+
-p --platform Specify the target platform for cross-compilation (e.g., linux amd64, darwin amd64)"
339368
-t --test Run tests when used with --fast or --watch
340369
-c --codegen Runs formatting, doc gen and update without compiling/testing
341370
-w --watch Watch for source changes and recompile in fast mode
@@ -353,12 +382,13 @@ ln -s $(basedir)/hack/build.sh /usr/local/bin/kn_build.sh
353382
Examples:
354383
355384
* Update deps, format, license check,
356-
gen docs, compile, test: ........... build.sh
357-
* Compile only: ...................... build.sh --fast
358-
* Run only tests: .................... build.sh --test
359-
* Compile with tests: ................ build.sh -f -t
360-
* Automatic recompilation: ........... build.sh --watch
361-
* Build cross platform binaries: ..... build.sh --all
385+
gen docs, compile, test: ........................ build.sh
386+
* Compile only: ................................... build.sh --fast
387+
* Build cross platform binaries for a platform: ... build.sh -p linux amd64
388+
* Run only tests: ................................. build.sh --test
389+
* Compile with tests: ............................. build.sh -f -t
390+
* Automatic recompilation: ........................ build.sh --watch
391+
* Build cross platform binaries: .................. build.sh --all
362392
EOT
363393
}
364394

@@ -368,8 +398,7 @@ if has_flag --debug; then
368398
fi
369399

370400
# Shared funcs from hack repo
371-
# shellcheck disable=SC1090
372-
source "$(go run knative.dev/hack/cmd/script library.sh)"
401+
source "$(basedir)"/vendor/knative.dev/hack/library.sh
373402

374403
# Shared funcs with CI
375404
while IFS= read -r -d '' file; do

openshift/ci-operator/build-image/Dockerfile

100644100755
Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
# Copyright 2019 The OpenShift Knative Authors
2-
#
3-
# Licensed under the Apache License, Version 2.0 (the "License");
4-
# you may not use this file except in compliance with the License.
5-
# You may obtain a copy of the License at
6-
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# Unless required by applicable law or agreed to in writing, software
10-
# distributed under the License is distributed on an "AS IS" BASIS,
11-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
# See the License for the specific language governing permissions and
13-
# limitations under the License.
1+
# DO NOT EDIT! Generated Dockerfile.
2+
3+
FROM registry.ci.openshift.org/ocp/4.17:cli-artifacts as tools
144

155
# Dockerfile to bootstrap build and test in openshift-ci
166
FROM registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.17 as builder
177

18-
# Add kubernetes repository
19-
ADD openshift/ci-operator/build-image/kubernetes.repo /etc/yum.repos.d/
8+
ARG TARGETARCH
9+
10+
COPY --from=tools /usr/share/openshift/linux_$TARGETARCH/oc.rhel8 /usr/bin/oc
11+
12+
RUN ln -s /usr/bin/oc /usr/bin/kubectl
13+
14+
RUN yum install -y httpd-tools
15+
16+
RUN wget https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \
17+
chmod 700 ./get-helm-3
18+
19+
RUN ./get-helm-3 --version v3.11.3 --no-sudo && helm version
2020

21-
RUN yum install -y kubectl httpd-tools
21+
RUN GOFLAGS='' go install github.com/mikefarah/yq/v3@latest
22+
RUN GOFLAGS='' go install -tags="exclude_graphdriver_btrfs containers_image_openpgp" github.com/containers/skopeo/cmd/[email protected]
2223

23-
# Allow runtime users to add entries to /etc/passwd
24-
RUN chmod g+rw /etc/passwd
24+
# go install creates $GOPATH/.cache with root permissions, we delete it here
25+
# to avoid permission issues with the runtime users
26+
RUN rm -rf $GOPATH/.cache

openshift/ci-operator/build-image/kubernetes.repo

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This is not generated Dockerfile, yet!
2+
ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal
3+
ARG CLI_ARTIFACTS=registry.redhat.io/openshift-serverless-1/kn-cli-artifacts-rhel8:1.14
4+
5+
FROM $CLI_ARTIFACTS as builder
6+
7+
FROM $GO_RUNTIME
8+
9+
ARG VERSION=knative-v1.16
10+
11+
RUN mkdir -p /usr/share/kn
12+
13+
COPY --from=builder /usr/share/kn /usr/share/kn
14+
COPY LICENSE /licenses/
15+
16+
USER 65532
17+
18+
LABEL \
19+
com.redhat.component="openshift-serverless-1-client-cli-artifacts-rhel8-container" \
20+
name="openshift-serverless-1/client-cli-artifacts-rhel8" \
21+
version=$VERSION \
22+
summary="Red Hat OpenShift Serverless 1 Client Cli Artifacts" \
23+
maintainer="[email protected]" \
24+
description="Red Hat OpenShift Serverless 1 Client Cli Artifacts" \
25+
io.k8s.display-name="Red Hat OpenShift Serverless 1 Client Cli Artifacts" \
26+
io.k8s.description="Red Hat OpenShift Serverless Client Cli Artifacts" \
27+
io.openshift.tags="cli-artifacts"

openshift/ci-operator/knative-images/client/Dockerfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

openshift/ci-operator/knative-images/client/Dockerfile.cliartifacts

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# DO NOT EDIT! Generated Dockerfile for cmd/kn.
2+
ARG GO_BUILDER=registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.17
3+
ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal
4+
5+
FROM $GO_BUILDER as builder
6+
7+
WORKDIR /workspace
8+
COPY . .
9+
10+
ENV CGO_ENABLED=1
11+
ENV GOEXPERIMENT=strictfipsruntime
12+
13+
ENV KN_PLUGIN_FUNC_UTIL_IMAGE=registry.redhat.io/openshift-serverless-1/kn-plugin-func-func-util-rhel8@sha256:63fbd304ffb93e5883b987ac90a476cd9ff9946f164ca8acb9c1a95fee84bcb3
14+
ENV KN_PLUGIN_EVENT_SENDER_IMAGE=registry.redhat.io/openshift-serverless-1/kn-plugin-event-sender-rhel8@sha256:1d2a8b786bd09301530d37440ce6501527cfd511ba78d97da5eda952a6558ebe
15+
RUN go build -tags strictfipsruntime -o /usr/bin/main ./cmd/kn
16+
17+
FROM $GO_RUNTIME
18+
19+
ARG VERSION=knative-v1.16
20+
21+
COPY --from=builder /usr/bin/main /ko-app/kn
22+
COPY LICENSE /licenses/
23+
24+
USER 65532
25+
26+
LABEL \
27+
com.redhat.component="openshift-serverless-1-client-kn-rhel8-container" \
28+
name="openshift-serverless-1/client-kn-rhel8" \
29+
version=$VERSION \
30+
summary="Red Hat OpenShift Serverless 1 Client Kn" \
31+
maintainer="[email protected]" \
32+
description="Red Hat OpenShift Serverless 1 Client Kn" \
33+
io.k8s.display-name="Red Hat OpenShift Serverless 1 Client Kn" \
34+
io.k8s.description="Red Hat OpenShift Serverless Client Kn" \
35+
io.openshift.tags="kn"
36+
37+
ENTRYPOINT ["/ko-app/kn"]
Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1-
FROM openshift/origin-base
1+
# DO NOT EDIT! Generated Dockerfile for test/test_images/helloworld.
2+
ARG GO_BUILDER=registry.ci.openshift.org/openshift/release:rhel-8-release-golang-1.22-openshift-4.17
3+
ARG GO_RUNTIME=registry.access.redhat.com/ubi8/ubi-minimal
4+
5+
FROM $GO_BUILDER as builder
6+
7+
WORKDIR /workspace
8+
COPY . .
9+
10+
ENV CGO_ENABLED=1
11+
ENV GOEXPERIMENT=strictfipsruntime
12+
13+
RUN go build -tags strictfipsruntime -o /usr/bin/main ./test/test_images/helloworld
14+
15+
FROM $GO_RUNTIME
16+
17+
ARG VERSION=knative-v1.16
18+
19+
COPY --from=builder /usr/bin/main /ko-app/helloworld
20+
COPY LICENSE /licenses/
21+
222
USER 65532
323

4-
ADD helloworld /ko-app/helloworld
24+
LABEL \
25+
com.redhat.component="openshift-serverless-1-client-test-test-images-helloworld-rhel8-container" \
26+
name="openshift-serverless-1/client-test-test-images-helloworld-rhel8" \
27+
version=$VERSION \
28+
summary="Red Hat OpenShift Serverless 1 Client Test Test Images Helloworld" \
29+
maintainer="[email protected]" \
30+
description="Red Hat OpenShift Serverless 1 Client Test Test Images Helloworld" \
31+
io.k8s.display-name="Red Hat OpenShift Serverless 1 Client Test Test Images Helloworld" \
32+
io.k8s.description="Red Hat OpenShift Serverless Client Test Test Images Helloworld" \
33+
io.openshift.tags="test-test-images-helloworld"
534

6-
ENTRYPOINT ["/ko-app/helloworld"]
35+
ENTRYPOINT ["/ko-app/helloworld"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# DO NOT EDIT! Generated Dockerfile.
2+
3+
FROM src
4+
5+
RUN chmod +x vendor/k8s.io/code-generator/generate-groups.sh || true
6+
RUN chmod +x vendor/knative.dev/pkg/hack/generate-knative.sh || true
7+
RUN chmod +x vendor/k8s.io/code-generator/generate-internal-groups.sh || true

0 commit comments

Comments
 (0)