mirror of
https://github.com/alibaba/higress.git
synced 2026-06-09 12:47:28 +08:00
tools(hgctl): add windows build (#739)
Signed-off-by: Ink33 <Ink33@smlk.org>
This commit is contained in:
4
.github/workflows/latest-release.yaml
vendored
4
.github/workflows/latest-release.yaml
vendored
@@ -18,6 +18,8 @@ jobs:
|
|||||||
tar -zcvf hgctl_latest_linux_arm64.tar.gz out/linux_arm64/
|
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_amd64.tar.gz out/darwin_amd64/
|
||||||
tar -zcvf hgctl_latest_darwin_arm64.tar.gz out/darwin_arm64/
|
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.
|
# 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_linux_arm64.tar.gz
|
||||||
hgctl_latest_darwin_amd64.tar.gz
|
hgctl_latest_darwin_amd64.tar.gz
|
||||||
hgctl_latest_darwin_arm64.tar.gz
|
hgctl_latest_darwin_arm64.tar.gz
|
||||||
|
hgctl_latest_windows_amd64.zip
|
||||||
|
hgctl_latest_windows_arm64.zip
|
||||||
body: |
|
body: |
|
||||||
This is the "latest" release of **Higress**, which contains the most recent commits from the main branch.
|
This is the "latest" release of **Higress**, which contains the most recent commits from the main branch.
|
||||||
|
|
||||||
|
|||||||
@@ -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=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=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=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
|
# Create targets for OUT_LINUX/binary
|
||||||
# There are two use cases here:
|
# 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
|
# * Building all docker images (generally in CI). In this case we want to build everything at once, so they share work
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/alibaba/higress/pkg/cmd/hgctl/plugin/option"
|
"github.com/alibaba/higress/pkg/cmd/hgctl/plugin/option"
|
||||||
ptypes "github.com/alibaba/higress/pkg/cmd/hgctl/plugin/types"
|
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.w = os.Stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
b.sig = make(chan os.Signal, 1)
|
signalNotify(b)
|
||||||
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)
|
|
||||||
|
|
||||||
if b.Debugger == nil {
|
if b.Debugger == nil {
|
||||||
b.Debugger = utils.NewDefaultDebugger(b.Debug, b.w)
|
b.Debugger = utils.NewDefaultDebugger(b.Debug, b.w)
|
||||||
|
|||||||
31
pkg/cmd/hgctl/plugin/build/signal.go
Normal file
31
pkg/cmd/hgctl/plugin/build/signal.go
Normal 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)
|
||||||
|
}
|
||||||
31
pkg/cmd/hgctl/plugin/build/signal_windows.go
Normal file
31
pkg/cmd/hgctl/plugin/build/signal_windows.go
Normal 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)
|
||||||
|
}
|
||||||
@@ -15,36 +15,37 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
: "${BINARY_NAME:="hgctl"}"
|
: "${BINARY_NAME:="hgctl"}"
|
||||||
|
: "${BINARY_NAME_WINDOWS:="hgctl.exe"}"
|
||||||
: "${hgctl_INSTALL_DIR:="/usr/local/bin"}"
|
: "${hgctl_INSTALL_DIR:="/usr/local/bin"}"
|
||||||
|
: "${hgctl_INSTALL_DIR_WINDOWS:="${USERPROFILE}/hgctl/bin"}"
|
||||||
export VERSION
|
export VERSION
|
||||||
|
|
||||||
HAS_CURL="$(type "curl" &> /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_WGET="$(type "wget" &>/dev/null && echo true || echo false)"
|
||||||
HAS_GIT="$(type "git" &> /dev/null && echo true || echo false)"
|
HAS_GIT="$(type "git" &>/dev/null && echo true || echo false)"
|
||||||
|
|
||||||
# initArch discovers the architecture for this system.
|
# initArch discovers the architecture for this system.
|
||||||
initArch() {
|
initArch() {
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
case $ARCH in
|
case $ARCH in
|
||||||
armv5*) ARCH="armv5";;
|
armv5*) ARCH="armv5" ;;
|
||||||
armv6*) ARCH="armv6";;
|
armv6*) ARCH="armv6" ;;
|
||||||
armv7*) ARCH="arm";;
|
armv7*) ARCH="arm" ;;
|
||||||
aarch64) ARCH="arm64";;
|
aarch64) ARCH="arm64" ;;
|
||||||
x86) ARCH="386";;
|
x86) ARCH="386" ;;
|
||||||
x86_64) ARCH="amd64";;
|
x86_64) ARCH="amd64" ;;
|
||||||
i686) ARCH="386";;
|
i686) ARCH="386" ;;
|
||||||
i386) ARCH="386";;
|
i386) ARCH="386" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# initOS discovers the operating system for this system.
|
# initOS discovers the operating system for this system.
|
||||||
initOS() {
|
initOS() {
|
||||||
OS="$(uname|tr '[:upper:]' '[:lower:]')"
|
OS="$(uname | tr '[:upper:]' '[:lower:]')"
|
||||||
|
|
||||||
case "$OS" in
|
case "$OS" in
|
||||||
# Minimalist GNU for Windows
|
# Minimalist GNU for Windows
|
||||||
mingw*|cygwin*) OS='windows';;
|
mingw* | cygwin*) OS='windows' ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +61,7 @@ runAsRoot() {
|
|||||||
# verifySupported checks that the os/arch combination is supported for
|
# verifySupported checks that the os/arch combination is supported for
|
||||||
# binary builds, as well whether or not necessary tools are present.
|
# binary builds, as well whether or not necessary tools are present.
|
||||||
verifySupported() {
|
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
|
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
|
||||||
echo "No prebuilt binary for ${OS}-${ARCH}."
|
echo "No prebuilt binary for ${OS}-${ARCH}."
|
||||||
echo "To build from source, go to https://github.com/alibaba/higress"
|
echo "To build from source, go to https://github.com/alibaba/higress"
|
||||||
@@ -94,7 +95,7 @@ checkDesiredVersion() {
|
|||||||
# if it needs to be changed.
|
# if it needs to be changed.
|
||||||
checkhgctlInstalledVersion() {
|
checkhgctlInstalledVersion() {
|
||||||
if [[ -f "${hgctl_INSTALL_DIR}/${BINARY_NAME}" ]]; then
|
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
|
if [[ "$version" == "$VERSION" ]]; then
|
||||||
echo "hgctl ${version} is already ${VERSION:-latest}"
|
echo "hgctl ${version} is already ${VERSION:-latest}"
|
||||||
return 0
|
return 0
|
||||||
@@ -111,6 +112,9 @@ checkhgctlInstalledVersion() {
|
|||||||
# for that binary.
|
# for that binary.
|
||||||
downloadFile() {
|
downloadFile() {
|
||||||
hgctl_DIST="hgctl_${VERSION}_${OS}_${ARCH}.tar.gz"
|
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"
|
DOWNLOAD_URL="https://github.com/alibaba/higress/releases/download/$VERSION/$hgctl_DIST"
|
||||||
hgctl_TMP_ROOT="$(mktemp -dt hgctl-installer-XXXXXX)"
|
hgctl_TMP_ROOT="$(mktemp -dt hgctl-installer-XXXXXX)"
|
||||||
hgctl_TMP_FILE="$hgctl_TMP_ROOT/$hgctl_DIST"
|
hgctl_TMP_FILE="$hgctl_TMP_ROOT/$hgctl_DIST"
|
||||||
@@ -133,6 +137,18 @@ installFile() {
|
|||||||
echo "$BINARY_NAME installed into $hgctl_INSTALL_DIR/$BINARY_NAME"
|
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 is executed if an error occurs.
|
||||||
fail_trap() {
|
fail_trap() {
|
||||||
result=$?
|
result=$?
|
||||||
@@ -150,9 +166,13 @@ fail_trap() {
|
|||||||
|
|
||||||
# testVersion tests the installed client to make sure it is working.
|
# testVersion tests the installed client to make sure it is working.
|
||||||
testVersion() {
|
testVersion() {
|
||||||
|
dir="$hgctl_INSTALL_DIR"
|
||||||
|
if [ "${OS}" == "windows" ]; then
|
||||||
|
dir="$hgctl_INSTALL_DIR_WINDOWS"
|
||||||
|
fi
|
||||||
set +e
|
set +e
|
||||||
if ! [ "$(command -v $BINARY_NAME)" ]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
set -e
|
set -e
|
||||||
@@ -177,7 +197,11 @@ verifySupported
|
|||||||
checkDesiredVersion
|
checkDesiredVersion
|
||||||
if ! checkhgctlInstalledVersion; then
|
if ! checkhgctlInstalledVersion; then
|
||||||
downloadFile
|
downloadFile
|
||||||
installFile
|
if [ "${OS}" == "windows" ]; then
|
||||||
|
installFileWindows
|
||||||
|
else
|
||||||
|
installFile
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
testVersion
|
testVersion
|
||||||
cleanup
|
cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user