Skip to content

Commit aeb4a1b

Browse files
Merge pull request #34 from ava-labs/devcontainer-avalanchego-binary-install-script
2 parents 696e94e + 5257cac commit aeb4a1b

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed

.devcontainer/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ ENV AVALANCHEGO_PLUGIN_PATH=$GOPATH/src/github.com/ava-labs/avalanchego/build/pl
77

88
# Download AvalancheGo Binary
99
WORKDIR /
10-
COPY versions.sh /
11-
RUN bash -c 'source /versions.sh && curl -LJ -o avalanchego.tar.gz "https://github.com/ava-labs/avalanchego/releases/download/{$AVALANCHEGO_VERSION}/avalanchego-linux-amd64-{$AVALANCHEGO_VERSION}.tar.gz"'
12-
RUN tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego
13-
RUN rm avalanchego.tar.gz
10+
COPY ./scripts/versions.sh /
11+
COPY ./.devcontainer/install_avalanchego.sh /
12+
1413
ENV AVALANCHEGO_EXEC_PATH=/avalanchego
1514

15+
RUN bash -c "source ./install_avalanchego.sh"
16+
1617
# Install Node.js and npm using the official Node.js image
1718
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs
1819

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
"build": {
77
"dockerfile": "Dockerfile",
8-
"context": "../scripts/"
8+
"context": "../"
99
},
1010
"runArgs": ["--network=host"],
1111

.devcontainer/install_avalanchego.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
# Pulls latest pre-built node binary from GitHub
3+
4+
#stop on errors
5+
set -e
6+
7+
#helper function to check for presence of required commands, and install if missing
8+
check_reqs_deb () {
9+
if ! command -v curl &> /dev/null
10+
then
11+
echo "curl could not be found, will install..."
12+
apt-get install curl -y
13+
fi
14+
}
15+
check_reqs_rhel () {
16+
if ! command -v curl &> /dev/null
17+
then
18+
echo "curl could not be found, will install..."
19+
dnf install curl -y
20+
fi
21+
if ! command -v wget &> /dev/null
22+
then
23+
echo "wget could not be found, will install..."
24+
dnf install wget -y
25+
fi
26+
if ! command -v dig &> /dev/null
27+
then
28+
echo "dig could not be found, will install..."
29+
dnf install bind-utils -y
30+
fi
31+
if ! command -v semanage &> /dev/null
32+
then
33+
echo "semanage could not be found, will install..."
34+
dnf install policycoreutils-python-utils -y
35+
fi
36+
if ! command -v restorecon &> /dev/null
37+
then
38+
echo "restorecon could not be found, will install..."
39+
dnf install policycoreutils -y
40+
fi
41+
}
42+
# Helper function to get OS Type
43+
getOsType () {
44+
which yum 1>/dev/null 2>&1 && { echo "RHEL"; return; }
45+
which zypper 1>/dev/null 2>&1 && { echo "openSUSE"; return; }
46+
which apt-get 1>/dev/null 2>&1 && { echo "Debian"; return; }
47+
}
48+
49+
# Installing necessary system dependencies for AvalacheGO
50+
osType=$(getOsType)
51+
if [ "$osType" = "Debian" ]; then
52+
check_reqs_deb
53+
elif [ "$osType" = "RHEL" ]; then
54+
check_reqs_rhel
55+
else
56+
#sorry, don't know you.
57+
echo "Unsupported linux flavour/distribution: $osType"
58+
echo "Exiting."
59+
exit
60+
fi
61+
62+
# Define architecture
63+
foundArch="$(uname -m)"
64+
65+
if [ "$foundArch" = "aarch64" ]; then
66+
getArch="arm64" #we're running on arm arch (probably RasPi)
67+
echo "Found arm64 architecture..."
68+
elif [ "$foundArch" = "x86_64" ]; then
69+
getArch="amd64" #we're running on intel/amd
70+
echo "Found amd64 architecture..."
71+
elif [ "$foundArch" = "arm64" ]; then
72+
getArch="arm64" #we're running on intel/amd
73+
echo "Found arm64 architecture..."
74+
else
75+
#sorry, don't know you.
76+
echo "Unsupported architecture: $foundArch!"
77+
echo "Exiting."
78+
exit
79+
fi
80+
81+
# Import environment variables
82+
source ./versions.sh
83+
84+
# Download AvalancheGo binary
85+
curl -LJ -o avalanchego.tar.gz "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz"
86+
tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego
87+
rm avalanchego.tar.gz

0 commit comments

Comments
 (0)