Skip to content

Commit a152e94

Browse files
authored
fix: use CNB_TARGET_* environment variables (#151)
Closes #148. Removes os and arch detection in `build` scripts and instead use the `CNB_TARGET_OS` and the `CNB_TARGET_ARCH` environment variables. Also, print a warning if the detected architecture (from `uname`) is different from the target architecture: at the moment, cross-platform builds with pack will very likely create an image with incompatible binaries (as many buildpacks use `uname` and not target platform metadata).
1 parent fed5ef0 commit a152e94

6 files changed

Lines changed: 31 additions & 33 deletions

File tree

buildpacks/conda-nodefaults/bin/build

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ cp environment.yml "$TMPDIR/original.yml"
1919
cache_layer_dir="${CNB_LAYERS_DIR}"/cache
2020
mkdir -p "${cache_layer_dir}"
2121

22-
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
23-
ARCH=$(uname -m)
24-
25-
case "$ARCH" in
26-
x86_64) ARCH=amd64 ;;
27-
arm64|aarch64) ARCH=arm64 ;;
28-
*) >&2 echo "Unsupported architecture: $ARCH"; exit 1 ;;
29-
esac
22+
OS="${CNB_TARGET_OS:-unknown}"
23+
ARCH="${CNB_TARGET_ARCH:-unknown}"
3024

3125
YQ_FILENAME="yq_${OS}_${ARCH}"
3226
YQ_VERSION=v4.47.1

buildpacks/renku-variables/bin/build

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ set -eo pipefail
33

44
echo -e "=== 🔧 \033[1mRenku Environment Variables buildpack\033[0m ==="
55

6+
# NOTE: we run platform mismatch check here as this buildpack is always selected
7+
CURRENT_ARCH="$(uname -m)"
8+
case "${CURRENT_ARCH}" in
9+
"aarch64"|"arm64") CURRENT_ARCH="arm64" ;;
10+
"amd64"|"x86_64") CURRENT_ARCH="amd64" ;;
11+
*) >&2 echo "ERROR: Unsupported architecture: ${CURRENT_ARCH}" ;;
12+
esac
13+
14+
if [ -n "${CNB_TARGET_ARCH:-}" ]; then
15+
if [ "${CNB_TARGET_ARCH}" != "${CURRENT_ARCH}" ]; then
16+
>&2 echo "ERROR: current architecture ${CURRENT_ARCH} does not match target architecture ${CNB_TARGET_ARCH}!"
17+
exit 1
18+
fi
19+
fi
20+
21+
622
layers_dir="$1"
723
layer_dir="${layers_dir}"/renku-env
824
env_dir="${layer_dir}"/env.launch

buildpacks/rstudio/bin/build

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ RSTUDIO_VERSION="2025.09.2-418"
1818
OS_CODENAME=jammy # https://posit.co/download/rstudio-server gives jammy regardless of ubuntu version
1919
FNAME="rstudio-$RSTUDIO_VERSION.deb"
2020

21-
ARCH=$(uname -m)
22-
23-
case "$ARCH" in
24-
x86_64) ARCH=amd64 ;;
25-
arm64|aarch64) ARCH=arm64 ;;
26-
*) >&2 echo "Unsupported architecture: $ARCH"; exit 1 ;;
27-
esac
21+
ARCH="${CNB_TARGET_ARCH:-unknown}"
2822

2923
if [ -f "$cache_layer_dir/$FNAME" ]; then
3024
echo "Found rstudio $RSTUDIO_VERSION in $cache_layer_dir skipping download"

buildpacks/ttyd/bin/build

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ ttyd_layer_dir="${layers_dir}"/ttyd
1212
ttyd_bin_dir="${ttyd_layer_dir}"/bin
1313
mkdir -p "${ttyd_bin_dir}"
1414

15-
ARCH=$(uname -i)
15+
ARCH="${CNB_TARGET_ARCH:-unknown}"
16+
case "${ARCH}" in
17+
"arm64") ARCH="aarch64" ;;
18+
"amd64") ARCH="x86_64" ;;
19+
esac
20+
1621
TTYD_VERSION="1.7.7"
1722
TTYD_URL="https://github.com/tsl0922/ttyd/releases/download/${TTYD_VERSION}/ttyd.${ARCH}"
1823

buildpacks/vscodium/bin/build

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ mkdir -p "${execd_layer_dir}"
2222
mkdir -p "${cache_layer_dir}"
2323

2424

25-
ARCH=$(uname -m)
26-
27-
case "$ARCH" in
28-
x86_64) ARCH=x64 ;;
29-
arm64|aarch64) ARCH=arm64 ;;
30-
*) >&2 echo "Unsupported architecture: $ARCH"; exit 1 ;;
25+
ARCH="${CNB_TARGET_ARCH:-unknown}"
26+
case "${ARCH}" in
27+
"amd64") ARCH="x64" ;;
3128
esac
3229

3330
VSCODIUM_DEFAULT_VERSION="1.104.36664"

scripts/install_shellcheck.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,13 @@ LOCATION=$2
88

99
OS="linux"
1010
case "$(uname)" in
11-
'Darwin')
12-
OS='darwin'
13-
;;
14-
*) ;;
11+
'Darwin') OS='darwin' ;;
1512
esac
1613

1714
ARCH="x86_64"
1815
case "$(uname -m)" in
19-
'aarch64')
20-
ARCH='aarch64'
21-
;;
22-
'arm64')
23-
ARCH='aarch64'
24-
;;
25-
*) ;;
16+
'aarch64') ARCH='aarch64' ;;
17+
'arm64') ARCH='aarch64' ;;
2618
esac
2719

2820
if [[ -z $VERSION ]]; then

0 commit comments

Comments
 (0)