From 84e671581037e974225b226f8cebd5dd09d53241 Mon Sep 17 00:00:00 2001 From: Leo Romanovsky Date: Tue, 3 Dec 2024 16:02:39 -0800 Subject: [PATCH] Add script for testing rubygem published package in alpine and debian. --- package-testing/ruby-sdk-relay/README.md | 18 ++++++ .../Dockerfile.rubygems.alpine | 18 ++++++ .../Dockerfile.rubygems.debian | 15 +++++ .../published-versions/test-gem.sh | 5 ++ .../ruby-sdk-relay/test-rubygems-install.sh | 57 +++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 package-testing/ruby-sdk-relay/README.md create mode 100644 package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.alpine create mode 100644 package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.debian create mode 100755 package-testing/ruby-sdk-relay/published-versions/test-gem.sh create mode 100755 package-testing/ruby-sdk-relay/test-rubygems-install.sh diff --git a/package-testing/ruby-sdk-relay/README.md b/package-testing/ruby-sdk-relay/README.md new file mode 100644 index 0000000..85e40b0 --- /dev/null +++ b/package-testing/ruby-sdk-relay/README.md @@ -0,0 +1,18 @@ +## Ruby SDK Testing + +This directory contains scripts for testing the Ruby SDK in various environments. + +### Test Ruby Gems Installation + +Verifies that the Ruby SDK can be installed from RubyGems in a variety of environments. + +The `test-rubygems-install.sh` script builds Docker images for Alpine and Debian and runs the test script inside each container. + +You should see output like the following if the tests pass: + +``` +Successfully installed eppo-server-sdk-3.3.0-aarch64-linux +1 gem installed +Installed version: 3.3.0 +✅ Installation successful in debian environment +``` diff --git a/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.alpine b/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.alpine new file mode 100644 index 0000000..e0c1d3a --- /dev/null +++ b/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.alpine @@ -0,0 +1,18 @@ +FROM ruby:3.3-alpine + +# Install bash +RUN apk add --no-cache bash + +# Create a test user +RUN adduser -D testuser + +# Copy script and set permissions while still root +COPY test-gem.sh /home/testuser/ +RUN chmod +x /home/testuser/test-gem.sh && \ + chown testuser:testuser /home/testuser/test-gem.sh + +# Switch to test user +USER testuser +WORKDIR /home/testuser + +CMD ["bash", "/home/testuser/test-gem.sh"] diff --git a/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.debian b/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.debian new file mode 100644 index 0000000..4984be1 --- /dev/null +++ b/package-testing/ruby-sdk-relay/published-versions/Dockerfile.rubygems.debian @@ -0,0 +1,15 @@ +FROM ruby:3.3-slim-bullseye + +# Create a test user +RUN useradd -m testuser + +# Copy script and set permissions while still root +COPY test-gem.sh /home/testuser/ +RUN chmod +x /home/testuser/test-gem.sh && \ + chown testuser:testuser /home/testuser/test-gem.sh + +# Switch to test user +USER testuser +WORKDIR /home/testuser + +CMD ["bash", "/home/testuser/test-gem.sh"] diff --git a/package-testing/ruby-sdk-relay/published-versions/test-gem.sh b/package-testing/ruby-sdk-relay/published-versions/test-gem.sh new file mode 100755 index 0000000..4d04ca4 --- /dev/null +++ b/package-testing/ruby-sdk-relay/published-versions/test-gem.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Install the gem and verify it works +gem install eppo-server-sdk +ruby -r eppo_client -e 'puts "Installed version: #{EppoClient::VERSION}"' diff --git a/package-testing/ruby-sdk-relay/test-rubygems-install.sh b/package-testing/ruby-sdk-relay/test-rubygems-install.sh new file mode 100755 index 0000000..d969b37 --- /dev/null +++ b/package-testing/ruby-sdk-relay/test-rubygems-install.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +# Default environment if none specified +ENV=${1:-"all"} + +# Constants +DOCKERFILE_FORMAT="Dockerfile.rubygems" +DOCKER_TAG_PREFIX="rubygems-test" +TEST_DIRECTORY="published-versions" + +# Ensure we're in the correct directory +cd "$(dirname "$0")" + +# Ensure test script exists +if [ ! -f "$TEST_DIRECTORY/test-gem.sh" ]; then + echo "Error: $TEST_DIRECTORY/test-gem.sh not found" + exit 1 +fi + +# Function to test in specific environment +test_environment() { + local env=$1 + echo "Testing installation in $env environment..." + + # Build from the published-versions directory where both Dockerfile and test-gem.sh are located + docker build -t "$DOCKER_TAG_PREFIX-$env" -f "$TEST_DIRECTORY/$DOCKERFILE_FORMAT.$env" "$TEST_DIRECTORY" + docker run --rm "$DOCKER_TAG_PREFIX-$env" + + local result=$? + if [ $result -eq 0 ]; then + echo "✅ Installation successful in $env environment" + else + echo "❌ Installation failed in $env environment" + fi + return $result +} + +# Run tests based on environment parameter +case $ENV in + "alpine") + test_environment "alpine" + ;; + "debian") + test_environment "debian" + ;; + "all") + failed=0 + test_environment "alpine" || failed=1 + test_environment "debian" || failed=1 + exit $failed + ;; + *) + echo "Unsupported environment: $ENV" + echo "Supported environments: alpine, debian, all" + exit 1 + ;; +esac