Skip to content

Commit

Permalink
fix govc installation
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jan 8, 2025
1 parent 94325ed commit 03267e4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ GOVULNCHECK_PKG := golang.org/x/vuln/cmd/govulncheck
GOVC_VER := $(shell cat go.mod | grep "github.com/vmware/govmomi" | awk '{print $$NF}')
GOVC_BIN := govc
GOVC := $(abspath $(TOOLS_BIN_DIR)/$(GOVC_BIN)-$(GOVC_VER))
GOVC_PKG := github.com/vmware/govmomi/govc
GOVC_INSTALL := ./hack/govc-install.sh

KIND_VER := $(call get_test_go_version,sigs.k8s.io/kind)
KIND_BIN := kind
Expand Down Expand Up @@ -1111,7 +1111,7 @@ $(GOVULNCHECK): # Build govulncheck.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOVULNCHECK_PKG) $(GOVULNCHECK_BIN) $(GOVULNCHECK_VER)

$(GOVC): # Build GOVC.
CGO_ENABLED=0 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOVC_PKG) $(GOVC_BIN) $(GOVC_VER)
GOBIN=$(TOOLS_BIN_DIR) $(GOVC_INSTALL) $(GOVC_BIN) $(GOVC_VER)

$(KIND): # Build kind.
cd $(TEST_DIR); GOBIN=$(TOOLS_BIN_DIR) ../$(GO_INSTALL) $(KIND_PKG) $(KIND_BIN) $(KIND_VER)
Expand Down
68 changes: 68 additions & 0 deletions hack/govc-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Copyright 2021 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

set -x

if [ -z "${1}" ]; then
echo "must provide binary name as first parameter"
exit 1
fi

if [ -z "${2}" ]; then
echo "must provide version as second parameter"
exit 1
fi

if [ -z "${GOBIN}" ]; then
echo "GOBIN is not set. Must set GOBIN to install the bin in a specified directory."
exit 1
fi

GOVC_ARCH="x86_64"
if [ "$(go env GOARCH)" == "arm64" ]; then
GOVC_ARCH="arm64"
fi

GOVC_OS="Linux"
if [ "$(go env GOOS)" == "darwin" ]; then
GOVC_OS="Darwin"
fi

rm -f "${GOBIN}/${1}"* || true

ORIGINAL_WORKDIR="$(pwd)"
TMP_DIR="${1}.tmp"

# Create TMP_DIR to download and unpack the govc tarball.
rm -r "${TMP_DIR}" || true
mkdir -p "${TMP_DIR}"
cd "${TMP_DIR}"

# Download govc

wget "https://github.com/vmware/govmomi/releases/download/${2}/govc_${GOVC_OS}_${GOVC_ARCH}.tar.gz"
tar -xvzf "govc_${GOVC_OS}_${GOVC_ARCH}.tar.gz" govc
mv govc "${GOBIN}/${1}-${2}"

# Get back to the original directory and cleanup the temporary directory.
cd "${ORIGINAL_WORKDIR}"
rm -r "${TMP_DIR}"

# Link the unversioned name to the versioned binary.
ln -sf "${GOBIN}/${1}-${2}" "${GOBIN}/${1}"

0 comments on commit 03267e4

Please sign in to comment.