diff --git a/src/usr/local/buildpack/tools/elixir.sh b/src/usr/local/buildpack/tools/elixir.sh deleted file mode 100644 index b22df94033..0000000000 --- a/src/usr/local/buildpack/tools/elixir.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -require_root -check_command erl - - -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 - -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}" diff --git a/src/usr/local/buildpack/tools/erlang.sh b/src/usr/local/buildpack/tools/erlang.sh deleted file mode 100644 index 81cb198fe8..0000000000 --- a/src/usr/local/buildpack/tools/erlang.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -set -e - -SEMVER_REGEX="^(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))?(\.(0|[1-9][0-9]*))?(\.(0|[1-9][0-9]*))?(\+[0-9]+)?([a-z-].*)?$" - -function check_semver () { - if [[ ! "${1}" =~ ${SEMVER_REGEX} ]]; then - echo Not a semver like version - aborting: "${1}" - exit 1 - fi - export MAJOR=${BASH_REMATCH[1]} - export MINOR=${BASH_REMATCH[3]} - export PATCH=${BASH_REMATCH[5]} - export BUILD=${BASH_REMATCH[7]} -} - -check_semver "${TOOL_VERSION}" - - -if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" || ! "${BUILD}" ]]; then - echo Invalid version: "${TOOL_VERSION}" - exit 1 -fi - -tool_path=$(find_versioned_tool_path) - -if [[ -z "${tool_path}" ]]; then - INSTALL_DIR=$(get_install_dir) - base_path=${INSTALL_DIR}/${TOOL_NAME} - tool_path=${base_path}/${TOOL_VERSION} - - mkdir -p "${base_path}" - - file=/tmp/${TOOL_NAME}.tar.xz - - ARCH=$(uname -p) - BASE_URL="https://github.com/containerbase/${TOOL_NAME}-prebuild/releases/download" - - version_codename=$(get_distro) - - # TODO: extract to separate preparation tool - require_root - case "$version_codename" in - "bionic") apt_install \ - libodbc1 \ - libssl1.1 \ - libsctp1 \ - ;; - "focal") apt_install \ - libodbc1 \ - libssl1.1 \ - libsctp1 \ - ;; - esac - - curl -sSfLo "${file}" "${BASE_URL}/${TOOL_VERSION}/${TOOL_NAME}-${TOOL_VERSION}-${version_codename}-${ARCH}.tar.xz" - - if [[ -f ${file} ]]; then - echo "Using prebuild ${TOOL_NAME}" - tar -C "${base_path}" -xf "${file}" - rm "${file}" - else - echo "No prebuild ${TOOL_NAME} found" >&2 - exit 1 - fi -fi - -link_wrapper "erl" "${tool_path}/bin" - -erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell diff --git a/src/usr/local/buildpack/tools/v2/elixir.sh b/src/usr/local/buildpack/tools/v2/elixir.sh new file mode 100644 index 0000000000..50c4df8a6e --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/elixir.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +function install_tool () { + local versioned_tool_path + + check_command erl + + versioned_tool_path=$(create_versioned_tool_path) + create_folder "${versioned_tool_path}/bin" + + local file + file=$(get_from_url "https://github.com/elixir-lang/elixir/releases/download/v${TOOL_VERSION}/Precompiled.zip") + unzip -q "${file}" -d "${versioned_tool_path}" +} + +function link_tool () { + local versioned_tool_path + versioned_tool_path=$(find_versioned_tool_path) + + shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" + shell_wrapper mix "${versioned_tool_path}/bin" + + elixir --version + mix --version + + if [[ $(is_root) -eq 0 ]]; then + su -c 'mix local.hex --force' "${USER_NAME}" + su -c 'mix local.rebar --force' "${USER_NAME}" + else + mix local.hex --force + mix local.rebar --force + fi +} diff --git a/src/usr/local/buildpack/tools/v2/erlang.sh b/src/usr/local/buildpack/tools/v2/erlang.sh new file mode 100644 index 0000000000..630627ca31 --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/erlang.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +SEMVER_REGEX="^(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))?(\.(0|[1-9][0-9]*))?(\.(0|[1-9][0-9]*))?(\+[0-9]+)?([a-z-].*)?$" + +function check_semver () { + if [[ ! "${1}" =~ ${SEMVER_REGEX} ]]; then + echo Not a semver like version - aborting: "${1}" + exit 1 + fi + export MAJOR=${BASH_REMATCH[1]} + export MINOR=${BASH_REMATCH[3]} + export PATCH=${BASH_REMATCH[5]} + export BUILD=${BASH_REMATCH[7]} +} + +function check_tool_requirements () { + check_semver "${TOOL_VERSION}" + if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" || ! "${BUILD}" ]]; then + echo Invalid version: "${TOOL_VERSION}" + exit 1 + fi +} + +function prepare_tool() { + local version_codename + + version_codename=$(get_distro) + case "$version_codename" in + "bionic") apt_install \ + libodbc1 \ + libssl1.1 \ + libsctp1 \ + ;; + "focal") apt_install \ + libodbc1 \ + libssl1.1 \ + libsctp1 \ + ;; + esac + + local tool_path + tool_path=$(create_tool_path) + + # workaround https://github.com/containerbase/buildpack/issues/377 + ln -sf "$tool_path" /usr/local/erlang +} + +function install_tool () { + local tool_path + local file + local BASE_URL + local ARCH + local version_codename + + tool_path=$(find_tool_path) + + if [[ ! -d "${tool_path}" ]]; then + if [[ $(is_root) -ne 0 ]]; then + echo "${TOOL_NAME} not prepared" + exit 1 + fi + prepare_tool + tool_path=$(find_tool_path) + fi + + ARCH=$(uname -p) + BASE_URL="https://github.com/containerbase/${TOOL_NAME}-prebuild/releases/download" + version_codename=$(get_distro) + + file=$(get_from_url "${BASE_URL}/${TOOL_VERSION}/${TOOL_NAME}-${TOOL_VERSION}-${version_codename}-${ARCH}.tar.xz") + tar -C "${tool_path}" -xf "${file}" +} + +function link_tool () { + local versioned_tool_path + versioned_tool_path=$(find_versioned_tool_path) + + export_tool_env ERL_ROOTDIR "${versioned_tool_path}" + shell_wrapper erl "${versioned_tool_path}/bin" + erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell +} diff --git a/test/erlang/Dockerfile b/test/erlang/Dockerfile index 27e933fa6c..d9eb12c1bc 100644 --- a/test/erlang/Dockerfile +++ b/test/erlang/Dockerfile @@ -1,25 +1,65 @@ ARG IMAGE=containerbase/buildpack -FROM ${IMAGE} +FROM ${IMAGE} as build -ARG APT_HTTP_PROXY +RUN touch /.dummy -# Erlang +# test openshift compatibility 1000<>1001 +COPY --chown=1001:0 test test + +WORKDIR /test + +#-------------------------------------- +# test: erlang (root) +#-------------------------------------- +FROM build as testa + +ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG # renovate: datasource=github-releases lookupName=containerbase/erlang-prebuild versioning=docker RUN install-tool erlang 24.3.3.0 -# Elixir - # renovate: datasource=docker versioning=docker RUN install-tool elixir 1.13.4 -# test openshift compatibility 1000<>1001 -COPY --chown=1001:0 test test -WORKDIR /test +USER 1001 + +RUN set -ex; \ + cd a; \ + mix deps.update --all; + + +#-------------------------------------- +# test: erlang (user,openshift) +#-------------------------------------- +FROM build as testb + +ARG APT_HTTP_PROXY +ARG BUILDPACK_DEBUG + +RUN prepare-tool erlang USER 1001 +# renovate: datasource=github-releases lookupName=containerbase/erlang-prebuild versioning=docker +RUN install-tool erlang 24.3.3.0 + +ARG BUILDPACK_DEBUG + +# renovate: datasource=docker versioning=docker +RUN install-tool elixir 1.13.4 + + RUN set -ex; \ cd a; \ mix deps.update --all; + + +#-------------------------------------- +# final +#-------------------------------------- +FROM build + +COPY --from=testa /.dummy /.dummy +COPY --from=testb /.dummy /.dummy