From 9fae28d9c8d5dc077642365d3114a99e1cf5c7d1 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Wed, 14 May 2025 14:51:52 +0200 Subject: [PATCH 1/3] added ruby support --- template/Dockerfile | 17 +++++++++++++++-- template/server/contexts.py | 3 +++ template/test.Dockerfile | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/template/Dockerfile b/template/Dockerfile index 199a5cb0..8b4decc4 100644 --- a/template/Dockerfile +++ b/template/Dockerfile @@ -13,10 +13,12 @@ ENV PIP_DEFAULT_TIMEOUT=100 \ JUPYTER_CONFIG_PATH="/root/.jupyter" \ IPYTHON_CONFIG_PATH="/root/.ipython" \ SERVER_PATH="/root/.server" \ - R_VERSION=4.4.2 + R_VERSION=4.4.2 \ + RUBY_VERSION=3.4.3 ENV R_HOME=/opt/R/${R_VERSION} \ - JAVA_HOME=/opt/java/openjdk + JAVA_HOME=/opt/java/openjdk \ + RUBY_HOME=/opt/ruby/${RUBY_VERSION} # Install Jupyter COPY ./requirements.txt requirements.txt @@ -78,5 +80,16 @@ RUN wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3 unzip ijava-1.3.0.zip && \ python install.py --sys-prefix +# Install Ruby using ruby-build +RUN git clone https://github.com/rbenv/ruby-build.git ~/.ruby-build +RUN ~/.ruby-build/bin/ruby-build ${RUBY_VERSION} ${RUBY_HOME} +ENV PATH="${RUBY_HOME}/bin:${PATH}" +ENV PATH="/root/.local/share/gem/ruby/${RUBY_VERSION%.*}.0/bin:${PATH}" + +# Install IRuby +RUN gem install --user-install rubygems-requirements-system && \ + gem install --user-install iruby && \ + iruby register --force + # Setup entrypoint for local development ENTRYPOINT $JUPYTER_CONFIG_PATH/start-up.sh diff --git a/template/server/contexts.py b/template/server/contexts.py index d078dc6e..ffda1a61 100644 --- a/template/server/contexts.py +++ b/template/server/contexts.py @@ -29,6 +29,9 @@ def normalize_language(language: Optional[str]) -> str: if language == "ts": return "typescript" + if language == "ruby" or language == "rb": + return "ruby3" + return language diff --git a/template/test.Dockerfile b/template/test.Dockerfile index f9302081..b9f62751 100644 --- a/template/test.Dockerfile +++ b/template/test.Dockerfile @@ -16,7 +16,10 @@ ENV PIP_DEFAULT_TIMEOUT=100 \ PIP_NO_CACHE_DIR=1 \ JUPYTER_CONFIG_PATH="/root/.jupyter" \ IPYTHON_CONFIG_PATH="/root/.ipython" \ - SERVER_PATH="/root/.server" + SERVER_PATH="/root/.server" \ + RUBY_VERSION=3.4.3 + +ENV RUBY_HOME=/opt/ruby/${RUBY_VERSION} # Install Jupyter COPY ./template/requirements.txt requirements.txt @@ -36,6 +39,17 @@ RUN chmod +x /usr/bin/deno RUN deno jupyter --unstable --install COPY ./template/deno.json /root/.local/share/jupyter/kernels/deno/kernel.json +# Install Ruby using ruby-build +RUN git clone https://github.com/rbenv/ruby-build.git ~/.ruby-build +RUN ~/.ruby-build/bin/ruby-build ${RUBY_VERSION} ${RUBY_HOME} +ENV PATH="${RUBY_HOME}/bin:${PATH}" +ENV PATH="/root/.local/share/gem/ruby/${RUBY_VERSION%.*}.0/bin:${PATH}" + +# Install IRuby +RUN gem install --user-install rubygems-requirements-system && \ + gem install --user-install iruby && \ + iruby register --force + # Create separate virtual environment for server RUN python -m venv $SERVER_PATH/.venv From a69802877fd8601b6b23c783eafc9fb005b0bec9 Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Wed, 14 May 2025 15:07:21 +0200 Subject: [PATCH 2/3] added changeset --- .changeset/shy-months-beg.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shy-months-beg.md diff --git a/.changeset/shy-months-beg.md b/.changeset/shy-months-beg.md new file mode 100644 index 00000000..f34d2e68 --- /dev/null +++ b/.changeset/shy-months-beg.md @@ -0,0 +1,5 @@ +--- +'@e2b/code-interpreter-template': patch +--- + +added Ruby support From ec131879e70299bc0fc836e0afdd35929ca7739a Mon Sep 17 00:00:00 2001 From: Mish <10400064+mishushakov@users.noreply.github.com> Date: Wed, 14 May 2025 15:10:22 +0200 Subject: [PATCH 3/3] added tests for the ruby kernel --- js/tests/defaultKernels.test.ts | 7 +++++++ python/tests/async/test_async_default_kernels.py | 5 +++++ python/tests/sync/test_default_kernels.py | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/js/tests/defaultKernels.test.ts b/js/tests/defaultKernels.test.ts index 5750644a..6c9bbb3a 100644 --- a/js/tests/defaultKernels.test.ts +++ b/js/tests/defaultKernels.test.ts @@ -23,3 +23,10 @@ sandboxTest('test ts kernel errors', async ({ sandbox }) => { }) expect(output.error?.name).toEqual('TypeScriptCompilerError') }) + +sandboxTest('test ruby kernel', async ({ sandbox }) => { + const output = await sandbox.runCode('puts "Hello World!"', { + language: 'ruby', + }) + expect(output.logs.stdout).toEqual(['Hello World!\n']) +}) diff --git a/python/tests/async/test_async_default_kernels.py b/python/tests/async/test_async_default_kernels.py index 83f92746..27b28cef 100644 --- a/python/tests/async/test_async_default_kernels.py +++ b/python/tests/async/test_async_default_kernels.py @@ -21,3 +21,8 @@ async def test_ts_kernel_errors(async_sandbox: AsyncSandbox): ) assert execution.error is not None assert execution.error.name == "TypeScriptCompilerError" + + +async def test_ruby_kernel(async_sandbox: AsyncSandbox): + execution = await async_sandbox.run_code("puts 'Hello, World!'", language="ruby") + assert execution.logs.stdout == ["Hello, World!\n"] diff --git a/python/tests/sync/test_default_kernels.py b/python/tests/sync/test_default_kernels.py index 0695defd..78c6210d 100644 --- a/python/tests/sync/test_default_kernels.py +++ b/python/tests/sync/test_default_kernels.py @@ -30,3 +30,8 @@ def test_ts_kernel_errors(sandbox: Sandbox): execution = sandbox.run_code("import x from 'module';", language="ts") assert execution.error is not None assert execution.error.name == "TypeScriptCompilerError" + + +def test_ruby_kernel(sandbox: Sandbox): + execution = sandbox.run_code("puts 'Hello, World!'", language="ruby") + assert execution.logs.stdout == ["Hello, World!\n"]