diff --git a/containers/images/ruby-3.4/Dockerfile b/containers/images/ruby-3.4/Dockerfile new file mode 100644 index 0000000..2c9a3c3 --- /dev/null +++ b/containers/images/ruby-3.4/Dockerfile @@ -0,0 +1,151 @@ +FROM sourcemation/debian-13-slim + +# This Dockerfile originates from the official Docker Hub image. We have made modifications +# to improve readability and maintainability. Importantly, our images are automatically +# rebuilt and updated. +# License: MIT + +ARG BUILD_DATE +ARG TARGETARCH + +LABEL name="ruby-3.4" \ + vendor="Sourcemation" \ + url="https://Sourcemation.com/"\ + licenses="2-clause BSDL " \ + created="$BUILD_DATE" \ + architecture="$TARGETARCH" \ + summary="Ruby 3.4 on Debian 13 Slim Container" \ + description="Provides Ruby 3.4 on Debian 13 Slim Container" \ + version="3.4.10" \ + org.opencontainers.image.source="https://github.com/Sourcemation/images" \ + io.k8s.display-name="Ruby 3.4 on Debian 13 Slim Container" \ + io.k8s.description="Provides Ruby 3.4 on Debian 13 Slim Container" \ + io.openshift.tags="ruby-3.4 debian-13-slim" + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + ; \ + apt-get dist-clean + +# skip installing gem documentation with `gem install`/`gem update` +RUN set -eux; \ + mkdir -p /usr/local/etc; \ + echo 'gem: --no-document' >> /usr/local/etc/gemrc + +ENV LANG C.UTF-8 + +# https://www.ruby-lang.org/en/news/2026/07/14/ruby-3-4-10-released/ +ENV RUBY_VERSION 3.4.10 +ENV RUBY_DOWNLOAD_URL https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.10.tar.xz +ENV RUBY_DOWNLOAD_SHA256 6f32ad662baafc228d12030dbcd284f83b034dd4337b300dc84ac74d11a1eb68 + +# some of ruby's build scripts are written in ruby +# we purge system ruby later to make sure our final image uses what we just built +RUN set -eux; \ + \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + dpkg-dev \ + libgdbm-dev \ + ruby \ + autoconf \ + bzip2 \ + g++ \ + gcc \ + libbz2-dev \ + libffi-dev \ + libgdbm-compat-dev \ + libglib2.0-dev \ + libgmp-dev \ + libncurses-dev \ + libssl-dev \ + libxml2-dev \ + libxslt-dev \ + libyaml-dev \ + make \ + wget \ + xz-utils \ + zlib1g-dev \ + ; \ + \ + rustArch=; \ + dpkgArch="$(dpkg --print-architecture)"; \ + case "$dpkgArch" in \ + 'amd64') rustArch='x86_64-unknown-linux-gnu'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.28.2/x86_64-unknown-linux-gnu/rustup-init'; rustupSha256='20a06e644b0d9bd2fbdbfd52d42540bdde820ea7df86e92e533c073da0cdd43c' ;; \ + 'arm64') rustArch='aarch64-unknown-linux-gnu'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.28.2/aarch64-unknown-linux-gnu/rustup-init'; rustupSha256='e3853c5a252fca15252d07cb23a1bdd9377a8c6f3efa01531109281ae47f841c' ;; \ + esac; \ + \ + if [ -n "$rustArch" ]; then \ + mkdir -p /tmp/rust; \ + \ + wget -O /tmp/rust/rustup-init "$rustupUrl"; \ + echo "$rustupSha256 */tmp/rust/rustup-init" | sha256sum --check --strict; \ + chmod +x /tmp/rust/rustup-init; \ + \ + export RUSTUP_HOME='/tmp/rust/rustup' CARGO_HOME='/tmp/rust/cargo'; \ + export PATH="$CARGO_HOME/bin:$PATH"; \ + /tmp/rust/rustup-init -y --no-modify-path --profile minimal --default-toolchain '1.91.1' --default-host "$rustArch"; \ + \ + rustc --version; \ + cargo --version; \ + fi; \ + \ + wget -O ruby.tar.xz "$RUBY_DOWNLOAD_URL"; \ + echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \ + \ + mkdir -p /usr/src/ruby; \ + tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \ + rm ruby.tar.xz; \ + \ + cd /usr/src/ruby; \ + \ + autoconf; \ + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ + ./configure \ + --build="$gnuArch" \ + --disable-install-doc \ + --enable-shared \ + ${rustArch:+--enable-yjit} \ + ; \ + make -j "$(nproc)"; \ + make install; \ + \ + rm -rf /tmp/rust; \ + apt-mark auto '.*' > /dev/null; \ + apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ +# https://manpages.debian.org/bookworm/dpkg/dpkg-query.1.en.html#S (we ignore diversions and it'll be really unusual for more than one package to provide any given .so file) + | awk 'sub(":$", "", $1) { print $1 }' \ + | sort -u \ + | xargs -r apt-mark manual \ + ; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + apt-get dist-clean; \ + \ + cd /; \ + rm -r /usr/src/ruby; \ +# verify we have no "ruby" packages installed + if dpkg -l | grep -i ruby; then exit 1; fi; \ + [ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \ +# rough smoke test + ruby --version; \ + gem --version; \ + bundle --version + +# don't create ".bundle" in all our apps +ENV GEM_HOME /usr/local/bundle +ENV BUNDLE_SILENCE_ROOT_WARNING=1 \ + BUNDLE_APP_CONFIG="$GEM_HOME" +ENV PATH $GEM_HOME/bin:$PATH +RUN set -eux; \ + mkdir "$GEM_HOME"; \ +# adjust permissions of GEM_HOME for running "gem install" as an arbitrary user + chmod 1777 "$GEM_HOME" + +CMD [ "irb" ] diff --git a/containers/images/ruby-3.4/README.md b/containers/images/ruby-3.4/README.md new file mode 100644 index 0000000..2a3a1ce --- /dev/null +++ b/containers/images/ruby-3.4/README.md @@ -0,0 +1,78 @@ +# Ruby 3.4 packaged by Sourcemation + +An open source purely object-oriented programming language with a focus on +simplicity and readability. Ruby 3.4 introduces performance improvements, YJIT +optimizations, and modernized language features. + +This Ruby distribution is built from official source distributions by the +Sourcemation automation team. It is based on the `sourcemation/debian-13-slim` +base image, providing a highly optimized, clean, and secure environment. + +## Usage + +Run a temporary container with the Ruby REPL (`irb`) (don't forget the +`-it` argument). + +```bash +docker run --rm -it sourcemation/ruby-3.4:latest +``` + +### Advanced usage examples + +Example: create a Gemfile for a Ruby project, in your current directory: + +```bash +docker run --rm -v "${PWD}:/your-project" -w "/your-project" sourcemation/ruby-3.4:latest bundle init +``` + +## Environment Vars, Ports, Volumes + +This image uses the following environment variables: + +``` +PATH="/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +GEM_HOME="/usr/local/bundle" +BUNDLE_APP_CONFIG="/usr/local/bundle" +APP_VERSION="3.4.10" +APP_NAME="ruby-3.4" +``` + +This image exposes no ports by default. + +Please note that the ports need to be either manually forwarded with the +`-p` option or let Docker choose some for you with the `-P` option. + +## Contributing and Issues + +We welcome your contributions! If you have new feature requests, want to report +a bug, or wish to submit a pull request with your code or an image request, you +can do so via the Sourcemation GitHub repository for this image. + +- [Open a new issue (for feature requests, bug reports, or image requests)](https://github.com/Sourcemation/images/issues/new/choose) +- [Submit a pull request](https://github.com/Sourcemation/images/compare) + +**Disclaimer:** The `sourcemation/ruby-3.4` image is not affiliated with +Yukihiro Matsumoto and the Ruby Community [the Ruby +Community](https://www.ruby-lang.org/en/community/). The respective +entities own the trademarks mentioned in the offering. The +`sourcemation/ruby-3.4` image is a separate project and is maintained by +[Sourcemation](https://sourcemation.com). + +## Extra notes + +### Image and its components Risk Analysis report + +A detailed risk analysis report of the image and its components can be +found on the [Sourcemation +platform](https://www.sourcemation.com). + +For more information, check out the [overview of +Ruby](https://www.ruby-lang.org/en/about/) page. + +### Licenses + +The base license for the solution (Ruby) is the [Ruby +License](https://www.ruby-lang.org/en/about/license.txt). The licenses +for each component shipped as part of this image can be found on [the +image's appropriate Sourcemation +entry](https://www.sourcemation.com). diff --git a/containers/images/ruby-3.4/init.sh b/containers/images/ruby-3.4/init.sh new file mode 100755 index 0000000..837a6da --- /dev/null +++ b/containers/images/ruby-3.4/init.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# --------------------------------------------------- +# Automated build process for the ruby 3.4 image +# Author: Alex Baranowski +# e-mail: aleksander.baranowski@yahoo.pl +# --------------------------------------------------- + +APP="ruby-3.4" + +# Updating repository metadata and downloading the latest available version of the application +echo "Checking the latest available version of the $APP" +VERSION=$(git ls-remote --refs --tags https://github.com/ruby/ruby.git | grep -o 'v3_4_[0-9]*$' | tr -d 'v' | tr '_' '.' | sort --version-sort --reverse | head -1) + +# Exit with an error if the returned version contains anything other than digits and dots +[[ ! $VERSION =~ ^[0-9.]+$ ]] && exit 1 + +# Now get the SHA256 sum +echo "Fetching and computing SHA256 for ruby-$VERSION" +SHA256_SUM=$(curl -s "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-${VERSION}.tar.xz" | sha256sum | awk '{print $1}') + +# Replacing the version number and SHA256 in the Dockerfile +sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" Dockerfile || exit 1 +sed -i "s/ENV RUBY_VERSION [0-9.]*/ENV RUBY_VERSION $VERSION/" Dockerfile || exit 1 +sed -i "s|ENV RUBY_DOWNLOAD_URL .*|ENV RUBY_DOWNLOAD_URL https://cache.ruby-lang.org/pub/ruby/3.4/ruby-${VERSION}.tar.xz|" Dockerfile || exit 1 +sed -i "s/ENV RUBY_DOWNLOAD_SHA256 [a-f0-9]*/ENV RUBY_DOWNLOAD_SHA256 $SHA256_SUM/" Dockerfile || exit 1 + +# Replacing the version number in README.md +sed -i "s/APP_VERSION=\"[^\"]*\"/APP_VERSION=\"$VERSION\"/" README.md || exit 1 + +echo "Finished setting up the $APP $VERSION image" diff --git a/containers/images/ruby-4.0/Dockerfile b/containers/images/ruby-4.0/Dockerfile new file mode 100644 index 0000000..6a51912 --- /dev/null +++ b/containers/images/ruby-4.0/Dockerfile @@ -0,0 +1,152 @@ +FROM sourcemation/debian-13-slim + +# This Dockerfile originates from the official Docker Hub image. We have made modifications +# to improve readability and maintainability. Importantly, our images are automatically +# rebuilt and updated. +# License: MIT + +ARG BUILD_DATE +ARG TARGETARCH + +LABEL name="ruby-4.0" \ + vendor="Sourcemation" \ + url="https://Sourcemation.com/"\ + licenses="2-clause BSDL " \ + created="$BUILD_DATE" \ + architecture="$TARGETARCH" \ + summary="Ruby 4.0 on Debian 13 Slim Container" \ + description="Provides Ruby 4.0 on Debian 13 Slim Container" \ + version="4.0.6" \ + org.opencontainers.image.source="https://github.com/Sourcemation/images" \ + io.k8s.display-name="Ruby 4.0 on Debian 13 Slim Container" \ + io.k8s.description="Provides Ruby 4.0 on Debian 13 Slim Container" \ + io.openshift.tags="ruby-4.0 debian-13-slim" + +RUN set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + ; \ + apt-get dist-clean + +# skip installing gem documentation with `gem install`/`gem update` +RUN set -eux; \ + mkdir -p /usr/local/etc; \ + echo 'gem: --no-document' >> /usr/local/etc/gemrc + +ENV LANG C.UTF-8 + +# https://www.ruby-lang.org/en/news/2026/07/14/ruby-4-0-6-released/ +ENV RUBY_VERSION 4.0.6 +ENV RUBY_DOWNLOAD_URL https://cache.ruby-lang.org/pub/ruby/4.0/ruby-4.0.6.tar.xz +ENV RUBY_DOWNLOAD_SHA256 9c9d121fe3314ea7c801e690b9de981d2b9d12d7849db99c27482468a541ba0a + +# some of ruby's build scripts are written in ruby +# we purge system ruby later to make sure our final image uses what we just built +RUN set -eux; \ + \ + savedAptMark="$(apt-mark showmanual)"; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + dpkg-dev \ + libgdbm-dev \ + ruby \ + autoconf \ + bzip2 \ + g++ \ + gcc \ + libbz2-dev \ + libffi-dev \ + libgdbm-compat-dev \ + libglib2.0-dev \ + libgmp-dev \ + libncurses-dev \ + libssl-dev \ + libxml2-dev \ + libxslt-dev \ + libyaml-dev \ + make \ + wget \ + xz-utils \ + zlib1g-dev \ + ; \ + \ + rustArch=; \ + dpkgArch="$(dpkg --print-architecture)"; \ + case "$dpkgArch" in \ + 'amd64') rustArch='x86_64-unknown-linux-gnu'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.28.2/x86_64-unknown-linux-gnu/rustup-init'; rustupSha256='20a06e644b0d9bd2fbdbfd52d42540bdde820ea7df86e92e533c073da0cdd43c' ;; \ + 'arm64') rustArch='aarch64-unknown-linux-gnu'; rustupUrl='https://static.rust-lang.org/rustup/archive/1.28.2/aarch64-unknown-linux-gnu/rustup-init'; rustupSha256='e3853c5a252fca15252d07cb23a1bdd9377a8c6f3efa01531109281ae47f841c' ;; \ + esac; \ + \ + if [ -n "$rustArch" ]; then \ + mkdir -p /tmp/rust; \ + \ + wget -O /tmp/rust/rustup-init "$rustupUrl"; \ + echo "$rustupSha256 */tmp/rust/rustup-init" | sha256sum --check --strict; \ + chmod +x /tmp/rust/rustup-init; \ + \ + export RUSTUP_HOME='/tmp/rust/rustup' CARGO_HOME='/tmp/rust/cargo'; \ + export PATH="$CARGO_HOME/bin:$PATH"; \ + /tmp/rust/rustup-init -y --no-modify-path --profile minimal --default-toolchain '1.91.1' --default-host "$rustArch"; \ + \ + rustc --version; \ + cargo --version; \ + fi; \ + \ + wget -O ruby.tar.xz "$RUBY_DOWNLOAD_URL"; \ + echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.xz" | sha256sum --check --strict; \ + \ + mkdir -p /usr/src/ruby; \ + tar -xJf ruby.tar.xz -C /usr/src/ruby --strip-components=1; \ + rm ruby.tar.xz; \ + \ + cd /usr/src/ruby; \ + \ + autoconf; \ + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ + ./configure \ + --build="$gnuArch" \ + --disable-install-doc \ + --enable-shared \ + ${rustArch:+--enable-yjit} \ + ${rustArch:+--enable-zjit} \ + ; \ + make -j "$(nproc)"; \ + make install; \ + \ + rm -rf /tmp/rust; \ + apt-mark auto '.*' > /dev/null; \ + apt-mark manual $savedAptMark > /dev/null; \ + find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \ + | awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \ + | sort -u \ + | xargs -r dpkg-query --search \ +# https://manpages.debian.org/bookworm/dpkg/dpkg-query.1.en.html#S (we ignore diversions and it'll be really unusual for more than one package to provide any given .so file) + | awk 'sub(":$", "", $1) { print $1 }' \ + | sort -u \ + | xargs -r apt-mark manual \ + ; \ + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ + apt-get dist-clean; \ + \ + cd /; \ + rm -r /usr/src/ruby; \ +# verify we have no "ruby" packages installed + if dpkg -l | grep -i ruby; then exit 1; fi; \ + [ "$(command -v ruby)" = '/usr/local/bin/ruby' ]; \ +# rough smoke test + ruby --version; \ + gem --version; \ + bundle --version + +# don't create ".bundle" in all our apps +ENV GEM_HOME /usr/local/bundle +ENV BUNDLE_SILENCE_ROOT_WARNING=1 \ + BUNDLE_APP_CONFIG="$GEM_HOME" +ENV PATH $GEM_HOME/bin:$PATH +RUN set -eux; \ + mkdir "$GEM_HOME"; \ +# adjust permissions of GEM_HOME for running "gem install" as an arbitrary user + chmod 1777 "$GEM_HOME" + +CMD [ "irb" ] diff --git a/containers/images/ruby-4.0/README.md b/containers/images/ruby-4.0/README.md new file mode 100644 index 0000000..af16c02 --- /dev/null +++ b/containers/images/ruby-4.0/README.md @@ -0,0 +1,78 @@ +# Ruby 4.0 packaged by Sourcemation + +An open source purely object-oriented programming language with a focus on +simplicity and readability. Ruby 4.0 introduces performance improvements, YJIT +optimizations, and modernized language features. + +This Ruby distribution is built from official source distributions by the +Sourcemation automation team. It is based on the `sourcemation/debian-13-slim` +base image, providing a highly optimized, clean, and secure environment. + +## Usage + +Run a temporary container with the Ruby REPL (`irb`) (don't forget the +`-it` argument). + +```bash +docker run --rm -it sourcemation/ruby-4.0:latest +``` + +### Advanced usage examples + +Example: create a Gemfile for a Ruby project, in your current directory: + +```bash +docker run --rm -v "${PWD}:/your-project" -w "/your-project" sourcemation/ruby-4.0:latest bundle init +``` + +## Environment Vars, Ports, Volumes + +This image uses the following environment variables: + +``` +PATH="/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +GEM_HOME="/usr/local/bundle" +BUNDLE_APP_CONFIG="/usr/local/bundle" +APP_VERSION="4.0.6" +APP_NAME="ruby-4.0" +``` + +This image exposes no ports by default. + +Please note that the ports need to be either manually forwarded with the +`-p` option or let Docker choose some for you with the `-P` option. + +## Contributing and Issues + +We welcome your contributions! If you have new feature requests, want to report +a bug, or wish to submit a pull request with your code or an image request, you +can do so via the Sourcemation GitHub repository for this image. + +- [Open a new issue (for feature requests, bug reports, or image requests)](https://github.com/Sourcemation/images/issues/new/choose) +- [Submit a pull request](https://github.com/Sourcemation/images/compare) + +**Disclaimer:** The `sourcemation/ruby-4.0` image is not affiliated with +Yukihiro Matsumoto and the Ruby Community [the Ruby +Community](https://www.ruby-lang.org/en/community/). The respective +entities own the trademarks mentioned in the offering. The +`sourcemation/ruby-4.0` image is a separate project and is maintained by +[Sourcemation](https://sourcemation.com). + +## Extra notes + +### Image and its components Risk Analysis report + +A detailed risk analysis report of the image and its components can be +found on the [Sourcemation +platform](https://www.sourcemation.com). + +For more information, check out the [overview of +Ruby](https://www.ruby-lang.org/en/about/) page. + +### Licenses + +The base license for the solution (Ruby) is the [Ruby +License](https://www.ruby-lang.org/en/about/license.txt). The licenses +for each component shipped as part of this image can be found on [the +image's appropriate Sourcemation +entry](https://www.sourcemation.com). diff --git a/containers/images/ruby-4.0/init.sh b/containers/images/ruby-4.0/init.sh new file mode 100755 index 0000000..f06c18a --- /dev/null +++ b/containers/images/ruby-4.0/init.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# --------------------------------------------------- +# Automated build process for the ruby 4.0 image +# Author: Alex Baranowski +# e-mail: aleksander.baranowski@yahoo.pl +# --------------------------------------------------- + +APP="ruby-4.0" + +# Updating repository metadata and downloading the latest available version of the application +echo "Checking the latest available version of the $APP" +VERSION=$(git ls-remote --refs --tags https://github.com/ruby/ruby.git | grep -o 'v4\.0\.[0-9]*$' | tr -d 'v' | sort --version-sort --reverse | head -1) + +# Exit with an error if the returned version contains anything other than digits and dots +[[ ! $VERSION =~ ^[0-9.]+$ ]] && exit 1 + +# Now get the SHA256 sum +echo "Fetching and computing SHA256 for ruby-$VERSION" +SHA256_SUM=$(curl -s "https://cache.ruby-lang.org/pub/ruby/4.0/ruby-${VERSION}.tar.xz" | sha256sum | awk '{print $1}') + +# Replacing the version number and SHA256 in the Dockerfile +sed -i "s/version=\"[^\"]*\"/version=\"$VERSION\"/" Dockerfile || exit 1 +sed -i "s/ENV RUBY_VERSION [0-9.]*/ENV RUBY_VERSION $VERSION/" Dockerfile || exit 1 +sed -i "s|ENV RUBY_DOWNLOAD_URL .*|ENV RUBY_DOWNLOAD_URL https://cache.ruby-lang.org/pub/ruby/4.0/ruby-${VERSION}.tar.xz|" Dockerfile || exit 1 +sed -i "s/ENV RUBY_DOWNLOAD_SHA256 [a-f0-9]*/ENV RUBY_DOWNLOAD_SHA256 $SHA256_SUM/" Dockerfile || exit 1 + +# Replacing the version number in README.md +sed -i "s/APP_VERSION=\"[^\"]*\"/APP_VERSION=\"$VERSION\"/" README.md || exit 1 + +echo "Finished setting up the $APP $VERSION image" diff --git a/containers/tests/test_ruby_3_4.py b/containers/tests/test_ruby_3_4.py new file mode 100644 index 0000000..dda5867 --- /dev/null +++ b/containers/tests/test_ruby_3_4.py @@ -0,0 +1,90 @@ +import pytest +import subprocess +import os + +def test_ruby_installed(): + result = subprocess.run(['ruby', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Ruby is not installed or not found in system PATH" + assert "ruby" in result.stdout, f"Unexpected output from 'ruby -v': {result.stdout}" + +def test_ruby_version(): + result = subprocess.run(['ruby', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Ruby is not installed or not found in system PATH" + + version_info = result.stdout.split()[1] + major_version = int(version_info.split('.')[0]) + minor_version = int(version_info.split('.')[1]) + + assert major_version == 3 and minor_version == 4, f"Expected Ruby version 3.4, but got: {version_info}" + +def test_bundler_installed(): + result = subprocess.run(['gem', 'list', 'bundler'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Failed to check installed gems" + assert "bundler" in result.stdout, "Bundler is not installed" + +def test_install_gem(): + install_result = subprocess.run(['gem', 'install', 'sinatra'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert install_result.returncode == 0, f"Failed to install gem 'sinatra': {install_result.stderr}" + + list_result = subprocess.run(['gem', 'list', 'sinatra'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert list_result.returncode == 0, "Failed to list installed gems" + assert "sinatra" in list_result.stdout, "Gem 'sinatra' was not installed successfully" + + subprocess.run(['gem', 'uninstall', 'sinatra', '-a', '-x'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + +def test_run_simple_ruby_program(): + ruby_program = """ + puts 'Ruby is working!' + """ + with open('testRuby.rb', 'w') as f: + f.write(ruby_program) + + result = subprocess.run(['ruby', 'testRuby.rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run Ruby program: {result.stderr}" + assert "Ruby is working!" in result.stdout, "Ruby program did not produce expected output" + + os.remove('testRuby.rb') + +def test_irb(): + irb_command = "echo 'puts \"IRB is working!\"; exit' | irb --simple-prompt" + result = subprocess.run(irb_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run IRB: {result.stderr}" + assert "IRB is working!" in result.stdout, "IRB did not produce expected output" + +def test_gemspec_processing(): + gemspec_content = """ + Gem::Specification.new do |s| + s.name = 'test_gem' + s.version = '0.1.0' + s.summary = 'A simple test gem' + s.authors = ['Jan Kowalski'] + s.email = ['jan.kowalski@example.com'] + s.files = [] + end + """ + with open('test_gem.gemspec', 'w') as f: + f.write(gemspec_content) + + result = subprocess.run(['gem', 'build', 'test_gem.gemspec'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to build gem from gemspec: {result.stderr}" + assert "Successfully built RubyGem" in result.stdout, "Gemspec did not build as expected" + + os.remove('test_gem.gemspec') + os.remove('test_gem-0.1.0.gem') + +def test_ruby_unicode(): + ruby_program = """ + puts "Unicode test: Ω α ω" + """ + with open('testUnicodeRuby.rb', 'w') as f: + f.write(ruby_program) + + result = subprocess.run(['ruby', 'testUnicodeRuby.rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run Ruby program: {result.stderr}" + assert "Unicode test: Ω α ω" in result.stdout, "Ruby program did not produce expected Unicode output" + + os.remove('testUnicodeRuby.rb') diff --git a/containers/tests/test_ruby_4_0.py b/containers/tests/test_ruby_4_0.py new file mode 100644 index 0000000..a4d8e0c --- /dev/null +++ b/containers/tests/test_ruby_4_0.py @@ -0,0 +1,90 @@ +import pytest +import subprocess +import os + +def test_ruby_installed(): + result = subprocess.run(['ruby', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Ruby is not installed or not found in system PATH" + assert "ruby" in result.stdout, f"Unexpected output from 'ruby -v': {result.stdout}" + +def test_ruby_version(): + result = subprocess.run(['ruby', '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Ruby is not installed or not found in system PATH" + + version_info = result.stdout.split()[1] + major_version = int(version_info.split('.')[0]) + minor_version = int(version_info.split('.')[1]) + + assert major_version == 4, f"Expected Ruby version 4.x, but got: {version_info}" + +def test_bundler_installed(): + result = subprocess.run(['gem', 'list', 'bundler'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert result.returncode == 0, "Failed to check installed gems" + assert "bundler" in result.stdout, "Bundler is not installed" + +def test_install_gem(): + install_result = subprocess.run(['gem', 'install', 'sinatra'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert install_result.returncode == 0, f"Failed to install gem 'sinatra': {install_result.stderr}" + + list_result = subprocess.run(['gem', 'list', 'sinatra'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + assert list_result.returncode == 0, "Failed to list installed gems" + assert "sinatra" in list_result.stdout, "Gem 'sinatra' was not installed successfully" + + subprocess.run(['gem', 'uninstall', 'sinatra', '-a', '-x'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + +def test_run_simple_ruby_program(): + ruby_program = """ + puts 'Ruby is working!' + """ + with open('testRuby.rb', 'w') as f: + f.write(ruby_program) + + result = subprocess.run(['ruby', 'testRuby.rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run Ruby program: {result.stderr}" + assert "Ruby is working!" in result.stdout, "Ruby program did not produce expected output" + + os.remove('testRuby.rb') + +def test_irb(): + irb_command = "echo 'puts \"IRB is working!\"; exit' | irb --simple-prompt" + result = subprocess.run(irb_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run IRB: {result.stderr}" + assert "IRB is working!" in result.stdout, "IRB did not produce expected output" + +def test_gemspec_processing(): + gemspec_content = """ + Gem::Specification.new do |s| + s.name = 'test_gem' + s.version = '0.1.0' + s.summary = 'A simple test gem' + s.authors = ['Jan Kowalski'] + s.email = ['jan.kowalski@example.com'] + s.files = [] + end + """ + with open('test_gem.gemspec', 'w') as f: + f.write(gemspec_content) + + result = subprocess.run(['gem', 'build', 'test_gem.gemspec'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to build gem from gemspec: {result.stderr}" + assert "Successfully built RubyGem" in result.stdout, "Gemspec did not build as expected" + + os.remove('test_gem.gemspec') + os.remove('test_gem-0.1.0.gem') + +def test_ruby_unicode(): + ruby_program = """ + puts "Unicode test: Ω α ω" + """ + with open('testUnicodeRuby.rb', 'w') as f: + f.write(ruby_program) + + result = subprocess.run(['ruby', 'testUnicodeRuby.rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + + assert result.returncode == 0, f"Failed to run Ruby program: {result.stderr}" + assert "Unicode test: Ω α ω" in result.stdout, "Ruby program did not produce expected Unicode output" + + os.remove('testUnicodeRuby.rb')