tools(hgctl): add windows build (#739)

Signed-off-by: Ink33 <Ink33@smlk.org>
This commit is contained in:
Ink33
2023-12-28 21:00:35 +08:00
committed by GitHub
parent 0ae376b320
commit 659a982496
6 changed files with 112 additions and 27 deletions

View File

@@ -18,6 +18,8 @@ jobs:
tar -zcvf hgctl_latest_linux_arm64.tar.gz out/linux_arm64/
tar -zcvf hgctl_latest_darwin_amd64.tar.gz out/darwin_amd64/
tar -zcvf hgctl_latest_darwin_arm64.tar.gz out/darwin_arm64/
zip -q -r hgctl_latest_windows_amd64.zip out/windows_amd64/
zip -q -r hgctl_latest_windows_arm64.zip out/windows_arm64/
# Ignore the error when we delete the latest release, it might not exist.
@@ -54,6 +56,8 @@ jobs:
hgctl_latest_linux_arm64.tar.gz
hgctl_latest_darwin_amd64.tar.gz
hgctl_latest_darwin_arm64.tar.gz
hgctl_latest_windows_amd64.zip
hgctl_latest_windows_arm64.zip
body: |
This is the "latest" release of **Higress**, which contains the most recent commits from the main branch.

View File

@@ -92,7 +92,8 @@ build-hgctl-multiarch: prebuild $(OUT)
GOPROXY=$(GOPROXY) GOOS=linux GOARCH=arm64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/linux_arm64/ $(HGCTL_BINARIES)
GOPROXY=$(GOPROXY) GOOS=darwin GOARCH=amd64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/darwin_amd64/ $(HGCTL_BINARIES)
GOPROXY=$(GOPROXY) GOOS=darwin GOARCH=arm64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/darwin_arm64/ $(HGCTL_BINARIES)
GOPROXY=$(GOPROXY) GOOS=windows GOARCH=amd64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/windows_amd64/ $(HGCTL_BINARIES)
GOPROXY=$(GOPROXY) GOOS=windows GOARCH=arm64 LDFLAGS=$(RELEASE_LDFLAGS) tools/hack/gobuild.sh ./out/windows_arm64/ $(HGCTL_BINARIES)
# Create targets for OUT_LINUX/binary
# There are two use cases here:
# * Building all docker images (generally in CI). In this case we want to build everything at once, so they share work

View File

@@ -20,10 +20,8 @@ import (
"fmt"
"io"
"os"
"os/signal"
"os/user"
"strings"
"syscall"
"github.com/alibaba/higress/pkg/cmd/hgctl/plugin/option"
ptypes "github.com/alibaba/higress/pkg/cmd/hgctl/plugin/types"
@@ -633,11 +631,7 @@ func (b *Builder) config(f ConfigFunc) (err error) {
b.w = os.Stdout
}
b.sig = make(chan os.Signal, 1)
b.stop = make(chan struct{}, 1)
b.done = make(chan struct{}, 1)
signal.Notify(b.sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM,
syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGQUIT, syscall.SIGTSTP)
signalNotify(b)
if b.Debugger == nil {
b.Debugger = utils.NewDefaultDebugger(b.Debug, b.w)

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// 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.
//go:build linux || darwin || bsd
package build
import (
"os"
"os/signal"
"syscall"
)
func signalNotify(b *Builder) {
b.sig = make(chan os.Signal, 1)
b.stop = make(chan struct{}, 1)
b.done = make(chan struct{}, 1)
signal.Notify(b.sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM,
syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGQUIT, syscall.SIGTSTP)
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) 2022 Alibaba Group Holding Ltd.
//
// 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.
//go:build windows
package build
import (
"os"
"os/signal"
"syscall"
)
func signalNotify(b *Builder) {
b.sig = make(chan os.Signal, 1)
b.stop = make(chan struct{}, 1)
b.done = make(chan struct{}, 1)
signal.Notify(b.sig, syscall.SIGHUP, syscall.SIGINT,
syscall.SIGTERM, syscall.SIGQUIT)
}

View File

@@ -15,36 +15,37 @@
#!/usr/bin/env bash
: "${BINARY_NAME:="hgctl"}"
: "${BINARY_NAME_WINDOWS:="hgctl.exe"}"
: "${hgctl_INSTALL_DIR:="/usr/local/bin"}"
: "${hgctl_INSTALL_DIR_WINDOWS:="${USERPROFILE}/hgctl/bin"}"
export VERSION
HAS_CURL="$(type "curl" &> /dev/null && echo true || echo false)"
HAS_WGET="$(type "wget" &> /dev/null && echo true || echo false)"
HAS_GIT="$(type "git" &> /dev/null && echo true || echo false)"
HAS_CURL="$(type "curl" &>/dev/null && echo true || echo false)"
HAS_WGET="$(type "wget" &>/dev/null && echo true || echo false)"
HAS_GIT="$(type "git" &>/dev/null && echo true || echo false)"
# initArch discovers the architecture for this system.
initArch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
armv5*) ARCH="armv5" ;;
armv6*) ARCH="armv6" ;;
armv7*) ARCH="arm" ;;
aarch64) ARCH="arm64" ;;
x86) ARCH="386" ;;
x86_64) ARCH="amd64" ;;
i686) ARCH="386" ;;
i386) ARCH="386" ;;
esac
}
# initOS discovers the operating system for this system.
initOS() {
OS="$(uname|tr '[:upper:]' '[:lower:]')"
OS="$(uname | tr '[:upper:]' '[:lower:]')"
case "$OS" in
# Minimalist GNU for Windows
mingw*|cygwin*) OS='windows';;
# Minimalist GNU for Windows
mingw* | cygwin*) OS='windows' ;;
esac
}
@@ -60,7 +61,7 @@ runAsRoot() {
# verifySupported checks that the os/arch combination is supported for
# binary builds, as well whether or not necessary tools are present.
verifySupported() {
local supported="darwin-amd64\ndarwin-arm64\nlinux-amd64\nlinux-arm64\n"
local supported="darwin-amd64\ndarwin-arm64\nlinux-amd64\nlinux-arm64\nwindows-amd64\nwindows-arm64\n"
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
echo "No prebuilt binary for ${OS}-${ARCH}."
echo "To build from source, go to https://github.com/alibaba/higress"
@@ -94,7 +95,7 @@ checkDesiredVersion() {
# if it needs to be changed.
checkhgctlInstalledVersion() {
if [[ -f "${hgctl_INSTALL_DIR}/${BINARY_NAME}" ]]; then
version=$("${hgctl_INSTALL_DIR}/${BINARY_NAME}" version --client | grep -Eo "v[0-9]+\.[0-9]+.*" )
version=$("${hgctl_INSTALL_DIR}/${BINARY_NAME}" version --client | grep -Eo "v[0-9]+\.[0-9]+.*")
if [[ "$version" == "$VERSION" ]]; then
echo "hgctl ${version} is already ${VERSION:-latest}"
return 0
@@ -111,6 +112,9 @@ checkhgctlInstalledVersion() {
# for that binary.
downloadFile() {
hgctl_DIST="hgctl_${VERSION}_${OS}_${ARCH}.tar.gz"
if [ "${OS}" == "windows" ]; then
hgctl_DIST="hgctl_${VERSION}_${OS}_${ARCH}.zip"
fi
DOWNLOAD_URL="https://github.com/alibaba/higress/releases/download/$VERSION/$hgctl_DIST"
hgctl_TMP_ROOT="$(mktemp -dt hgctl-installer-XXXXXX)"
hgctl_TMP_FILE="$hgctl_TMP_ROOT/$hgctl_DIST"
@@ -133,6 +137,18 @@ installFile() {
echo "$BINARY_NAME installed into $hgctl_INSTALL_DIR/$BINARY_NAME"
}
# installFileWindows installs the hgctl binary for windows.
installFileWindows() {
hgctl_TMP="$hgctl_TMP_ROOT/$BINARY_NAME"
mkdir -p "$hgctl_TMP"
unzip "$hgctl_TMP_FILE" -d "$hgctl_TMP"
hgctl_TMP_BIN="$hgctl_TMP/out/${OS}_${ARCH}/hgctl.exe"
echo "Preparing to install ${BINARY_NAME} into "
mkdir -p ${hgctl_INSTALL_DIR_WINDOWS}
cp "$hgctl_TMP_BIN" "$hgctl_INSTALL_DIR_WINDOWS/$BINARY_NAME_WINDOWS"
echo "$BINARY_NAME installed into $hgctl_INSTALL_DIR_WINDOWS/$BINARY_NAME_WINDOWS"
}
# fail_trap is executed if an error occurs.
fail_trap() {
result=$?
@@ -150,9 +166,13 @@ fail_trap() {
# testVersion tests the installed client to make sure it is working.
testVersion() {
dir="$hgctl_INSTALL_DIR"
if [ "${OS}" == "windows" ]; then
dir="$hgctl_INSTALL_DIR_WINDOWS"
fi
set +e
if ! [ "$(command -v $BINARY_NAME)" ]; then
echo "$BINARY_NAME not found. Is $hgctl_INSTALL_DIR on your PATH?"
echo "$BINARY_NAME not found. Is ${dir} on your PATH?"
exit 1
fi
set -e
@@ -177,7 +197,11 @@ verifySupported
checkDesiredVersion
if ! checkhgctlInstalledVersion; then
downloadFile
installFile
if [ "${OS}" == "windows" ]; then
installFileWindows
else
installFile
fi
fi
testVersion
cleanup