From 447ca83cfa667031bda92f6560eae1728115dd33 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Tue, 17 Aug 2021 03:11:56 +0200 Subject: [PATCH] Make arm64 compatible --- .github/workflows/build-ubuntu.yml | 35 ++++++++++++++++++++++++++---- linux/ubuntu/scripts/act.sh | 7 ++++-- linux/ubuntu/scripts/go.sh | 5 ++++- linux/ubuntu/scripts/js.sh | 5 ++++- linux/ubuntu/scripts/pwsh.sh | 32 ++++++++++++++++++--------- 5 files changed, 66 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-ubuntu.yml b/.github/workflows/build-ubuntu.yml index 53498b7..3e50bd5 100644 --- a/.github/workflows/build-ubuntu.yml +++ b/.github/workflows/build-ubuntu.yml @@ -18,7 +18,6 @@ on: env: SLUG: ${{ github.repository_owner }}/ubuntu DISTRO: ubuntu - PLATFORMS: linux/amd64 NODE: '14' BUILD_REF: ${{ github.sha }} SKIP_TEST: false @@ -34,7 +33,17 @@ jobs: fail-fast: true max-parallel: 4 matrix: - TAG: [latest, 20.04, 18.04, 16.04] + include: + - TAG: latest + PLATFORMS: linux/amd64,linux/arm64 + - TAG: 20.04 + PLATFORMS: linux/amd64,linux/arm64 + - TAG: 18.04 + PLATFORMS: linux/amd64 + - TAG: 16.04 + PLATFORMS: linux/amd64 + env: + PLATFORMS: ${{ matrix.PLATFORMS }} steps: - name: Login to GitHub Container Registry if: ${{ github.repository_owner == github.actor }} @@ -162,9 +171,27 @@ jobs: fail-fast: false max-parallel: 2 matrix: - TAG: [latest, 20.04, 18.04] - TYPE: [js, pwsh] + include: + - TAG: latest + TYPE: js + PLATFORMS: linux/amd64,linux/arm64 + - TAG: latest + TYPE: pwsh + PLATFORMS: linux/amd64,linux/arm64 + - TAG: 20.04 + TYPE: js + PLATFORMS: linux/amd64,linux/arm64 + - TAG: 20.04 + TYPE: pwsh + PLATFORMS: linux/amd64,linux/arm64 + - TAG: 18.04 + TYPE: js + PLATFORMS: linux/amd64 + - TAG: 18.04 + TYPE: pwsh + PLATFORMS: linux/amd64 env: + PLATFORMS: ${{ matrix.PLATFORMS }} BUILD_TAG: ${{ matrix.TYPE }}-${{ matrix.TAG }} TAG: ${{ matrix.TYPE }}-${{ matrix.TAG }} TYPE: ${{ matrix.TYPE }} diff --git a/linux/ubuntu/scripts/act.sh b/linux/ubuntu/scripts/act.sh index 3196cc0..b296f7e 100755 --- a/linux/ubuntu/scripts/act.sh +++ b/linux/ubuntu/scripts/act.sh @@ -90,10 +90,13 @@ printf "\n\tšŸ‹ Installed moby-buildx šŸ‹\t\n" docker buildx version printf "\n\tšŸ‹ Installing Node.JS šŸ‹\t\n" +ARCH=$(uname -m) +if [ "$ARCH" = x86_64 ]; then ARCH=x64; fi +if [ "$ARCH" = aarch64 ]; then ARCH=arm64; fi VER=$(curl https://nodejs.org/download/release/index.json | jq "[.[] | select(.version|test(\"^v${NODE_VERSION}\"))][0].version" -r) -NODEPATH="$AGENT_TOOLSDIRECTORY/node/${VER:1}/x64" +NODEPATH="$AGENT_TOOLSDIRECTORY/node/${VER:1}/$ARCH" mkdir -v -m 0777 -p "$NODEPATH" -curl -SsL "https://nodejs.org/download/release/latest-v${NODE_VERSION}.x/node-$VER-linux-x64.tar.xz" | tar -Jxf - --strip-components=1 -C "$NODEPATH" +curl -SsL "https://nodejs.org/download/release/latest-v${NODE_VERSION}.x/node-$VER-linux-$ARCH.tar.xz" | tar -Jxf - --strip-components=1 -C "$NODEPATH" sed "s|^PATH=|PATH=$NODEPATH/bin:|mg" -i /etc/environment export PATH="$NODEPATH/bin:$PATH" diff --git a/linux/ubuntu/scripts/go.sh b/linux/ubuntu/scripts/go.sh index 22f4f70..7018f32 100755 --- a/linux/ubuntu/scripts/go.sh +++ b/linux/ubuntu/scripts/go.sh @@ -21,7 +21,10 @@ for V in $(jq -r '.toolcache[] | select(.name == "go") | .versions[]' "/imagegen GOPATH="$AGENT_TOOLSDIRECTORY/go/${VER}/x64" mkdir -v -m 0777 -p "$GOPATH" - wget -qO- "https://golang.org/dl/go${VER}.linux-amd64.tar.gz" | tar -zxf - --strip-components=1 -C "$GOPATH" + ARCH=$(uname -m) + if [ "$ARCH" = x86_64 ]; then ARCH=amd64; fi + if [ "$ARCH" = aarch64 ]; then ARCH=arm64; fi + wget -qO- "https://golang.org/dl/go${VER}.linux-$ARCH.tar.gz" | tar -zxf - --strip-components=1 -C "$GOPATH" ENVVAR="${V//\./_}" echo "${ENVVAR}=${GOPATH}" >>/etc/environment diff --git a/linux/ubuntu/scripts/js.sh b/linux/ubuntu/scripts/js.sh index 676c024..1b869ae 100755 --- a/linux/ubuntu/scripts/js.sh +++ b/linux/ubuntu/scripts/js.sh @@ -23,7 +23,10 @@ for V in "${versions[@]}"; do # disable warning about 'mkdir -m -p' # shellcheck disable=SC2174 mkdir -v -m 0777 -p "$NODEPATH" - wget -qO- "https://nodejs.org/download/release/latest-v${V}.x/node-$VER-linux-x64.tar.xz" | tar -Jxf - --strip-components=1 -C "$NODEPATH" + ARCH=$(uname -m) + if [ "$ARCH" = x86_64 ]; then ARCH=x64; fi + if [ "$ARCH" = aarch64 ]; then ARCH=arm64; fi + wget -qO- "https://nodejs.org/download/release/latest-v${V}.x/node-$VER-linux-$ARCH.tar.xz" | tar -Jxf - --strip-components=1 -C "$NODEPATH" ENVVAR="${V//\./_}" echo "${ENVVAR}=${NODEPATH}" >>/etc/environment diff --git a/linux/ubuntu/scripts/pwsh.sh b/linux/ubuntu/scripts/pwsh.sh index 51338b8..15b71c9 100755 --- a/linux/ubuntu/scripts/pwsh.sh +++ b/linux/ubuntu/scripts/pwsh.sh @@ -3,8 +3,26 @@ set -Eeuxo pipefail printf "\n\tšŸ‹ Installing PowerShell šŸ‹\t\n" -sudo apt-get -yq update -sudo apt-get -yq install powershell + +# While an linux/amd64 platform installation can use apt-get, the linux/arm64 +# platform installation can't as described here: +# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1#support-for-arm-processors +# +# Due to that, we rely on the binary installation method for both platforms, as +# described here: +# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7.1#linux +# + +ARCH=$(uname -m) +if [ "$ARCH" = x86_64 ]; then ARCH=x64; fi +if [ "$ARCH" = aarch64 ]; then ARCH=arm64; fi +VER=$(curl --silent "https://api.github.com/repos/PowerShell/PowerShell/releases/latest" | jq -r .tag_name) +curl -L -o /tmp/powershell.tar.gz "https://github.com/PowerShell/PowerShell/releases/download/$VER/powershell-${VER:1}-linux-$ARCH.tar.gz" +sudo mkdir -p "/opt/microsoft/powershell/${VER:1:1}" +sudo tar zxf /tmp/powershell.tar.gz -C "/opt/microsoft/powershell/${VER:1:1}" +sudo chmod +x "/opt/microsoft/powershell/${VER:1:1}/pwsh" +sudo ln -s "/opt/microsoft/powershell/${VER:1:1}/pwsh" /usr/bin/pwsh +rm /tmp/powershell.tar.gz printf "\n\tšŸ‹ Installed PWSH šŸ‹\t\n" pwsh -v @@ -13,12 +31,6 @@ printf "\n\tšŸ‹ Installing PowerShell modules šŸ‹\t\n" modules=("MarkdownPS" "Pester" "PSScriptAnalyzer") for mod in "${modules[@]}"; do - printf "\n\tšŸ‹ Installing %s šŸ‹\t\n" "${mod}" - pwsh -nol -nop -c "Install-Module -Name ${mod} -Scope AllUsers -SkipPublisherCheck -Force" + printf "\n\tšŸ‹ Installing %s šŸ‹\t\n" "${mod}" + pwsh -nol -nop -c "Install-Module -Name ${mod} -Scope AllUsers -SkipPublisherCheck -Force" done - -printf "\n\tšŸ‹ Cleaning image šŸ‹\t\n" -apt-get clean -rm -rf /var/cache/* /var/log/* /var/lib/apt/lists/* /tmp/* || echo 'Failed to delete directories' - -printf "\n\tšŸ‹ Cleaned up image šŸ‹\t\n"