Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download AvalancheGo Binary using versions.sh instead of cloning #31

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
# Use a base image that includes both Go and Node.js, such as the official Go image
FROM golang:latest


ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin
ENV AVALANCHEGO_EXEC_PATH=$GOPATH/src/github.com/ava-labs/avalanchego/build/avalanchego
ENV AVALANCHEGO_PLUGIN_PATH=$GOPATH/src/github.com/ava-labs/avalanchego/build/plugins

# Install Node.js and npm using the official Node.js image
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install -y nodejs

# Clone the avalanchego repository
RUN git clone -b v1.10.5 https://github.com/ava-labs/avalanchego.git $GOPATH/src/github.com/ava-labs/avalanchego
# Download AvalancheGo Binary
WORKDIR /
COPY ./scripts/versions.sh /
COPY ./.devcontainer/install_avalanchego.sh /

# Set the working directory to the cloned repository
WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego
ENV AVALANCHEGO_EXEC_PATH=/avalanchego

# Build the avalanchego project using the sh script
RUN ./scripts/build.sh
RUN bash -c "source ./install_avalanchego.sh"

# Install Avalanche Network Runner
RUN curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s

ENV PATH ~/bin:$PATH
15 changes: 7 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
"name": "Avalanche-DevContainer",

"build": {
"dockerfile": "Dockerfile"
"dockerfile": "Dockerfile",
"context": "../"
},
"runArgs": ["--network=host"],

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "latest"
}
},

"features": {
"ghcr.io/devcontainers/features/node:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8080,
Expand All @@ -27,7 +26,7 @@
],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash scripts/build.sh",
"postCreateCommand": "bash scripts/build.sh && cd ./contracts && npm install",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
Expand Down
87 changes: 87 additions & 0 deletions .devcontainer/install_avalanchego.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Pulls latest pre-built node binary from GitHub

#stop on errors
set -e

#helper function to check for presence of required commands, and install if missing
check_reqs_deb () {
if ! command -v curl &> /dev/null
then
echo "curl could not be found, will install..."
apt-get install curl -y
fi
}
check_reqs_rhel () {
if ! command -v curl &> /dev/null
then
echo "curl could not be found, will install..."
dnf install curl -y
fi
if ! command -v wget &> /dev/null
then
echo "wget could not be found, will install..."
dnf install wget -y
fi
if ! command -v dig &> /dev/null
then
echo "dig could not be found, will install..."
dnf install bind-utils -y
fi
if ! command -v semanage &> /dev/null
then
echo "semanage could not be found, will install..."
dnf install policycoreutils-python-utils -y
fi
if ! command -v restorecon &> /dev/null
then
echo "restorecon could not be found, will install..."
dnf install policycoreutils -y
fi
}
# Helper function to get OS Type
getOsType () {
which yum 1>/dev/null 2>&1 && { echo "RHEL"; return; }
which zypper 1>/dev/null 2>&1 && { echo "openSUSE"; return; }
which apt-get 1>/dev/null 2>&1 && { echo "Debian"; return; }
}

# Installing necessary system dependencies for AvalacheGO
osType=$(getOsType)
if [ "$osType" = "Debian" ]; then
check_reqs_deb
elif [ "$osType" = "RHEL" ]; then
check_reqs_rhel
else
#sorry, don't know you.
echo "Unsupported linux flavour/distribution: $osType"
echo "Exiting."
exit
fi

# Define architecture
foundArch="$(uname -m)"

if [ "$foundArch" = "aarch64" ]; then
getArch="arm64" #we're running on arm arch (probably RasPi)
echo "Found arm64 architecture..."
elif [ "$foundArch" = "x86_64" ]; then
getArch="amd64" #we're running on intel/amd
echo "Found amd64 architecture..."
elif [ "$foundArch" = "arm64" ]; then
getArch="arm64" #we're running on intel/amd
echo "Found arm64 architecture..."
else
#sorry, don't know you.
echo "Unsupported architecture: $foundArch!"
echo "Exiting."
exit
fi

# Import environment variables
source ./versions.sh

# Download AvalancheGo binary
curl -LJ -o avalanchego.tar.gz "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz"
tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego
rm avalanchego.tar.gz