Skip to content

Commit ef5231c

Browse files
marunmaru-ava
andauthored
[ci] Use go env {GOOS,GOARCH} for os and arch detection (#3661)
Co-authored-by: Maru Newby <maru.newby@avalabs.org>
1 parent a152a52 commit ef5231c

File tree

3 files changed

+16
-45
lines changed

3 files changed

+16
-45
lines changed

scripts/run_prometheus.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,19 @@ if ! command -v "${CMD}" &> /dev/null; then
6161
if ! command -v "${CMD}" &> /dev/null; then
6262
echo "prometheus not found, attempting to install..."
6363

64-
# Determine the arch
65-
if which sw_vers &> /dev/null; then
64+
GOOS="$(go env GOOS)"
65+
GOARCH="$(go env GOARCH)"
66+
if [[ "${GOOS}" == "darwin" && "${GOARCH}" == "arm64" ]]; then
6667
echo "On macos, only amd64 binaries are available so rosetta is required on apple silicon machines."
6768
echo "To avoid using rosetta, install via homebrew: brew install prometheus"
68-
DIST=darwin
69-
else
70-
ARCH="$(uname -i)"
71-
if [[ "${ARCH}" != "x86_64" ]]; then
72-
echo "On linux, only amd64 binaries are available. manual installation of prometheus is required."
69+
fi
70+
if [[ "${GOOS}" == "linux" && "${GOARCH}" != "amd64" ]]; then
71+
echo "On linux, only amd64 binaries are available. Manual installation of prometheus is required."
7372
exit 1
74-
else
75-
DIST="linux"
76-
fi
7773
fi
7874

7975
# Install the specified release
80-
PROMETHEUS_FILE="prometheus-${VERSION}.${DIST}-amd64"
76+
PROMETHEUS_FILE="prometheus-${VERSION}.${GOOS}-amd64"
8177
URL="https://github.com/prometheus/prometheus/releases/download/v${VERSION}/${PROMETHEUS_FILE}.tar.gz"
8278
curl -s -L "${URL}" | tar zxv -C /tmp > /dev/null
8379
mkdir -p "$(dirname "${CMD}")"

scripts/run_promtail.sh

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,11 @@ if ! command -v "${CMD}" &> /dev/null; then
5757
CMD="${PWD}/bin/promtail"
5858
if ! command -v "${CMD}" &> /dev/null; then
5959
echo "promtail not found, attempting to install..."
60-
# Determine the arch
61-
if which sw_vers &> /dev/null; then
62-
DIST="darwin-$(uname -m)"
63-
else
64-
ARCH="$(uname -i)"
65-
if [[ "${ARCH}" == "aarch64" ]]; then
66-
ARCH="arm64"
67-
elif [[ "${ARCH}" == "x86_64" ]]; then
68-
ARCH="amd64"
69-
fi
70-
DIST="linux-${ARCH}"
71-
fi
60+
61+
# Determine the platform
62+
GOOS="$(go env GOOS)"
63+
GOARCH="$(go env GOARCH)"
64+
DIST="${GOOS}-${GOARCH}"
7265

7366
# Install the specified release
7467
PROMTAIL_FILE="promtail-${DIST}"

scripts/tests.e2e.bootstrap_monitor.sh

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,8 @@ if ! [[ "$0" =~ scripts/tests.e2e.bootstrap_monitor.sh ]]; then
99
exit 255
1010
fi
1111

12-
# Determine DIST and ARCH in case installation is required for kubectl and kind
13-
#
14-
# TODO(marun) Factor this out for reuse
15-
if which sw_vers &> /dev/null; then
16-
OS="darwin"
17-
ARCH="$(uname -m)"
18-
else
19-
# Assume linux (windows is not supported)
20-
OS="linux"
21-
RAW_ARCH="$(uname -i)"
22-
# Convert the linux arch string to the string used for k8s releases
23-
if [[ "${RAW_ARCH}" == "aarch64" ]]; then
24-
ARCH="arm64"
25-
elif [[ "${RAW_ARCH}" == "x86_64" ]]; then
26-
ARCH="amd64"
27-
else
28-
echo "Unsupported architecture: ${RAW_ARCH}"
29-
exit 1
30-
fi
31-
fi
12+
GOOS="$(go env GOOS)"
13+
GOARCH="$(go env GOARCH)"
3214

3315
function ensure_command {
3416
local cmd=$1
@@ -49,11 +31,11 @@ function ensure_command {
4931

5032
# Ensure the kubectl command is available
5133
KUBECTL_VERSION=v1.30.2
52-
ensure_command kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${OS}/${ARCH}/kubectl"
34+
ensure_command kubectl "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${GOOS}/${GOARCH}/kubectl"
5335

5436
# Ensure the kind command is available
5537
KIND_VERSION=v0.23.0
56-
ensure_command kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${OS}-${ARCH}"
38+
ensure_command kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-${GOOS}-${GOARCH}"
5739

5840
# Ensure the kind-with-registry command is available
5941
ensure_command "kind-with-registry.sh" "https://raw.githubusercontent.com/kubernetes-sigs/kind/7cb9e6be25b48a0e248097eef29d496ab1a044d0/site/static/examples/kind-with-registry.sh"

0 commit comments

Comments
 (0)