From 0f5bc500c38ba5b7aee622a79b558da66eb67ac4 Mon Sep 17 00:00:00 2001 From: "Balasankar \"Balu\" C" Date: Tue, 5 Jul 2022 11:11:57 +0530 Subject: [PATCH] Support building NodeJS in UBI Signed-off-by: Balasankar "Balu" C --- scripts/install-node | 59 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/scripts/install-node b/scripts/install-node index 9d60e69..921040e 100755 --- a/scripts/install-node +++ b/scripts/install-node @@ -8,19 +8,54 @@ YARN_INSTALL_VERSION=${2:-1.22.17} # Map MAJOR.MINOR.patch -> MAJOR.x NODE_MAJOR=`echo $NODE_INSTALL_VERSION | sed -r -e "s/([0-9]+)\.[0-9]+.*/\1\.x/g"` -# add official debian repos for node -curl -sS -L https://deb.nodesource.com/setup_${NODE_MAJOR} | bash - +function build_debian() { + # add official debian repos for node + curl -sS -L https://deb.nodesource.com/setup_${NODE_MAJOR} | bash - -apt-get update + apt-get update -NODE_FILE_NAME="nodejs_$NODE_INSTALL_VERSION-deb-1nodesource1_$(dpkg --print-architecture).deb" -curl -s -O "https://deb.nodesource.com/node_$NODE_MAJOR/pool/main/n/nodejs/$NODE_FILE_NAME" -dpkg -i "$NODE_FILE_NAME" -rm -f "$NODE_FILE_NAME" + NODE_FILE_NAME="nodejs_$NODE_INSTALL_VERSION-deb-1nodesource1_${BUILD_ARCH}.deb" + curl -s -O "https://deb.nodesource.com/node_$NODE_MAJOR/pool/main/n/nodejs/$NODE_FILE_NAME" + dpkg -i "$NODE_FILE_NAME" + rm -f "$NODE_FILE_NAME" -npm install --global yarn@${YARN_INSTALL_VERSION} -npm cache clean --force + npm install --global yarn@${YARN_INSTALL_VERSION} + npm cache clean --force -apt-get autoremove -yq -apt-get clean -yqq -rm -rf /var/lib/apt/lists/* + apt-get autoremove -yq + apt-get clean -yqq + rm -rf /var/lib/apt/lists/* +} + +function build_ubi() { + # For rpms, node uses `x86_64` suffix and not `amd64`. So we can't use + # existing `BUILD_ARCH` (which says amd64/arm64) here. + BUILD_ARCH=$(arch) + + UBI_VERSION=$(lsb_release -a | awk '/Release/ { print $2 }') + UBI_MAJOR_VERSION=${UBI_VERSION%.*} # strip last component + + # add official rhel repos for node + curl -fsSL https://rpm.nodesource.com/setup_${NODE_MAJOR} | bash - + + yum update -y + + NODE_FILE_NAME="nodejs-${NODE_INSTALL_VERSION}-1nodesource.${BUILD_ARCH}.rpm" + curl -s -O "https://rpm.nodesource.com/pub_${NODE_MAJOR}/el/${UBI_MAJOR_VERSION}/${BUILD_ARCH}/${NODE_FILE_NAME}" + yum install -y "$NODE_FILE_NAME" + rm -f "$NODE_FILE_NAME" + + npm install --global yarn@${YARN_INSTALL_VERSION} + npm cache clean --force + + yum autoremove -y + yum clean -y all +} + +BUILD_OS=${BUILD_OS:-debian} + +if [[ $BUILD_OS =~ debian ]]; then + build_debian "$@" +elif [[ $BUILD_OS =~ ubi ]]; then + build_ubi "$@" +fi