From b6b422a609a3ffbc1f9444e2925241f3afae763f Mon Sep 17 00:00:00 2001 From: Matt Thalman Date: Wed, 15 Jan 2025 09:39:04 -0600 Subject: [PATCH 1/2] Upgrade to newer Node version in Helix WASM Dockerfiles --- src/ubuntu/20.04/helix/wasm/amd64/Dockerfile | 12 +- .../20.04/helix/wasm/amd64/setup-node-23.x.sh | 115 ++++++++++++++++++ .../22.04/helix/webassembly/amd64/Dockerfile | 4 +- .../webassembly/amd64/setup-node-18.x.sh | 45 ------- .../webassembly/amd64/setup-node-23.x.sh | 115 ++++++++++++++++++ 5 files changed, 234 insertions(+), 57 deletions(-) create mode 100644 src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh delete mode 100755 src/ubuntu/22.04/helix/webassembly/amd64/setup-node-18.x.sh create mode 100644 src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh diff --git a/src/ubuntu/20.04/helix/wasm/amd64/Dockerfile b/src/ubuntu/20.04/helix/wasm/amd64/Dockerfile index 1df772994..1abade825 100644 --- a/src/ubuntu/20.04/helix/wasm/amd64/Dockerfile +++ b/src/ubuntu/20.04/helix/wasm/amd64/Dockerfile @@ -13,23 +13,15 @@ RUN apt-get clean && \ libnode-dev \ curl \ node-gyp \ - npm \ && rm -rf /var/lib/apt/lists/* \ \ && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 -USER helixbot - # update node, which is required for newer npm, jsvu and v8 -ENV NODE_VERSION 18.18.2 -RUN cd ~ && \ - curl -LO https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz && \ - tar xf node-v${NODE_VERSION}-linux-x64.tar.xz - -USER root +COPY ./setup-node-23.x.sh /tmp +RUN /tmp/setup-node-23.x.sh && apt-get -y install nodejs -ENV PATH=/home/helixbot/node-v${NODE_VERSION}-linux-x64/bin:$PATH RUN npm install -g npm RUN npm install jsvu -g diff --git a/src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh b/src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh new file mode 100644 index 000000000..4a07a0b0b --- /dev/null +++ b/src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# +# Extracted from https://deb.nodesource.com/setup_23.x + +# Logger Function +log() { + local message="$1" + local type="$2" + local timestamp=$(date '+%Y-%m-%d %H:%M:%S') + local color + local endcolor="\033[0m" + + case "$type" in + "info") color="\033[38;5;79m" ;; + "success") color="\033[1;32m" ;; + "error") color="\033[1;31m" ;; + *) color="\033[1;34m" ;; + esac + + echo -e "${color}${timestamp} - ${message}${endcolor}" +} + +# Error handler function +handle_error() { + local exit_code=$1 + local error_message="$2" + log "Error: $error_message (Exit Code: $exit_code)" "error" + exit $exit_code +} + +# Function to check for command availability +command_exists() { + command -v "$1" &> /dev/null +} + +check_os() { + if ! [ -f "/etc/debian_version" ]; then + echo "Error: This script is only supported on Debian-based systems." + exit 1 + fi +} + +# Function to Install the script pre-requisites +install_pre_reqs() { + log "Installing pre-requisites" "info" + + # Run 'apt-get update' + if ! apt-get update -y; then + handle_error "$?" "Failed to run 'apt-get update'" + fi + + # Run 'apt-get install' + if ! apt-get install -y apt-transport-https ca-certificates curl gnupg; then + handle_error "$?" "Failed to install packages" + fi + + if ! mkdir -p /usr/share/keyrings; then + handle_error "$?" "Makes sure the path /usr/share/keyrings exist or run ' mkdir -p /usr/share/keyrings' with sudo" + fi + + rm -f /usr/share/keyrings/nodesource.gpg || true + rm -f /etc/apt/sources.list.d/nodesource.list || true + + # Run 'curl' and 'gpg' to download and import the NodeSource signing key + if ! curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg; then + handle_error "$?" "Failed to download and import the NodeSource signing key" + fi + + # Explicitly set the permissions to ensure the file is readable by all + if ! chmod 644 /usr/share/keyrings/nodesource.gpg; then + handle_error "$?" "Failed to set correct permissions on /usr/share/keyrings/nodesource.gpg" + fi +} + +# Function to configure the Repo +configure_repo() { + local node_version=$1 + + arch=$(dpkg --print-architecture) + if [ "$arch" != "amd64" ] && [ "$arch" != "arm64" ] && [ "$arch" != "armhf" ]; then + handle_error "1" "Unsupported architecture: $arch. Only amd64, arm64, and armhf are supported." + fi + + echo "deb [arch=$arch signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$node_version nodistro main" | tee /etc/apt/sources.list.d/nodesource.list > /dev/null + + # N|solid Config + echo "Package: nsolid" | tee /etc/apt/preferences.d/nsolid > /dev/null + echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nsolid > /dev/null + echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nsolid > /dev/null + + # Nodejs Config + echo "Package: nodejs" | tee /etc/apt/preferences.d/nodejs > /dev/null + echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nodejs > /dev/null + echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nodejs > /dev/null + + # Run 'apt-get update' + if ! apt-get update -y; then + handle_error "$?" "Failed to run 'apt-get update'" + else + log "Repository configured successfully." + log "To install Node.js, run: apt-get install nodejs -y" "info" + log "You can use N|solid Runtime as a node.js alternative" "info" + log "To install N|solid Runtime, run: apt-get install nsolid -y \n" "success" + fi +} + +# Define Node.js version +NODE_VERSION="23.x" + +# Check OS +check_os + +# Main execution +install_pre_reqs || handle_error $? "Failed installing pre-requisites" +configure_repo "$NODE_VERSION" || handle_error $? "Failed configuring repository" diff --git a/src/ubuntu/22.04/helix/webassembly/amd64/Dockerfile b/src/ubuntu/22.04/helix/webassembly/amd64/Dockerfile index 1f80a6b50..f587debee 100644 --- a/src/ubuntu/22.04/helix/webassembly/amd64/Dockerfile +++ b/src/ubuntu/22.04/helix/webassembly/amd64/Dockerfile @@ -37,8 +37,8 @@ RUN wget https://cmake.org/files/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.0-Linu RUN locale-gen en_US.UTF-8 # install node, which is required for newer npm, jsvu and v8 -COPY ./setup-node-18.x.sh /tmp -RUN /tmp/setup-node-18.x.sh && apt-get -y install nodejs +COPY ./setup-node-23.x.sh /tmp +RUN /tmp/setup-node-23.x.sh && apt-get -y install nodejs RUN npm install -g npm RUN npm install jsvu -g diff --git a/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-18.x.sh b/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-18.x.sh deleted file mode 100755 index 2198f86c0..000000000 --- a/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-18.x.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -# -# Extracted from https://deb.nodesource.com/setup_18.x - -export DEBIAN_FRONTEND=noninteractive -NODENAME="Node.js 18.x" -NODEREPO="node_18.x" - -print_status() { - echo - echo "## $1" - echo -} - -bail() { - echo 'Error executing command, exiting' - exit 1 -} - -exec_cmd_nobail() { - echo "+ $1" - bash -c "$1" -} - -exec_cmd() { - exec_cmd_nobail "$1" || bail -} - -DISTRO=$(lsb_release -c -s) - -exec_cmd "curl -sLf -o /dev/null 'https://deb.nodesource.com/${NODEREPO}/dists/${DISTRO}/Release'" - -print_status 'Adding the NodeSource signing key to your keyring...' -keyring='/usr/share/keyrings' -node_key_url="https://deb.nodesource.com/gpgkey/nodesource.gpg.key" -local_node_key="$keyring/nodesource.gpg" - -exec_cmd "curl -s $node_key_url | gpg --dearmor | tee $local_node_key >/dev/null" - -print_status "Creating apt sources list file for the NodeSource ${NODENAME} repo..." - -exec_cmd "echo 'deb [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list" -exec_cmd "echo 'deb-src [signed-by=$local_node_key] https://deb.nodesource.com/${NODEREPO} ${DISTRO} main' >> /etc/apt/sources.list.d/nodesource.list" - -exec_cmd 'apt-get update' diff --git a/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh b/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh new file mode 100644 index 000000000..4a07a0b0b --- /dev/null +++ b/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# +# Extracted from https://deb.nodesource.com/setup_23.x + +# Logger Function +log() { + local message="$1" + local type="$2" + local timestamp=$(date '+%Y-%m-%d %H:%M:%S') + local color + local endcolor="\033[0m" + + case "$type" in + "info") color="\033[38;5;79m" ;; + "success") color="\033[1;32m" ;; + "error") color="\033[1;31m" ;; + *) color="\033[1;34m" ;; + esac + + echo -e "${color}${timestamp} - ${message}${endcolor}" +} + +# Error handler function +handle_error() { + local exit_code=$1 + local error_message="$2" + log "Error: $error_message (Exit Code: $exit_code)" "error" + exit $exit_code +} + +# Function to check for command availability +command_exists() { + command -v "$1" &> /dev/null +} + +check_os() { + if ! [ -f "/etc/debian_version" ]; then + echo "Error: This script is only supported on Debian-based systems." + exit 1 + fi +} + +# Function to Install the script pre-requisites +install_pre_reqs() { + log "Installing pre-requisites" "info" + + # Run 'apt-get update' + if ! apt-get update -y; then + handle_error "$?" "Failed to run 'apt-get update'" + fi + + # Run 'apt-get install' + if ! apt-get install -y apt-transport-https ca-certificates curl gnupg; then + handle_error "$?" "Failed to install packages" + fi + + if ! mkdir -p /usr/share/keyrings; then + handle_error "$?" "Makes sure the path /usr/share/keyrings exist or run ' mkdir -p /usr/share/keyrings' with sudo" + fi + + rm -f /usr/share/keyrings/nodesource.gpg || true + rm -f /etc/apt/sources.list.d/nodesource.list || true + + # Run 'curl' and 'gpg' to download and import the NodeSource signing key + if ! curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg; then + handle_error "$?" "Failed to download and import the NodeSource signing key" + fi + + # Explicitly set the permissions to ensure the file is readable by all + if ! chmod 644 /usr/share/keyrings/nodesource.gpg; then + handle_error "$?" "Failed to set correct permissions on /usr/share/keyrings/nodesource.gpg" + fi +} + +# Function to configure the Repo +configure_repo() { + local node_version=$1 + + arch=$(dpkg --print-architecture) + if [ "$arch" != "amd64" ] && [ "$arch" != "arm64" ] && [ "$arch" != "armhf" ]; then + handle_error "1" "Unsupported architecture: $arch. Only amd64, arm64, and armhf are supported." + fi + + echo "deb [arch=$arch signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$node_version nodistro main" | tee /etc/apt/sources.list.d/nodesource.list > /dev/null + + # N|solid Config + echo "Package: nsolid" | tee /etc/apt/preferences.d/nsolid > /dev/null + echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nsolid > /dev/null + echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nsolid > /dev/null + + # Nodejs Config + echo "Package: nodejs" | tee /etc/apt/preferences.d/nodejs > /dev/null + echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nodejs > /dev/null + echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nodejs > /dev/null + + # Run 'apt-get update' + if ! apt-get update -y; then + handle_error "$?" "Failed to run 'apt-get update'" + else + log "Repository configured successfully." + log "To install Node.js, run: apt-get install nodejs -y" "info" + log "You can use N|solid Runtime as a node.js alternative" "info" + log "To install N|solid Runtime, run: apt-get install nsolid -y \n" "success" + fi +} + +# Define Node.js version +NODE_VERSION="23.x" + +# Check OS +check_os + +# Main execution +install_pre_reqs || handle_error $? "Failed installing pre-requisites" +configure_repo "$NODE_VERSION" || handle_error $? "Failed configuring repository" From 6d35d58546056f064a50dd8402b6bb266a19a816 Mon Sep 17 00:00:00 2001 From: Matt Thalman Date: Wed, 15 Jan 2025 10:34:57 -0600 Subject: [PATCH 2/2] set executable permissions on script files --- src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh | 0 src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh mode change 100644 => 100755 src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh diff --git a/src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh b/src/ubuntu/20.04/helix/wasm/amd64/setup-node-23.x.sh old mode 100644 new mode 100755 diff --git a/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh b/src/ubuntu/22.04/helix/webassembly/amd64/setup-node-23.x.sh old mode 100644 new mode 100755