diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index aec6ad6..6e4946c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 69229c6..8df9a08 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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, @@ -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" diff --git a/.devcontainer/install_avalanchego.sh b/.devcontainer/install_avalanchego.sh new file mode 100644 index 0000000..6be8655 --- /dev/null +++ b/.devcontainer/install_avalanchego.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# 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