parametrize the install scripts

This commit is contained in:
Denis N. Antonioli 2023-04-21 20:57:35 -07:00 committed by Brett Logan
parent 47884a0e25
commit 5cbf58c106
5 changed files with 71 additions and 12 deletions

View file

@ -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 #

View file

@ -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 #

View file

@ -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

View file

@ -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)" \

View file

@ -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