From 325c041264428447b4c9f887e1fa2318c7a175fe Mon Sep 17 00:00:00 2001 From: Rodrigo Villar Date: Wed, 16 Aug 2023 14:14:24 -0400 Subject: [PATCH 1/2] start install.sh --- .devcontainer/Dockerfile | 9 ++-- .devcontainer/devcontainer.json | 2 +- .devcontainer/install.sh | 93 +++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 .devcontainer/install.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8af84da..1980470 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,12 +7,13 @@ ENV AVALANCHEGO_PLUGIN_PATH=$GOPATH/src/github.com/ava-labs/avalanchego/build/pl # Download AvalancheGo Binary WORKDIR / -COPY versions.sh / -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"' -RUN tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego -RUN rm avalanchego.tar.gz +COPY ./scripts/versions.sh / +COPY ./.devcontainer/install.sh / + ENV AVALANCHEGO_EXEC_PATH=/avalanchego +RUN bash -c "source ./install.sh" + # 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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 39572a8..29c8f43 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ "build": { "dockerfile": "Dockerfile", - "context": "../scripts/" + "context": "../" }, "runArgs": ["--network=host"], diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh new file mode 100644 index 0000000..25bbaac --- /dev/null +++ b/.devcontainer/install.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# Pulls latest pre-built node binary from GitHub +# Context of container, NOT local workspace + +#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 + +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 +echo $AVALANCHEGO_VERSION +echo $getArch +echo "PRINTED AGO VERSION!" + +# Download AvalancheGo binary +echo "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz" +curl -LJ -o avalanchego.tar.gz "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz" +echo "DOWNLOADED TAR FILE" +tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego +echo "TARRED THE FILE!" +rm avalanchego.tar.gz From 5257cacef585ca8431c2352481b9eedfb134e31b Mon Sep 17 00:00:00 2001 From: Rodrigo Villar Date: Wed, 16 Aug 2023 15:04:24 -0400 Subject: [PATCH 2/2] incorporate martin feedback --- .devcontainer/Dockerfile | 4 ++-- .devcontainer/{install.sh => install_avalanchego.sh} | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) rename .devcontainer/{install.sh => install_avalanchego.sh} (89%) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 1980470..bee3d6e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -8,11 +8,11 @@ ENV AVALANCHEGO_PLUGIN_PATH=$GOPATH/src/github.com/ava-labs/avalanchego/build/pl # Download AvalancheGo Binary WORKDIR / COPY ./scripts/versions.sh / -COPY ./.devcontainer/install.sh / +COPY ./.devcontainer/install_avalanchego.sh / ENV AVALANCHEGO_EXEC_PATH=/avalanchego -RUN bash -c "source ./install.sh" +RUN bash -c "source ./install_avalanchego.sh" # 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 diff --git a/.devcontainer/install.sh b/.devcontainer/install_avalanchego.sh similarity index 89% rename from .devcontainer/install.sh rename to .devcontainer/install_avalanchego.sh index 25bbaac..6be8655 100644 --- a/.devcontainer/install.sh +++ b/.devcontainer/install_avalanchego.sh @@ -1,6 +1,5 @@ #!/bin/bash # Pulls latest pre-built node binary from GitHub -# Context of container, NOT local workspace #stop on errors set -e @@ -60,6 +59,7 @@ else exit fi +# Define architecture foundArch="$(uname -m)" if [ "$foundArch" = "aarch64" ]; then @@ -80,14 +80,8 @@ fi # Import environment variables source ./versions.sh -echo $AVALANCHEGO_VERSION -echo $getArch -echo "PRINTED AGO VERSION!" # Download AvalancheGo binary -echo "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz" curl -LJ -o avalanchego.tar.gz "https://github.com/ava-labs/avalanchego/releases/download/$AVALANCHEGO_VERSION/avalanchego-linux-$getArch-$AVALANCHEGO_VERSION.tar.gz" -echo "DOWNLOADED TAR FILE" tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego -echo "TARRED THE FILE!" rm avalanchego.tar.gz