Skip to content

Commit

Permalink
feat(ruby): dynamic bundler and cocoapods (#252)
Browse files Browse the repository at this point in the history
* feat(ruby): dynamic bundler and cocoapods

* fix: add allow-root arg
  • Loading branch information
viceice authored Jan 21, 2022
1 parent 26cf7d7 commit fdeee44
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
12 changes: 12 additions & 0 deletions src/usr/local/buildpack/tools/bundler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

check_command ruby

. /usr/local/buildpack/utils/ruby.sh

gem_install
gem_shell_wrapper

bundler --version
12 changes: 12 additions & 0 deletions src/usr/local/buildpack/tools/cocoapods.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/usr/local/buildpack/tools/ruby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
39 changes: 39 additions & 0 deletions src/usr/local/buildpack/utils/ruby.sh
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions test/Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 51 additions & 12 deletions test/ruby/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

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

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

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

0 comments on commit fdeee44

Please sign in to comment.