diff --git a/src/usr/local/bin/install-buildpack b/src/usr/local/bin/install-buildpack index 61880d3de..0f2012e1a 100755 --- a/src/usr/local/bin/install-buildpack +++ b/src/usr/local/bin/install-buildpack @@ -31,7 +31,7 @@ fi # env helper, loads tool specific env cat >> $ENV_FILE <<- EOM -export BUILDPACK=1 USER_NAME="${USER_NAME}" USER_ID="${USER_ID}" USER_HOME="/home/${USER_NAME}" PATH="/home/${USER_NAME}/bin:\${PATH}" +export BUILDPACK=1 USER_NAME="${USER_NAME}" USER_ID="${USER_ID}" USER_HOME="/home/${USER_NAME}" # openshift override unknown user home if [ "\${EUID}" != 0 ]; then @@ -74,10 +74,13 @@ useradd --uid ${USER_ID} --gid 0 --groups ${USER_NAME} --shell /bin/bash --creat mkdir /usr/local/env.d su ${USER_NAME} -c 'mkdir -p /home/${USER_NAME}/{env.d,bin}' +if [[ "$PATH" =~ (^|:)"/home/${USER_NAME}/bin"(:|$) ]]; then + echo "export PATH=\"/home/${USER_NAME}/bin:\${PATH}\"" >> $ENV_FILE +fi + # OpenShift chmod g+w /home/${USER_NAME}/{,env.d,bin} - export_env DEBIAN_FRONTEND "noninteractive" export_env LC_ALL "C.UTF-8" export_env LANG "C.UTF-8" diff --git a/src/usr/local/bin/install-gem b/src/usr/local/bin/install-gem index 1f5fecf75..030f06582 100755 --- a/src/usr/local/bin/install-gem +++ b/src/usr/local/bin/install-gem @@ -7,9 +7,5 @@ set -e require_tool "$@" check_command gem -if [[ $EUID -eq 0 ]]; then - unset GEM_HOME -fi - echo "Installing gem ${TOOL_NAME} v${TOOL_VERSION}" gem install ${TOOL_NAME} -v ${TOOL_VERSION} diff --git a/src/usr/local/buildpack/tools/composer.sh b/src/usr/local/buildpack/tools/composer.sh index 1428009a8..fcf042b53 100644 --- a/src/usr/local/buildpack/tools/composer.sh +++ b/src/usr/local/buildpack/tools/composer.sh @@ -19,12 +19,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -41,6 +35,6 @@ if [[ -z "${tool_path}" ]]; then chmod +x ${tool_path}/bin/composer fi -update_env ${tool_path} + link_wrapper ${TOOL_NAME} ${tool_path}/bin composer --version diff --git a/src/usr/local/buildpack/tools/docker.sh b/src/usr/local/buildpack/tools/docker.sh index 8ac31acea..e3745cf51 100644 --- a/src/usr/local/buildpack/tools/docker.sh +++ b/src/usr/local/buildpack/tools/docker.sh @@ -4,7 +4,6 @@ set -e require_root - if [[ -d "/usr/local/bin/${TOOL_NAME}" ]]; then echo "Skipping, already installed" exit 0 diff --git a/src/usr/local/buildpack/tools/dotnet.sh b/src/usr/local/buildpack/tools/dotnet.sh index d63c40f10..bfcab3cf8 100644 --- a/src/usr/local/buildpack/tools/dotnet.sh +++ b/src/usr/local/buildpack/tools/dotnet.sh @@ -10,7 +10,7 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then exit 1 fi -DOTNET_INSTALL_DIR=/usr/local/${TOOL_NAME} +DOTNET_INSTALL_DIR=/usr/local/buildpack/${TOOL_NAME} if [[ -d "${DOTNET_INSTALL_DIR}/sdk/${TOOL_VERSION}" ]]; then echo "Skipping, already installed" @@ -27,18 +27,18 @@ esac mkdir -p $DOTNET_INSTALL_DIR -export_path "${DOTNET_INSTALL_DIR}" -export_env DOTNET_ROOT "${DOTNET_INSTALL_DIR}" -export_env DOTNET_CLI_TELEMETRY_OPTOUT "1" -export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1" - +if [[ -z "${DOTNET_ROOT+x}" ]]; then + export_env DOTNET_ROOT "${DOTNET_INSTALL_DIR}" + export_env DOTNET_CLI_TELEMETRY_OPTOUT "1" + export_env DOTNET_SKIP_FIRST_TIME_EXPERIENCE "1" +fi curl -sSL https://dot.net/v1/dotnet-install.sh | bash -s - --install-dir $DOTNET_INSTALL_DIR --no-path -version $TOOL_VERSION +link_wrapper dotnet $DOTNET_INSTALL_DIR + # first time experience dotnet help > /dev/null su $USER_NAME -c 'dotnet help' > /dev/null dotnet --info - -shell_wrapper dotnet diff --git a/src/usr/local/buildpack/tools/elixir.sh b/src/usr/local/buildpack/tools/elixir.sh index 0a9f4d612..7e5b15884 100644 --- a/src/usr/local/buildpack/tools/elixir.sh +++ b/src/usr/local/buildpack/tools/elixir.sh @@ -5,23 +5,22 @@ set -e require_root check_command erl -if [[ -d "/usr/local/${TOOL_NAME}/${TOOL_VERSION}" ]]; then - echo "Skipping, already installed" - exit 0 -fi -curl -sSL https://github.com/elixir-lang/elixir/releases/download/v${TOOL_VERSION}/Precompiled.zip -o elixir.zip -mkdir -p /usr/local/${TOOL_NAME}/${TOOL_VERSION} -unzip -q elixir.zip -d /usr/local/${TOOL_NAME}/${TOOL_VERSION} -rm elixir.zip +base_path=/usr/local/buildpack/${TOOL_NAME} +tool_path=${base_path}/${TOOL_VERSION} + +if [[ ! -d "$tool_path" ]]; then + curl -sSL https://github.com/elixir-lang/elixir/releases/download/v${TOOL_VERSION}/Precompiled.zip -o elixir.zip + mkdir -p $tool_path + unzip -q elixir.zip -d $tool_path + rm elixir.zip +fi -export_path "/usr/local/${TOOL_NAME}/${TOOL_VERSION}/bin" +link_wrapper ${TOOL_NAME} ${tool_path}/bin +link_wrapper mix ${tool_path}/bin elixir --version mix --version su -c 'mix local.hex --force' ${USER_NAME} su -c 'mix local.rebar --force' ${USER_NAME} - -shell_wrapper elixir -shell_wrapper mix diff --git a/src/usr/local/buildpack/tools/golang.sh b/src/usr/local/buildpack/tools/golang.sh index 7676f68c0..8dfa7a21e 100644 --- a/src/usr/local/buildpack/tools/golang.sh +++ b/src/usr/local/buildpack/tools/golang.sh @@ -11,36 +11,41 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then exit 1 fi -if [[ -d "/usr/local/go/${TOOL_VERSION}" ]]; then - echo "Skipping, already installed" - exit 0 -fi -# fix version -GOLANG_FILE_VERSION=${TOOL_VERSION} -if [[ "${PATCH}" == "0" ]]; then - GOLANG_FILE_VERSION="${MAJOR}.${MINOR}" -fi +base_path=/usr/local/buildpack/go +tool_path=${base_path}/${TOOL_VERSION} + +if [[ ! -d "$tool_path" ]]; then -# go suggests: git svn bzr mercurial -apt_install bzr mercurial + # fix version + GOLANG_FILE_VERSION=${TOOL_VERSION} + if [[ "${PATCH}" == "0" ]]; then + GOLANG_FILE_VERSION="${MAJOR}.${MINOR}" + fi -mkdir -p /usr/local/go/${TOOL_VERSION} -curl -sSL https://dl.google.com/go/go${GOLANG_FILE_VERSION}.linux-amd64.tar.gz --output go.tgz -tar --strip 1 -C /usr/local/go/${TOOL_VERSION} -xzf go.tgz -rm go.tgz + # go suggests: git svn bzr mercurial + apt_install bzr mercurial -export_env GOPATH "/go" -export_env CGO_ENABLED 0 -export_env GOSUMDB off -export_path "/usr/local/go/${TOOL_VERSION}/bin:\$GOPATH/bin" + mkdir -p $tool_path + curl -sSL https://dl.google.com/go/go${GOLANG_FILE_VERSION}.linux-amd64.tar.gz --output go.tgz + tar --strip 1 -C $tool_path -xzf go.tgz + rm go.tgz -mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg" + if [[ ! -d "${GOPATH}" ]]; then + export_env GOPATH "/go" + export_env CGO_ENABLED 0 + export_env GOSUMDB off + export_path "\$GOPATH/bin" + + mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg" + + chown -R ${USER_ID} $GOPATH + chmod -R g+w $GOPATH + fi +fi -chown -R ${USER_ID} $GOPATH -chmod -R g+w $GOPATH +link_wrapper go $tool_path/bin go version go env -shell_wrapper go diff --git a/src/usr/local/buildpack/tools/gradle.sh b/src/usr/local/buildpack/tools/gradle.sh index 09f3a0c63..826069464 100644 --- a/src/usr/local/buildpack/tools/gradle.sh +++ b/src/usr/local/buildpack/tools/gradle.sh @@ -17,11 +17,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - reset_tool_env - export_tool_path "${1}/bin" -} - function create_gradle_settings() { if [[ -f ${USER_HOME}/.gradle/gradle.properties ]]; then echo 'Gradle settings already found' @@ -77,12 +72,8 @@ if [[ -z "${tool_path}" ]]; then unzip -q -d ${base_path} ${file} rm ${file} mv ${base_path}/${TOOL_NAME}-${TOOL_VERSION} ${tool_path} - - update_env ${tool_path} - shell_wrapper gradle -else - echo "Already installed, resetting env" - update_env ${tool_path} fi +link_wrapper gradle $tool_path/bin + gradle --version diff --git a/src/usr/local/buildpack/tools/helm.sh b/src/usr/local/buildpack/tools/helm.sh index 1eb42dc8f..e77c8ea59 100644 --- a/src/usr/local/buildpack/tools/helm.sh +++ b/src/usr/local/buildpack/tools/helm.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -31,6 +26,6 @@ if [[ -z "${tool_path}" ]]; then rm ${file} fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin helm version diff --git a/src/usr/local/buildpack/tools/jb.sh b/src/usr/local/buildpack/tools/jb.sh index f4e3e18d6..5bba7d599 100644 --- a/src/usr/local/buildpack/tools/jb.sh +++ b/src/usr/local/buildpack/tools/jb.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -32,6 +27,6 @@ if [[ -z "${tool_path}" ]]; then chmod +x ${tool_path}/bin/${TOOL_NAME} fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin jb --version diff --git a/src/usr/local/buildpack/tools/lerna.sh b/src/usr/local/buildpack/tools/lerna.sh index a76ba18d6..6515caf13 100644 --- a/src/usr/local/buildpack/tools/lerna.sh +++ b/src/usr/local/buildpack/tools/lerna.sh @@ -6,11 +6,6 @@ check_command node tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -26,6 +21,6 @@ if [[ -z "${tool_path}" ]]; then rm -rf $HOME/.cache /tmp/empty-cache fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} $tool_path/bin lerna --version diff --git a/src/usr/local/buildpack/tools/maven.sh b/src/usr/local/buildpack/tools/maven.sh index 355747389..24085f38b 100644 --- a/src/usr/local/buildpack/tools/maven.sh +++ b/src/usr/local/buildpack/tools/maven.sh @@ -15,8 +15,7 @@ tool_path=$(find_tool_path) function update_env () { reset_tool_env export_tool_env MAVEN_HOME "${1}" - PATH="${1}/bin:${PATH}" - link_wrapper mvn + link_wrapper mvn $tool_path/bin } if [[ -z "${tool_path}" ]]; then diff --git a/src/usr/local/buildpack/tools/npm.sh b/src/usr/local/buildpack/tools/npm.sh index 092bb28cb..d752c72aa 100644 --- a/src/usr/local/buildpack/tools/npm.sh +++ b/src/usr/local/buildpack/tools/npm.sh @@ -13,13 +13,6 @@ fi tool_path=$(find_tool_path) npm=$(command -v npm) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} - link_wrapper npx - hash -d ${TOOL_NAME} npx 2>/dev/null || true -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -42,6 +35,8 @@ if [[ -z "${tool_path}" ]]; then rm -rf $HOME/.cache /tmp/empty-cache fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} $tool_path/bin +link_wrapper npx $tool_path/bin +hash -d ${TOOL_NAME} npx 2>/dev/null || true npm --version diff --git a/src/usr/local/buildpack/tools/php.sh b/src/usr/local/buildpack/tools/php.sh index 5a48f2262..898f9ca3a 100644 --- a/src/usr/local/buildpack/tools/php.sh +++ b/src/usr/local/buildpack/tools/php.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -65,6 +60,6 @@ if [[ -z "${tool_path}" ]]; then fi fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin php --version diff --git a/src/usr/local/buildpack/tools/pnpm.sh b/src/usr/local/buildpack/tools/pnpm.sh index 4375ac819..824c73ba1 100644 --- a/src/usr/local/buildpack/tools/pnpm.sh +++ b/src/usr/local/buildpack/tools/pnpm.sh @@ -6,11 +6,6 @@ check_command node tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -26,6 +21,6 @@ if [[ -z "${tool_path}" ]]; then rm -rf $HOME/.cache /tmp/empty-cache fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} $tool_path/bin pnpm --version diff --git a/src/usr/local/buildpack/tools/poetry.sh b/src/usr/local/buildpack/tools/poetry.sh index 4dd6b4694..7175b1752 100644 --- a/src/usr/local/buildpack/tools/poetry.sh +++ b/src/usr/local/buildpack/tools/poetry.sh @@ -14,11 +14,6 @@ POETRY_URL=https://raw.githubusercontent.com/python-poetry/poetry/master/install tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) tool_path=${INSTALL_DIR}/${TOOL_NAME}/${TOOL_VERSION} @@ -39,6 +34,6 @@ if [[ -z "${tool_path}" ]]; then fi fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin poetry --version diff --git a/src/usr/local/buildpack/tools/powershell.sh b/src/usr/local/buildpack/tools/powershell.sh index e98a0db0d..e1a980cd7 100644 --- a/src/usr/local/buildpack/tools/powershell.sh +++ b/src/usr/local/buildpack/tools/powershell.sh @@ -31,7 +31,6 @@ if [[ -z "${tool_path}" ]]; then rm ${TOOL_NAME}.tgz fi -PATH="${tool_path}/bin:${PATH}" -link_wrapper pwsh +link_wrapper pwsh ${tool_path}/bin pwsh -Version diff --git a/src/usr/local/buildpack/tools/python.sh b/src/usr/local/buildpack/tools/python.sh index 054f2a78d..d1f5681ae 100644 --- a/src/usr/local/buildpack/tools/python.sh +++ b/src/usr/local/buildpack/tools/python.sh @@ -12,14 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - reset_tool_env - export_tool_path "${USER_HOME}/.local/bin:${1}/bin" - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} - link_wrapper pip -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -81,18 +73,37 @@ if [[ -z "${tool_path}" ]]; then fix_python_shebangs - ${tool_path}/bin/pip install --upgrade pip + PYTHONHOME=${tool_path} ${tool_path}/bin/pip install --upgrade pip # clean cache https://pip.pypa.io/en/stable/reference/pip_cache/#pip-cache - ${tool_path}/bin/pip cache purge - # TODO: support multiple installed python versions - # shell_wrapper python${MAJOR} - # shell_wrapper python${MAJOR}.${MINOR} - # shell_wrapper pip${MAJOR} - # shell_wrapper pip${MAJOR}.${MINOR} + PYTHONHOME=${tool_path} ${tool_path}/bin/pip cache purge fi -update_env ${tool_path} +reset_tool_env +# TODO: fix me, currently required for global pip +export_tool_path "${tool_path}/bin" +export_tool_path "${USER_HOME}/.local/bin" + +function python_shell_wrapper () { + local install_dir=$(get_install_dir) + local FILE="${install_dir}/bin/${1}" + check_command ${tool_path}/bin/$1 + cat > $FILE <<- EOM +#!/bin/bash + +export PYTHONHOME=${tool_path} PATH=${tool_path}/bin:\$PATH + +${1} "\$@" +EOM + chmod +x $FILE +} + +python_shell_wrapper ${TOOL_NAME} +python_shell_wrapper ${TOOL_NAME}${MAJOR} +python_shell_wrapper ${TOOL_NAME}${MAJOR}.${MINOR} +python_shell_wrapper pip +python_shell_wrapper pip${MAJOR} +python_shell_wrapper pip${MAJOR}.${MINOR} python --version pip --version diff --git a/src/usr/local/buildpack/tools/ruby.sh b/src/usr/local/buildpack/tools/ruby.sh index a5c964d37..28c652ee0 100644 --- a/src/usr/local/buildpack/tools/ruby.sh +++ b/src/usr/local/buildpack/tools/ruby.sh @@ -11,65 +11,77 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then exit 1 fi -if [[ -d "/usr/local/${TOOL_NAME}/${TOOL_VERSION}" ]]; then - echo "Skipping, already installed" - exit 0 -fi - -mkdir -p /usr/local/${TOOL_NAME} - -ARCH=$(uname -p) -CODENAME=$(. /etc/os-release && echo ${VERSION_CODENAME}) -RUBY_URL="https://github.com/containerbase/ruby-prebuild/releases/download" - -curl -sSfLo ruby.tar.xz ${RUBY_URL}/${TOOL_VERSION}/ruby-${TOOL_VERSION}-${CODENAME}-${ARCH}.tar.xz || echo 'Ignore download error' - -if [[ -f ruby.tar.xz ]]; then - echo "Using prebuild ruby for ${CODENAME}" - apt_install \ - build-essential \ - libffi-dev \ - ; - tar -C /usr/local/ruby -xf ruby.tar.xz - rm ruby.tar.xz -else - echo 'No prebuild ruby found, building from source' - apt_install \ - build-essential \ - libreadline-dev \ - libssl-dev \ - zlib1g-dev \ - libffi-dev \ - ; - - if [[ ! -x "$(command -v ruby-build)" ]]; then - git clone https://github.com/rbenv/ruby-build.git - PREFIX=/usr/local ./ruby-build/install.sh - rm -rf ruby-build +base_path=/usr/local/${TOOL_NAME} +tool_path=${base_path}/${TOOL_VERSION} + +if [[ ! -d "$tool_path" ]]; then + + mkdir -p $base_path + + ARCH=$(uname -p) + CODENAME=$(. /etc/os-release && echo ${VERSION_CODENAME}) + RUBY_URL="https://github.com/containerbase/ruby-prebuild/releases/download" + + curl -sSfLo ruby.tar.xz ${RUBY_URL}/${TOOL_VERSION}/ruby-${TOOL_VERSION}-${CODENAME}-${ARCH}.tar.xz || echo 'Ignore download error' + + if [[ -f ruby.tar.xz ]]; then + echo "Using prebuild ruby for ${CODENAME}" + apt_install \ + build-essential \ + libffi-dev \ + ; + tar -C /usr/local/ruby -xf ruby.tar.xz + rm ruby.tar.xz + else + echo 'No prebuild ruby found, building from source' + apt_install \ + build-essential \ + libreadline-dev \ + libssl-dev \ + zlib1g-dev \ + libffi-dev \ + ; + + if [[ ! -x "$(command -v ruby-build)" ]]; then + git clone https://github.com/rbenv/ruby-build.git + PREFIX=/usr/local ./ruby-build/install.sh + rm -rf ruby-build + fi + + ruby-build $TOOL_VERSION $tool_path fi - ruby-build $TOOL_VERSION /usr/local/${TOOL_NAME}/${TOOL_VERSION} -fi - -export_env GEM_HOME "${USER_HOME}/.gem-global" -export_path "\$GEM_HOME/bin:\$HOME/.gem/ruby/${MAJOR}.${MINOR}.0/bin:/usr/local/${TOOL_NAME}/${TOOL_VERSION}/bin" - -# System settings -mkdir -p /usr/local/${TOOL_NAME}/${TOOL_VERSION}/etc -cat > /usr/local/${TOOL_NAME}/${TOOL_VERSION}/etc/gemrc <<- EOM -gem: --no-document + # System settings + mkdir -p $tool_path/etc + cat > $tool_path/etc/gemrc <<- EOM +gem: --bindir /usr/local/bin --no-document :benchmark: false :verbose: true :update_sources: true :backtrace: false EOM + if [[ ! -r "${USER_HOME}/.gemrc" ]];then + cat > ${USER_HOME}/.gemrc <<- EOM +gem: --bindir ${USER_HOME}/bin --no-document +EOM + chown -R ${USER_ID} ${USER_HOME}/.gemrc + chmod -R g+w ${USER_HOME}/.gemrc + fi +fi + +reset_tool_env +cat >> $(find_tool_env) <<- EOM +if [ "\${EUID}" != 0 ]; then + export GEM_HOME="${USER_HOME}/.gem/ruby/${MAJOR}.${MINOR}.0" +fi +EOM + +link_wrapper ruby $tool_path/bin +link_wrapper gem $tool_path/bin ruby --version echo "gem $(gem --version)" gem env - -shell_wrapper ruby -shell_wrapper gem diff --git a/src/usr/local/buildpack/tools/rust.sh b/src/usr/local/buildpack/tools/rust.sh index 2af2ac30f..b892d6582 100644 --- a/src/usr/local/buildpack/tools/rust.sh +++ b/src/usr/local/buildpack/tools/rust.sh @@ -11,28 +11,28 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then exit 1 fi -if [[ -d "/usr/local/${TOOL_NAME}/${TOOL_VERSION}" ]]; then - echo "Skipping, already installed" - exit 0 +base_path=/usr/local/buildpack/${TOOL_NAME} +tool_path=$base_path/$TOOL_VERSION + +if [[ ! -d "${tool_path}" ]]; then + mkdir -p $base_path + curl -sSfLo rust.tar.gz https://static.rust-lang.org/dist/rust-${TOOL_VERSION}-x86_64-unknown-linux-gnu.tar.gz + mkdir rust + pushd rust + tar --strip 1 -xf ../rust.tar.gz + ./install.sh --prefix=$tool_path --components=cargo,rust-std-x86_64-unknown-linux-gnu,rustc + popd + rm rust.tar.gz + rm -rf rust fi -mkdir -p /usr/local/${TOOL_NAME} +reset_tool_env +export_tool_env RUST_BACKTRACE 1 +export_tool_env CARGO_HOME "${USER_HOME}/.cargo" +export_tool_path "\$CARGO_HOME/bin" -curl -sSfLo rust.tar.gz https://static.rust-lang.org/dist/rust-${TOOL_VERSION}-x86_64-unknown-linux-gnu.tar.gz -mkdir rust -pushd rust -tar --strip 1 -xf ../rust.tar.gz -./install.sh --prefix=/usr/local/${TOOL_NAME}/${TOOL_VERSION} --components=cargo,rust-std-x86_64-unknown-linux-gnu,rustc -popd -rm rust.tar.gz -rm -rf rust - -export_env RUST_BACKTRACE 1 -export_env CARGO_HOME "${USER_HOME}/.cargo" -export_path "\$CARGO_HOME/bin:/usr/local/${TOOL_NAME}/${TOOL_VERSION}/bin" +link_wrapper rustc ${tool_path}/bin +link_wrapper cargo ${tool_path}/bin cargo --version rustc --version - -shell_wrapper cargo -shell_wrapper rustc diff --git a/src/usr/local/buildpack/tools/sbt.sh b/src/usr/local/buildpack/tools/sbt.sh index 2266b9a60..de5fb44ec 100644 --- a/src/usr/local/buildpack/tools/sbt.sh +++ b/src/usr/local/buildpack/tools/sbt.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -37,7 +32,7 @@ if [[ -z "${tool_path}" ]]; then rm ${tool_path}/bin/*-darwin ${tool_path}/bin/*.exe ${tool_path}/bin/*.bat fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin sbt --version diff --git a/src/usr/local/buildpack/tools/scala.sh b/src/usr/local/buildpack/tools/scala.sh index 0fe10ba1c..aadf4379d 100644 --- a/src/usr/local/buildpack/tools/scala.sh +++ b/src/usr/local/buildpack/tools/scala.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -33,7 +28,7 @@ if [[ -z "${tool_path}" ]]; then rm ${file} fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin scala --version diff --git a/src/usr/local/buildpack/tools/swift.sh b/src/usr/local/buildpack/tools/swift.sh index a4ebe85b7..bf148c92d 100644 --- a/src/usr/local/buildpack/tools/swift.sh +++ b/src/usr/local/buildpack/tools/swift.sh @@ -10,78 +10,73 @@ if [[ ! "${MAJOR}" || ! "${MINOR}" ]]; then exit 1 fi -SWIFT_INSTALL_DIR=/usr/local/${TOOL_NAME}/${TOOL_VERSION} +base_path=/usr/local/buildpack/${TOOL_NAME} +tool_path=$base_path/$TOOL_VERSION + +if [[ ! -d "${tool_path}" ]]; then + VERSION_CODENAME=$(. /etc/os-release && echo ${VERSION_CODENAME}) + VERSION_ID=$(. /etc/os-release && echo ${VERSION_ID}) + + # https://swift.org/getting-started/#on-linux + # already installed: git + + case "$VERSION_CODENAME" in + "bionic") + apt_install \ + binutils \ + libc6-dev \ + libcurl4 \ + libedit2 \ + libgcc-5-dev \ + libpython2.7 \ + libsqlite3-0 \ + libstdc++-5-dev \ + libxml2 \ + pkg-config \ + tzdata \ + zlib1g-dev \ + ;; + "focal") + apt_install \ + binutils \ + gnupg2 \ + libc6-dev \ + libcurl4 \ + libedit2 \ + libgcc-9-dev \ + libpython2.7 \ + libsqlite3-0 \ + libstdc++-9-dev \ + libxml2 \ + libz3-dev \ + pkg-config \ + tzdata \ + zlib1g-dev \ + ;; + esac + + + # https://swift.org/builds/swift-5.3-release/ubuntu1804/swift-5.3-RELEASE/swift-5.3-RELEASE-ubuntu20.04.tar.gz + if [[ "${PATCH}" = "0" ]]; then + TOOL_VERSION=${MAJOR}.${MINOR} + fi + + SWIFT_PLATFORM=ubuntu${VERSION_ID} + SWIFT_BRANCH=swift-${TOOL_VERSION}-release + SWIFT_VER=swift-${TOOL_VERSION}-RELEASE + SWIFT_WEBROOT=https://swift.org/builds + + SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)" + SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VER/$SWIFT_VER-$SWIFT_PLATFORM.tar.gz" + + mkdir -p $tool_path + + curl -fsSL $SWIFT_BIN_URL -o swift.tar.gz + tar --strip 2 -C $tool_path -xzf swift.tar.gz + rm swift.tar.gz -if [[ -d "${SWIFT_INSTALL_DIR}" ]]; then - echo "Skipping, already installed" - exit 0 fi - -VERSION_CODENAME=$(. /etc/os-release && echo ${VERSION_CODENAME}) -VERSION_ID=$(. /etc/os-release && echo ${VERSION_ID}) - -# https://swift.org/getting-started/#on-linux -# already installed: git - -case "$VERSION_CODENAME" in - "bionic") - apt_install \ - binutils \ - libc6-dev \ - libcurl4 \ - libedit2 \ - libgcc-5-dev \ - libpython2.7 \ - libsqlite3-0 \ - libstdc++-5-dev \ - libxml2 \ - pkg-config \ - tzdata \ - zlib1g-dev \ - ;; - "focal") - apt_install \ - binutils \ - gnupg2 \ - libc6-dev \ - libcurl4 \ - libedit2 \ - libgcc-9-dev \ - libpython2.7 \ - libsqlite3-0 \ - libstdc++-9-dev \ - libxml2 \ - libz3-dev \ - pkg-config \ - tzdata \ - zlib1g-dev \ - ;; -esac - - -# https://swift.org/builds/swift-5.3-release/ubuntu1804/swift-5.3-RELEASE/swift-5.3-RELEASE-ubuntu20.04.tar.gz -if [[ "${PATCH}" = "0" ]]; then - TOOL_VERSION=${MAJOR}.${MINOR} -fi - -SWIFT_PLATFORM=ubuntu${VERSION_ID} -SWIFT_BRANCH=swift-${TOOL_VERSION}-release -SWIFT_VER=swift-${TOOL_VERSION}-RELEASE -SWIFT_WEBROOT=https://swift.org/builds - -SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)" -SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VER/$SWIFT_VER-$SWIFT_PLATFORM.tar.gz" - - -mkdir -p $SWIFT_INSTALL_DIR - -curl -fsSL $SWIFT_BIN_URL -o swift.tar.gz -tar --strip 2 -C $SWIFT_INSTALL_DIR -xzf swift.tar.gz -rm swift.tar.gz - -export_path "${SWIFT_INSTALL_DIR}/bin" +link_wrapper $TOOL_NAME $tool_path/bin swift --version - -shell_wrapper swift diff --git a/src/usr/local/buildpack/tools/terraform.sh b/src/usr/local/buildpack/tools/terraform.sh index 3c1f979b6..29da94140 100644 --- a/src/usr/local/buildpack/tools/terraform.sh +++ b/src/usr/local/buildpack/tools/terraform.sh @@ -12,11 +12,6 @@ fi tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -32,6 +27,6 @@ if [[ -z "${tool_path}" ]]; then rm ${file} fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin terraform version diff --git a/src/usr/local/buildpack/tools/yarn-slim.sh b/src/usr/local/buildpack/tools/yarn-slim.sh index c6924e936..1380194ff 100644 --- a/src/usr/local/buildpack/tools/yarn-slim.sh +++ b/src/usr/local/buildpack/tools/yarn-slim.sh @@ -4,15 +4,10 @@ set -e check_command node -INSTALL_DIR=$(get_install_dir) tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - ln -sf ${1}/bin/yarn $INSTALL_DIR/bin/${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then + INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} tool_path=${base_path}/${TOOL_VERSION} @@ -27,11 +22,8 @@ if [[ -z "${tool_path}" ]]; then # patch yarn sed -i 's/ steps,/ steps.slice(0,1),/' $tool_path/lib/node_modules/yarn/lib/cli.js - - update_env ${tool_path} -else - echo "Already installed, resetting env" - update_env ${tool_path} fi -yarn --version +link_wrapper ${TOOL_NAME} ${tool_path}/bin/yarn + +yarn-slim --version diff --git a/src/usr/local/buildpack/tools/yarn.sh b/src/usr/local/buildpack/tools/yarn.sh index 8cf9c61f0..7e3935629 100644 --- a/src/usr/local/buildpack/tools/yarn.sh +++ b/src/usr/local/buildpack/tools/yarn.sh @@ -6,11 +6,6 @@ check_command node tool_path=$(find_tool_path) -function update_env () { - PATH="${1}/bin:${PATH}" - link_wrapper ${TOOL_NAME} -} - if [[ -z "${tool_path}" ]]; then INSTALL_DIR=$(get_install_dir) base_path=${INSTALL_DIR}/${TOOL_NAME} @@ -26,6 +21,6 @@ if [[ -z "${tool_path}" ]]; then rm -rf $HOME/.cache /tmp/empty-cache fi -update_env ${tool_path} +link_wrapper ${TOOL_NAME} ${tool_path}/bin yarn --version diff --git a/test/dotnet/Dockerfile b/test/dotnet/Dockerfile index e3e52f815..3666b530f 100644 --- a/test/dotnet/Dockerfile +++ b/test/dotnet/Dockerfile @@ -1,4 +1,6 @@ ARG IMAGE=containerbase/buildpack +ARG BUILDPACK_DEBUG + FROM ${IMAGE} as base RUN touch /.dummy @@ -12,6 +14,7 @@ WORKDIR /test #-------------------------------------- FROM base as net3 +ARG BUILDPACK_DEBUG ARG APT_HTTP_PROXY # renovate: datasource=docker lookupName=mcr.microsoft.com/dotnet/sdk versioning=docker @@ -42,6 +45,7 @@ RUN set -ex; \ #-------------------------------------- FROM base as testb +ARG BUILDPACK_DEBUG ARG APT_HTTP_PROXY # Do not change diff --git a/test/node/Dockerfile b/test/node/Dockerfile index 08e7e8b8f..639519b6b 100644 --- a/test/node/Dockerfile +++ b/test/node/Dockerfile @@ -117,9 +117,16 @@ USER 1000 # renovate: datasource=node RUN install-tool node v17.0.1 +RUN npm install -g yarn +RUN set -ex; \ + [ "$(command -v yarn)" = "/home/${USER_NAME}/.npm-global/bin/yarn" ] && echo "works" || exit 1; \ + yarn --version; # renovate: datasource=npm RUN install-tool yarn 1.22.17 +RUN set -ex; \ + [ "$(command -v yarn)" = "/home/${USER_NAME}/bin/yarn" ] && echo "works" || exit 1; \ + yarn --version; COPY --chown=1000:0 test test @@ -130,11 +137,6 @@ RUN set -ex; \ RUN set -ex; cd test/a; npm i -RUN npm install -g yarn -RUN set -ex; \ - [ "$(command -v yarn)" = "/home/${USER_NAME}/.npm-global/bin/yarn" ] && echo "works" || exit 1; \ - yarn --version; - #-------------------------------------- # test: npm (install-tool npm) #-------------------------------------- diff --git a/test/python/Dockerfile b/test/python/Dockerfile index bd826868c..6a7072b5d 100644 --- a/test/python/Dockerfile +++ b/test/python/Dockerfile @@ -1,4 +1,6 @@ ARG IMAGE=containerbase/buildpack +ARG BUILDPACK_DEBUG + FROM ${IMAGE} as base RUN touch /.dummy @@ -10,6 +12,7 @@ WORKDIR /test FROM base as build ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG # Python # renovate: datasource=github-releases lookupName=containerbase/python-prebuild @@ -19,6 +22,7 @@ RUN install-tool python 3.10.1 FROM base as build-rootless ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG USER 1000 @@ -30,6 +34,8 @@ RUN install-tool python 3.10.1 #-------------------------------------- FROM build as pipenv +ARG BUILDPACK_DEBUG + # renovate: datasource=pypi RUN install-pip pipenv 2022.1.8 @@ -40,6 +46,8 @@ USER 1000 # build: poetry #-------------------------------------- FROM build as poetry +ARG BUILDPACK_DEBUG + # renovate: datasource=pypi RUN install-tool poetry 1.1.12 @@ -51,6 +59,8 @@ USER 1000 #-------------------------------------- FROM build as testa +ARG BUILDPACK_DEBUG + # try install again, sould skip # renovate: datasource=github-releases lookupName=containerbase/python-prebuild RUN install-tool python 3.10.1 @@ -98,6 +108,8 @@ RUN set -ex; cd d-poetry && poetry update --lock --no-interaction pytest #-------------------------------------- FROM build as teste +ARG BUILDPACK_DEBUG + RUN install-tool poetry 0.12.17 RUN install-tool poetry 1.1.0 @@ -118,7 +130,7 @@ RUN set -ex; \ #-------------------------------------- FROM build-rootless as testg -RUN set -ex; env; ls -la $HOME/bin; cat $BASH_ENV +ARG BUILDPACK_DEBUG # renovate: datasource=pypi RUN install-pip pipenv 2022.1.8 diff --git a/test/ruby/Dockerfile b/test/ruby/Dockerfile index be54afb80..2f835dbdc 100644 --- a/test/ruby/Dockerfile +++ b/test/ruby/Dockerfile @@ -1,7 +1,10 @@ ARG IMAGE=containerbase/buildpack +ARG BUILDPACK_DEBUG + FROM ${IMAGE} as build ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG # Do not renovate ruby 2.x RUN install-tool ruby 2.6.4 @@ -15,6 +18,7 @@ WORKDIR /test FROM ${IMAGE} as build3 ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG # renovate: datasource=github-releases lookupName=containerbase/ruby-prebuild versioning=ruby RUN install-tool ruby 3.0.3 @@ -30,22 +34,20 @@ WORKDIR /test #-------------------------------------- FROM build as testa -USER 1000 +ARG BUILDPACK_DEBUG + +# openshift +USER 1005 RUN ruby --version +RUN gem env RUN gem install bundler -v 1.17.2 -RUN set -ex; \ - [ "$(command -v bundle)" = "/home/${USER_NAME}/.gem-global/bin/bundle" ] && echo "works" || exit 1; \ - bundler env - -ENV GEM_HOME=/tmp/.gem - -RUN gem install bundler -v 1.17.2 +RUN bundle env RUN set -ex; \ - [ "$(command -v bundle)" = "/tmp/.gem/bin/bundle" ] && echo "works" || exit 1; \ + [ "$(command -v bundle)" = "/home/${USER_NAME}/bin/bundle" ] && echo "works" || exit 1; \ bundler env RUN set -ex; \ @@ -57,6 +59,8 @@ RUN set -ex; \ #-------------------------------------- FROM build as testb +ARG BUILDPACK_DEBUG + # renovate: datasource=rubygems versioning=ruby RUN install-gem bundler 2.3.4 @@ -77,6 +81,8 @@ RUN ruby --version #-------------------------------------- FROM build as testc +ARG BUILDPACK_DEBUG + USER 1000 RUN gem install cocoapods -v 1.9.1 @@ -91,6 +97,8 @@ RUN set -ex; \ #-------------------------------------- FROM build3 as testd +ARG BUILDPACK_DEBUG + # renovate: datasource=rubygems versioning=ruby RUN install-gem cocoapods 1.11.2