@@ -21,7 +21,10 @@ HOST_GOOS=$(go env GOOS)
2121HOST_GOARCH=$( go env GOARCH)
2222
2323# --tags allows detecting non-annotated tags as well as annotated ones
24- GIT_VERSION=$( git describe --always --dirty --tags)
24+ GIT_VERSION=${VERSION:- " $( git describe --always --dirty --tags) " }
25+ # PRE_DEFINED_VERSION is used when building binary and tagging image. Fallback to GIT_VERSION if not set.
26+ # This is useful when automate creating documents. Otherwise the version in the doc will be git shas.
27+ PRE_DEFINED_VERSION=${PRE_DEFINED_VERSION:- $GIT_VERSION }
2528IMAGE_VERSION=$( git describe --always --dirty --tags)
2629IMAGE_TAG=$( echo " $IMAGE_VERSION " | cut -d. -f1,2)
2730IMAGE_BRANCH=$( git rev-parse --abbrev-ref HEAD | sed ' s/\///g' )
@@ -143,7 +146,7 @@ gen_dockerfile_for_os_arch(){
143146 # Onlhy doing one arch so this could be hardcoded, likewise we could handle the
144147 # base image differently. Wanted something here for parity with linux in case we expand it though.
145148 sed -e ' s|BINARY|build/windows/amd64/sonobuoy.exe|g' DockerfileWindows > " $dockerfile "
146- else
149+ else
147150 echo " Windows ARCH unknown"
148151 fi
149152 else
@@ -155,7 +158,7 @@ gen_dockerfile_for_os_arch(){
155158build_container_os_arch_version (){
156159 dockerfile=" build/$1 /$2 /Dockerfile"
157160 gen_dockerfile_for_os_arch " $1 " " $2 "
158- if [ " $1 " = " windows" ]; then
161+ if [ " $1 " = " windows" ]; then
159162 buildx_container_windows_version $3
160163 else
161164 build_container_dockerfile_arch " $dockerfile " $2
@@ -178,7 +181,7 @@ windows_containers() {
178181
179182# Builds a binary for a specific goos/goarch.
180183build_binary_GOOS_GOARCH () {
181- LDFLAGS=" -s -w -X $GOTARGET /pkg/buildinfo.Version=$GIT_VERSION -X $GOTARGET /pkg/buildinfo.GitSHA=$GIT_REF_LONG "
184+ LDFLAGS=" -s -w -X $GOTARGET /pkg/buildinfo.Version=$PRE_DEFINED_VERSION -X $GOTARGET /pkg/buildinfo.GitSHA=$GIT_REF_LONG "
182185 args=(${VERBOSE: +-v} -ldflags " ${LDFLAGS} " " $GOTARGET " )
183186 if [ " $VERBOSE " ]; then args+=(" -v" ); fi ;
184187
@@ -209,7 +212,7 @@ build_binaries() {
209212
210213# Builds sonobuoy using the local goos/goarch.
211214native () {
212- LDFLAGS=" -s -w -X $GOTARGET /pkg/buildinfo.Version=$GIT_VERSION -X $GOTARGET /pkg/buildinfo.GitSHA=$GIT_REF_LONG "
215+ LDFLAGS=" -s -w -X $GOTARGET /pkg/buildinfo.Version=$PRE_DEFINED_VERSION -X $GOTARGET /pkg/buildinfo.GitSHA=$GIT_REF_LONG "
213216 args=(-ldflags " ${LDFLAGS} " " $GOTARGET " )
214217 CGO_ENABLED=0 GOOS=" $HOST_GOOS " GOARCH=" $HOST_GOARCH " go build -buildvcs=false -o sonobuoy " ${args[@]} "
215218 mkdir -p ./build/$HOST_GOOS /$HOST_GOARCH
0 commit comments