From d17ee7d99ef32074d8ebf6c0859803055d426a3a Mon Sep 17 00:00:00 2001 From: Hugo Hromic Date: Sat, 23 Sep 2023 22:00:28 +0100 Subject: [PATCH] fix(dev): update environment for website development The `nodejs` and `npm` packages installed from the stock Ubuntu Focal repository are outdated for the current website dependencies. This commit installs an updated Node.js (current LTS version) directly from the NodeSource repository instead. The `yarn` package in the stock Ubuntu Focal repository is not the Yarn package manager. The package is actually an alias package for the unrelated `cmdtest` package (ref: ). This commit installs (enables) the correct `yarn` command using the same updated Node.js installation above. Website development requires two tools not currently installed in the environment: * Hugo (static site generator). * htmltest (HTML checker for the website content). This commit also installs these tools directly from their GitHub release assets. In the case of Hugo, the installed version matches the version currently specified in 'netlify.toml'. In addition to all the above, this commit also improves the Ubuntu bootstrap script: * Switches `apt` for `apt-get` as recommended for non-interactive scripts. * Add missing temporary directory cleaning commands. After all the above changes, the following now works properly in `website/` in the environment: make serve make local-preview-build Signed-off-by: Hugo Hromic --- scripts/environment/bootstrap-ubuntu-20.04.sh | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/scripts/environment/bootstrap-ubuntu-20.04.sh b/scripts/environment/bootstrap-ubuntu-20.04.sh index b5eedad16afca..1c03e031ce843 100755 --- a/scripts/environment/bootstrap-ubuntu-20.04.sh +++ b/scripts/environment/bootstrap-ubuntu-20.04.sh @@ -13,17 +13,17 @@ export ACCEPT_EULA=Y echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/80-retries -apt update --yes +apt-get update --yes -apt install --yes \ +apt-get install --yes \ software-properties-common \ apt-utils \ apt-transport-https -apt upgrade --yes +apt-get upgrade --yes # Deps -apt install --yes --no-install-recommends \ +apt-get install --yes --no-install-recommends \ awscli \ build-essential \ ca-certificates \ @@ -40,8 +40,6 @@ apt install --yes --no-install-recommends \ libssl-dev \ llvm \ locales \ - nodejs \ - npm \ pkg-config \ python3-pip \ rename \ @@ -50,8 +48,7 @@ apt install --yes --no-install-recommends \ shellcheck \ sudo \ unzip \ - wget \ - yarn + wget # Cue TEMP=$(mktemp -d) @@ -62,6 +59,7 @@ tar \ -xvf "${TEMP}/cue_v0.5.0_linux_amd64.tar.gz" \ -C "${TEMP}" cp "${TEMP}/cue" /usr/bin/cue +rm -rf "$TEMP" # Grease # Grease is used for the `make release-github` task. @@ -73,6 +71,7 @@ tar \ -xvf "${TEMP}/grease-1.0.1-linux-amd64.tar.gz" \ -C "${TEMP}" cp "${TEMP}/grease/bin/grease" /usr/bin/grease +rm -rf "$TEMP" # Locales locale-gen en_US.UTF-8 @@ -102,8 +101,8 @@ if ! [ -x "$(command -v docker)" ]; then xenial \ stable" # Install those new things - apt update --yes - apt install --yes docker-ce docker-ce-cli containerd.io + apt-get update --yes + apt-get install --yes docker-ce docker-ce-cli containerd.io # ubuntu user doesn't exist in scripts/environment/Dockerfile which runs this usermod --append --groups docker ubuntu || true @@ -117,8 +116,49 @@ fi bash scripts/environment/install-protoc.sh +# Node.js, npm and yarn. +# Note: the current LTS for the Node.js toolchain is 18.x +if ! [ -x "$(command -v node)" ]; then + curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | apt-key add - + add-apt-repository \ + "deb [arch=$(dpkg --print-architecture)] https://deb.nodesource.com/node_18.x \ + nodistro \ + main" + # Install those new things + apt-get update --yes + apt-get install --yes nodejs + + # enable corepack (enables the yarn and pnpm package managers) + # ref: https://nodejs.org/docs/latest-v18.x/api/corepack.html + corepack enable +fi + +# Hugo (static site generator). +# Hugo is used to build the website content. +# Note: the installed version should match the version specified in 'netlify.toml' +TEMP=$(mktemp -d) +curl \ + -L https://github.com/gohugoio/hugo/releases/download/v0.84.0/hugo_extended_0.84.0_Linux-64bit.tar.gz \ + -o "${TEMP}/hugo_extended_0.84.0_Linux-64bit.tar.gz" +tar \ + -xvf "${TEMP}/hugo_extended_0.84.0_Linux-64bit.tar.gz" \ + -C "${TEMP}" +cp "${TEMP}/hugo" /usr/bin/hugo +rm -rf "$TEMP" + +# htmltest (HTML checker for the website content) +TEMP=$(mktemp -d) +curl \ + -L https://github.com/wjdp/htmltest/releases/download/v0.17.0/htmltest_0.17.0_linux_amd64.tar.gz \ + -o "${TEMP}/htmltest_0.17.0_linux_amd64.tar.gz" +tar \ + -xvf "${TEMP}/htmltest_0.17.0_linux_amd64.tar.gz" \ + -C "${TEMP}" +cp "${TEMP}/htmltest" /usr/bin/htmltest +rm -rf "$TEMP" + # Apt cleanup -apt clean +apt-get clean # Set up the default "deny all warnings" build flags CARGO_OVERRIDE_DIR="${HOME}/.cargo" @@ -146,6 +186,7 @@ if [ -z "${DISABLE_MOLD:-""}" ] ; then -C "${TEMP}" cp "${TEMP}/${MOLD_TARGET}/bin/mold" /usr/bin/mold cp "${TEMP}/${MOLD_TARGET}/lib/mold/mold-wrapper.so" /usr/bin/mold-wrapper.so + rm -rf "$TEMP" # Create our rustc wrapper script that we'll use to actually invoke `rustc` such that `mold` will wrap it and intercept # anything linking calls to use `mold` instead of `ld`, etc.