From ae5da2cdcbc69dd18c2c8e655cad51bd802ba497 Mon Sep 17 00:00:00 2001 From: Martin Eckardt Date: Mon, 14 Aug 2023 20:01:48 +0000 Subject: [PATCH 1/6] Download AvalancheGo Binary instead of cloning repo and building --- .devcontainer/Dockerfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index aec6ad6..aee9f6a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -4,20 +4,19 @@ 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 +WORKDIR / -# Set the working directory to the cloned repository -WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego +# # Build the avalanchego project using the sh script +RUN curl -LJO https://github.com/ava-labs/avalanchego/releases/download/v1.10.5/avalanchego-linux-amd64-v1.10.5.tar.gz +RUN tar -xzf avalanchego-linux-amd64-v1.10.5.tar.gz +RUN mv avalanchego-v1.10.5 avalanchego -# Build the avalanchego project using the sh script -RUN ./scripts/build.sh +ENV AVALANCHEGO_EXEC_PATH=/avalanchego/avalanchego RUN curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s From 17875462fe216fbc143a6c068983f0ee8ddd4301 Mon Sep 17 00:00:00 2001 From: Rodrigo Villar Date: Mon, 14 Aug 2023 16:57:42 -0400 Subject: [PATCH 2/6] remove avalanchego version reference --- .devcontainer/Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index aee9f6a..2e23541 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -12,11 +12,11 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && apt-get install WORKDIR / # # Build the avalanchego project using the sh script -RUN curl -LJO https://github.com/ava-labs/avalanchego/releases/download/v1.10.5/avalanchego-linux-amd64-v1.10.5.tar.gz -RUN tar -xzf avalanchego-linux-amd64-v1.10.5.tar.gz -RUN mv avalanchego-v1.10.5 avalanchego - -ENV AVALANCHEGO_EXEC_PATH=/avalanchego/avalanchego +RUN curl -LJ -o avalanchego.tar.gz https://github.com/ava-labs/avalanchego/releases/download/v1.10.5/avalanchego-linux-amd64-v1.10.5.tar.gz +RUN mkdir avalanchego +RUN tar -xzf avalanchego.tar.gz --wildcards '*/avalanchego' --strip-components=1 -C /avalanchego +RUN rm avalanchego.tar.gz +ENV AVALANCHEGO_EXEC_PATH=/avalanchego RUN curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s From 696e94ee9861605d686e5807011dd8087a89b9a8 Mon Sep 17 00:00:00 2001 From: Martin Eckardt Date: Mon, 14 Aug 2023 23:01:03 +0000 Subject: [PATCH 3/6] Load version from scripts/versions.sh --- .devcontainer/Dockerfile | 15 +++++++-------- .devcontainer/devcontainer.json | 3 ++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 2e23541..8af84da 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,23 +1,22 @@ # 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_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 - +# Download AvalancheGo Binary WORKDIR / - -# # Build the avalanchego project using the sh script -RUN curl -LJ -o avalanchego.tar.gz https://github.com/ava-labs/avalanchego/releases/download/v1.10.5/avalanchego-linux-amd64-v1.10.5.tar.gz -RUN mkdir avalanchego +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 ENV AVALANCHEGO_EXEC_PATH=/avalanchego +# 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 + +# 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..39572a8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,8 @@ "name": "Avalanche-DevContainer", "build": { - "dockerfile": "Dockerfile" + "dockerfile": "Dockerfile", + "context": "../scripts/" }, "runArgs": ["--network=host"], From 325c041264428447b4c9f887e1fa2318c7a175fe Mon Sep 17 00:00:00 2001 From: Rodrigo Villar Date: Wed, 16 Aug 2023 14:14:24 -0400 Subject: [PATCH 4/6] 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 5/6] 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 From cfc971a7ae199b641750a77ad845698637daf7e3 Mon Sep 17 00:00:00 2001 From: Rodrigo Villar Date: Wed, 16 Aug 2023 16:54:03 -0400 Subject: [PATCH 6/6] add node feature --- .devcontainer/Dockerfile | 3 --- .devcontainer/devcontainer.json | 12 +++++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index bee3d6e..6e4946c 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -14,9 +14,6 @@ ENV AVALANCHEGO_EXEC_PATH=/avalanchego 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 - # Install Avalanche Network Runner RUN curl -sSfL https://raw.githubusercontent.com/ava-labs/avalanche-network-runner/main/scripts/install.sh | sh -s diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 29c8f43..8df9a08 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,12 +10,10 @@ "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, @@ -28,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"