Skip to content

Commit 02ae693

Browse files
committed
hack/build-go.sh: Build cluster-version-operator-tests binary
Build a statically compiled openshift-tests extension binary. Static compilation is done because [1]: > Extension binaries are extracted from container images into a > running Pod executing openshift-tests. Contributors do not > necessarily know which version of RHEL the openshift-tests > binary will be running on, so, for maximum portability, > test extension binaries should be statically compiled. The `GO_COMPLIANCE_POLICY="exempt_all"` is set because [1]: > For compliance reasons, when a binary is compiled by a golang > builder image supplied by ART, a wrapper around the go compiler > will force FIPS compliant compilation (e.g. dynamic linking). > For this reason, extension binaries should include > GO_COMPLIANCE_POLICY="exempt_all" in the environment when > compiling an extension binary. This will inhibit the wrapper from > modifying CGO_ENABLED or other compiler arguments required for > static compilation. Set `CGO_ENABLED=0` to disable the use of cgo to allow the static compilation. Otherwise, the binary is dynamically linked. As such the usage cgo is disabled by default in the binary. Verifying whether such a binary is built statically: ```sh $ ldd _output/linux/amd64/openshift-tests-extension not a dynamic executable ``` Format of the github.com/openshift-eng/openshift-tests-extension variables is based on the existing Makefile [2] in the openshift-tests-extension repository. [1]: https://github.com/openshift/enhancements/blob/c2c0d43e3cd70cf79bc2b101ceb6a03c5e0114a8/enhancements/testing/openshift-tests-extension.md [2]: https://github.com/openshift-eng/openshift-tests-extension/blob/86b9979c22fd7b5022cef0e57312eda54e6e3064/Makefile
1 parent f5c1c83 commit 02ae693

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

hack/build-go.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,34 @@ if [ -z "${VERSION_OVERRIDE:-}" ]; then
2020
VERSION_OVERRIDE=$(git describe --abbrev=8 --dirty --always)
2121
fi
2222

23-
GLDFLAGS+="-X ${REPO}/pkg/version.Raw=${VERSION_OVERRIDE}"
24-
2523
eval $(go env)
2624

2725
if [ -z ${BIN_PATH+a} ]; then
2826
export BIN_PATH=_output/${GOOS}/${GOARCH}
2927
fi
3028

29+
echo "Building binaries into ${BIN_PATH}"
3130
mkdir -p ${BIN_PATH}
3231

33-
echo "Building ${REPO} (${VERSION_OVERRIDE})"
32+
# Build the cluster-version-operator-tests binary and compress it
33+
OPENSHIFT_TESTS_EXTENSION_MODULE="github.com/openshift-eng/openshift-tests-extension"
34+
GIT_COMMIT=$(git rev-parse --short HEAD)
35+
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
36+
GIT_TREE_STATE=$(if git diff --quiet; then echo clean; else echo dirty; fi)
37+
LDFLAGS_TEST_EXTENSION=$GLDFLAGS
38+
LDFLAGS_TEST_EXTENSION+=" -X '${OPENSHIFT_TESTS_EXTENSION_MODULE}/pkg/version.CommitFromGit=${GIT_COMMIT}'"
39+
LDFLAGS_TEST_EXTENSION+=" -X '${OPENSHIFT_TESTS_EXTENSION_MODULE}/pkg/version.BuildDate=${BUILD_DATE}'"
40+
LDFLAGS_TEST_EXTENSION+=" -X '${OPENSHIFT_TESTS_EXTENSION_MODULE}/pkg/version.GitTreeState=${GIT_TREE_STATE}'"
41+
42+
echo "Building ${REPO} cluster-version-operator-tests binary (${VERSION_OVERRIDE})"
43+
GO_COMPLIANCE_POLICY="exempt_all" CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} \
44+
go build \
45+
${GOFLAGS} \
46+
-ldflags "${LDFLAGS_TEST_EXTENSION}" \
47+
-o "${BIN_PATH}/cluster-version-operator-tests" \
48+
"${REPO}/cmd/cluster-version-operator-tests/..."
49+
50+
# Build the cluster-version-operator binary
51+
GLDFLAGS+="-X ${REPO}/pkg/version.Raw=${VERSION_OVERRIDE}"
52+
echo "Building ${REPO} cluster-version-operator binary (${VERSION_OVERRIDE})"
3453
GOOS=${GOOS} GOARCH=${GOARCH} go build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o ${BIN_PATH}/cluster-version-operator ${REPO}/cmd/cluster-version-operator/...

0 commit comments

Comments
 (0)