From fdeee4460600866fca42502407542e767343f1f3 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 21 Jan 2022 18:10:04 +0100 Subject: [PATCH] feat(ruby): dynamic bundler and cocoapods (#252) * feat(ruby): dynamic bundler and cocoapods * fix: add allow-root arg --- README.md | 7 +++ src/usr/local/buildpack/tools/bundler.sh | 12 +++++ src/usr/local/buildpack/tools/cocoapods.sh | 12 +++++ src/usr/local/buildpack/tools/ruby.sh | 2 + src/usr/local/buildpack/utils/ruby.sh | 39 ++++++++++++++ test/Dockerfile.bionic | 4 +- test/ruby/Dockerfile | 63 +++++++++++++++++----- 7 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 src/usr/local/buildpack/tools/bundler.sh create mode 100644 src/usr/local/buildpack/tools/cocoapods.sh create mode 100644 src/usr/local/buildpack/utils/ruby.sh diff --git a/README.md b/README.md index e7a594d6d..f609f18bc 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ If you make changes to the [`src`](./src/) folder or the [`Dockerfile`](./Docker docker buildx bake ``` +You can use the following command to ignore remote cache for local testing. +This will propably speedup local builds. + +```sh +docker buildx bake --set *.cache-from=[] +``` + ### Test images To run one of the tests use the following command, it will run the java tests from [`test/java`](./test/java/). diff --git a/src/usr/local/buildpack/tools/bundler.sh b/src/usr/local/buildpack/tools/bundler.sh new file mode 100644 index 000000000..765aee91b --- /dev/null +++ b/src/usr/local/buildpack/tools/bundler.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +check_command ruby + +. /usr/local/buildpack/utils/ruby.sh + +gem_install +gem_shell_wrapper + +bundler --version diff --git a/src/usr/local/buildpack/tools/cocoapods.sh b/src/usr/local/buildpack/tools/cocoapods.sh new file mode 100644 index 000000000..b5c353c9f --- /dev/null +++ b/src/usr/local/buildpack/tools/cocoapods.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +check_command ruby + +. /usr/local/buildpack/utils/ruby.sh + +gem_install +gem_shell_wrapper pod + +pod --version --allow-root diff --git a/src/usr/local/buildpack/tools/ruby.sh b/src/usr/local/buildpack/tools/ruby.sh index 28c652ee0..81b6a72d7 100644 --- a/src/usr/local/buildpack/tools/ruby.sh +++ b/src/usr/local/buildpack/tools/ruby.sh @@ -81,6 +81,8 @@ EOM link_wrapper ruby $tool_path/bin link_wrapper gem $tool_path/bin +echo $TOOL_VERSION > $base_path/.version + ruby --version echo "gem $(gem --version)" diff --git a/src/usr/local/buildpack/utils/ruby.sh b/src/usr/local/buildpack/utils/ruby.sh new file mode 100644 index 000000000..69b02f512 --- /dev/null +++ b/src/usr/local/buildpack/utils/ruby.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +function gem_install() { + tool_path=$(find_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 ${tool_path} + + GEM_HOME=$tool_path gem install --bindir $tool_path/bin ${TOOL_NAME} -v ${TOOL_VERSION} + + # TODO: clear gem cache + fi +} + + +function gem_link_wrapper() { + link_wrapper ${1:-$TOOL_NAME} $tool_path/bin +} + +function gem_shell_wrapper () { + local install_dir=$(get_install_dir) + local FILE="${install_dir}/bin/${1:-$TOOL_NAME}" + # TODO: make generic + local ruby_version=$(cat /usr/local/ruby/.version) + tool_path=$(find_tool_path) + check_command ${tool_path}/bin/${1:-$TOOL_NAME} + cat > $FILE <<- EOM +#!/bin/bash + +export GEM_PATH=${tool_path}:/usr/local/ruby/${ruby_version}/lib/ruby/gems/${ruby_version} PATH=${tool_path}/bin:\$PATH + +${1:-$TOOL_NAME} "\$@" +EOM + chmod +x $FILE +} diff --git a/test/Dockerfile.bionic b/test/Dockerfile.bionic index 581e23801..b67b03f98 100644 --- a/test/Dockerfile.bionic +++ b/test/Dockerfile.bionic @@ -82,9 +82,9 @@ RUN install-tool poetry 1.1.12 # renovate: datasource=github-releases lookupName=containerbase/ruby-prebuild versioning=ruby RUN install-tool ruby 3.1.0 # renovate: datasource=rubygems versioning=ruby -RUN install-gem bundler 2.3.5 +RUN install-tool bundler 2.3.5 # renovate: datasource=rubygems versioning=ruby -RUN install-gem cocoapods 1.11.2 +RUN install-tool cocoapods 1.11.2 # renovate: datasource=docker versioning=docker RUN install-tool rust 1.58.1 diff --git a/test/ruby/Dockerfile b/test/ruby/Dockerfile index 73ca269be..a7f8a375b 100644 --- a/test/ruby/Dockerfile +++ b/test/ruby/Dockerfile @@ -30,9 +30,9 @@ COPY --chown=1000:0 test test WORKDIR /test #-------------------------------------- -# test: bundler +# test: bundler (gem) #-------------------------------------- -FROM build as testa +FROM build as test-bundler-a ARG BUILDPACK_DEBUG @@ -52,12 +52,12 @@ RUN set -ex; \ RUN set -ex; \ cd a; \ - bundle lock + bundler lock #-------------------------------------- # test: global bundler #-------------------------------------- -FROM build as testb +FROM build as test-bundler-b ARG BUILDPACK_DEBUG @@ -71,15 +71,34 @@ RUN bundler env RUN set -ex; \ cd a; \ - bundle lock; + bundler lock; SHELL [ "/bin/sh", "-c" ] RUN ruby --version +#-------------------------------------- +# test: bundler (install-tool) +#-------------------------------------- +FROM build as test-bundler-c + +ARG BUILDPACK_DEBUG +USER 1000 + +# renovate: datasource=rubygems versioning=ruby +RUN install-tool bundler 2.3.5 + +RUN ruby --version +RUN bundler env + +RUN set -ex; \ + cd a; \ + bundler lock; + + #-------------------------------------- # test: cocoapods #-------------------------------------- -FROM build as testc +FROM build as test-cocoapods-a ARG BUILDPACK_DEBUG @@ -93,9 +112,9 @@ RUN set -ex; \ pod install; #-------------------------------------- -# test: global cocoapods +# test: global cocoapods (install-gem) #-------------------------------------- -FROM build3 as testd +FROM build3 as test-cocoapods-b ARG BUILDPACK_DEBUG @@ -110,13 +129,33 @@ RUN set -ex; \ pod install; +#-------------------------------------- +# test: cocoapods (install-tool) +#-------------------------------------- +FROM build3 as test-cocoapods-c + +ARG BUILDPACK_DEBUG + +USER 1000 + +# renovate: datasource=rubygems versioning=ruby +RUN install-tool cocoapods 1.11.2 + +RUN pod env + +RUN set -ex; \ + cd b/Project; \ + gem install cocoapods-acknowledgements; \ + pod install; #-------------------------------------- # final #-------------------------------------- FROM build -COPY --from=testa /.dummy /.dummy -COPY --from=testb /.dummy /.dummy -COPY --from=testc /.dummy /.dummy -COPY --from=testd /.dummy /.dummy +COPY --from=test-bundler-a /.dummy /.dummy +COPY --from=test-bundler-b /.dummy /.dummy +COPY --from=test-bundler-c /.dummy /.dummy +COPY --from=test-cocoapods-a /.dummy /.dummy +COPY --from=test-cocoapods-b /.dummy /.dummy +COPY --from=test-cocoapods-c /.dummy /.dummy