From 5cbf58c106d3ee47ad2cefadc1b9b1a1b611496b Mon Sep 17 00:00:00 2001 From: "Denis N. Antonioli" Date: Fri, 21 Apr 2023 20:57:35 -0700 Subject: [PATCH] parametrize the install scripts --- Dockerfile | 6 ++++++ scripts/install-ktlint.sh | 19 ++++++++++++++++--- scripts/install-phive.sh | 15 ++++++++++++++- scripts/install-pwsh.sh | 14 +++++++++++++- scripts/install-rustfmt.sh | 29 ++++++++++++++++++++++------- 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 26d95bba..b5569674 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,8 @@ ARG KTLINT_VERSION='0.47.1' ARG PSSA_VERSION='1.21.0' ARG PWSH_DIRECTORY='/usr/lib/microsoft/powershell' ARG PWSH_VERSION='v7.3.1' +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope +ARG TARGETARCH #################### # Run APK installs # @@ -235,6 +237,8 @@ ARG BUILD_REVISION ARG BUILD_VERSION ## install alpine-pkg-glibc (glibc compatibility layer package for Alpine Linux) ARG GLIBC_VERSION='2.34-r0' +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope +ARG TARGETARCH ######################################### # Label the instance and set maintainer # @@ -356,6 +360,8 @@ ENTRYPOINT ["/action/lib/linter.sh"] # Grab small clean image to build standard ############################### ################################################################################ FROM slim as standard +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope +ARG TARGETARCH ############### # Set up args # diff --git a/scripts/install-ktlint.sh b/scripts/install-ktlint.sh index 69f44fe9..ee1d1aff 100755 --- a/scripts/install-ktlint.sh +++ b/scripts/install-ktlint.sh @@ -2,6 +2,19 @@ set -euo pipefail +case $TARGETARCH in +amd64) + target=x64 + ;; +arm64) + target=arm64 + ;; +*) + echo "$TARGETARCH is not supported" + exit 1 + ;; +esac + ################## # Install ktlint # ################## @@ -33,10 +46,10 @@ curl --retry 5 --retry-delay 5 -sL -o "glibc-${GLIBC_VERSION}.apk" \ apk add --no-cache --force-overwrite "glibc-${GLIBC_VERSION}.apk" rm "glibc-${GLIBC_VERSION}.apk" -curl --retry 5 --retry-delay 5 -sO "https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-x64-release.zip" -unzip -q dartsdk-linux-x64-release.zip +curl --retry 5 --retry-delay 5 -sO "https://storage.googleapis.com/dart-archive/channels/stable/release/${DART_VERSION}/sdk/dartsdk-linux-${target}-release.zip" +unzip -q dartsdk-linux-${target}-release.zip chmod +x dart-sdk/bin/dart* && mv dart-sdk/bin/* /usr/bin/ && mv dart-sdk/lib/* /usr/lib/ && mv dart-sdk/include/* /usr/include/ -rm -r dart-sdk/ dartsdk-linux-x64-release.zip +rm -r dart-sdk/ dartsdk-linux-${target}-release.zip ################################ # Create and install Bash-Exec # diff --git a/scripts/install-phive.sh b/scripts/install-phive.sh index 5f417827..a4aa5268 100755 --- a/scripts/install-phive.sh +++ b/scripts/install-phive.sh @@ -3,6 +3,19 @@ set -euo pipefail set -x +case $TARGETARCH in +amd64) + target=x86_64 + ;; +arm64) + target=aarch64 + ;; +*) + echo "$TARGETARCH is not supported" + exit 1 + ;; +esac + apk add curl jq url=$(curl -s \ -H "Accept: application/vnd.github+json" \ @@ -23,7 +36,7 @@ apk add --no-cache --force-overwrite \ tar zstd rm "glibc-${GLIBC_VERSION}.apk" mkdir /tmp/libz -curl --retry 5 --retry-delay 5 -sL https://www.archlinux.org/packages/core/x86_64/zlib/download | tar -x --zstd -C /tmp/libz +curl --retry 5 --retry-delay 5 -sL https://www.archlinux.org/packages/core/${target}/zlib/download | tar -x --zstd -C /tmp/libz mv /tmp/libz/usr/lib/libz.so* /usr/glibc-compat/lib rm -rf /tmp/libz curl --retry 5 --retry-delay 5 -sLO https://phar.io/releases/phive.phar diff --git a/scripts/install-pwsh.sh b/scripts/install-pwsh.sh index 41a2f127..2b207565 100755 --- a/scripts/install-pwsh.sh +++ b/scripts/install-pwsh.sh @@ -6,12 +6,24 @@ set -euo pipefail # Slightly modified to always retrieve latest stable Powershell version # If changing PWSH_VERSION='latest' to a specific version, use format PWSH_VERSION='tags/v7.0.2' +case $TARGETARCH in +amd64) + target=x64 + ;; +# arm64) +# only on ubuntu +*) + echo "$TARGETARCH is not supported" + exit 1 + ;; +esac + mkdir -p "${PWSH_DIRECTORY}" url=$(curl -s \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $(cat /run/secrets/GITHUB_TOKEN)" \ "https://api.github.com/repos/powershell/powershell/releases/${PWSH_VERSION}" | - jq -r '.assets | .[] | select(.name | contains("linux-alpine-x64")) | .url') + jq --arg target "${target}" -r '.assets | .[] | select(.name | contains("linux-alpine-" + $target)) | .url') curl --retry 5 --retry-delay 5 -sL \ -H "Accept: application/octet-stream" \ -H "Authorization: Bearer $(cat /run/secrets/GITHUB_TOKEN)" \ diff --git a/scripts/install-rustfmt.sh b/scripts/install-rustfmt.sh index a1c72166..6ef3f7e6 100755 --- a/scripts/install-rustfmt.sh +++ b/scripts/install-rustfmt.sh @@ -2,17 +2,32 @@ # shellcheck disable=SC2016 # shellcheck disable=SC2129 +# https://doc.rust-lang.org/rustc/platform-support.html + set -euo pipefail +case $TARGETARCH in +amd64) + target=x86_64 + ;; +arm64) + target=aarch64 + ;; +*) + echo "$TARGETARCH is not supported" + exit 1 + ;; +esac + ln -s /usr/bin/rustup-init /usr/bin/rustup -rustup toolchain install stable-x86_64-unknown-linux-musl -rustup component add rustfmt --toolchain=stable-x86_64-unknown-linux-musl -rustup component add clippy --toolchain=stable-x86_64-unknown-linux-musl +rustup toolchain install stable-${target}-unknown-linux-musl +rustup component add rustfmt --toolchain=stable-${target}-unknown-linux-musl +rustup component add clippy --toolchain=stable-${target}-unknown-linux-musl mv /root/.rustup /usr/lib/.rustup -ln -fsv /usr/lib/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/rustfmt /usr/bin/rustfmt -ln -fsv /usr/lib/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/rustc /usr/bin/rustc -ln -fsv /usr/lib/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo /usr/bin/cargo -ln -fsv /usr/lib/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo-clippy /usr/bin/cargo-clippy +ln -fsv /usr/lib/.rustup/toolchains/stable-${target}-unknown-linux-musl/bin/rustfmt /usr/bin/rustfmt +ln -fsv /usr/lib/.rustup/toolchains/stable-${target}-unknown-linux-musl/bin/rustc /usr/bin/rustc +ln -fsv /usr/lib/.rustup/toolchains/stable-${target}-unknown-linux-musl/bin/cargo /usr/bin/cargo +ln -fsv /usr/lib/.rustup/toolchains/stable-${target}-unknown-linux-musl/bin/cargo-clippy /usr/bin/cargo-clippy echo '#!/usr/bin/env bash' >/usr/bin/clippy echo 'pushd $(dirname $1)' >>/usr/bin/clippy