Skip to content

Multi ruby devcontainer setup #2568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .devcontainer/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
IMAGE=bitnami/ruby

# Adjust as needed
TAG=3.4

# IMAGE=jruby
# TAG=latest
50 changes: 50 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ARG IMAGE="bitnami/ruby"
ARG TAG="latest"

FROM ${IMAGE}:${TAG}

USER root
RUN apt-get update && apt-get install -y \
gnupg \
git \
curl \
wget \
zsh \
vim \
build-essential \
sudo \
libssl-dev \
libreadline-dev \
zlib1g-dev \
autoconf \
bison \
libyaml-dev \
libncurses5-dev \
libffi-dev \
libgdbm-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd --gid 1000 sentry \
&& useradd --uid 1000 --gid sentry --shell /bin/zsh --create-home sentry

# Add sentry to sudoers with NOPASSWD option
RUN echo "sentry ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/sentry \
&& chmod 0440 /etc/sudoers.d/sentry

WORKDIR /workspace/sentry

RUN chown -R sentry:sentry /workspace/sentry
RUN mkdir /workspace/gems && chown -R sentry:sentry /workspace/gems

ARG TAG=latest

ENV LANG=C.UTF-8 \
BUNDLE_JOBS=4 \
BUNDLE_RETRY=3 \
GEM_HOME=/workspace/gems/${TAG} \
REDIS_HOST=redis

USER sentry

CMD ["ruby", "--version"]
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "sentry-ruby",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace/sentry",
"customizations": {
"vscode": {
"extensions": [
"sleistner.vscode-fileutils",
"Shopify.ruby-lsp"
]
}
},
"remoteUser": "sentry",
"postCreateCommand": "ruby --version"
}
22 changes: 22 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
IMAGE: ${IMAGE}
TAG: ${TAG}
volumes:
- ..:/workspace/sentry:cached
command: sleep infinity
environment:
- REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
depends_on:
- redis

redis:
image: redis:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- "6379:6379"
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ And if you have any questions, please feel free to reach out on [Discord].
If you use editors that support [VS Code-style multi-root workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces),
such as VS Code, Cursor...etc., opening the editor with `sentry-ruby.code-workspace` file will provide a better development experience.

## Working in a devcontainer

If you use [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, you can open the project with the devcontainer by running `Remote-Containers: Reopen in Container` command.

The devcontainer is configured with `.devcontainer/.env` file, that you need to create:

```bash
cp .devcontainer/.env.example .devcontainer/.env
```

This file defines which specific image and Ruby version will be used to run the code. Edit it whenever you need to use a different image or Ruby version.

## Contribute To Individual Gems

- Install the dependencies of a specific gem by running `bundle` in it's subdirectory. I.e:
Expand Down
64 changes: 37 additions & 27 deletions sentry-ruby.code-workspace
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
{
"folders": [
{
"path": "sentry-ruby"
},
{
"path": "sentry-rails"
},
{
"path": "sentry-sidekiq"
},
{
"path": "sentry-delayed_job"
},
{
"path": "sentry-resque"
},
{
"path": "sentry-opentelemetry"
},
{
"path": ".github"
}
],
"extensions": {
"recommendations": [
"Shopify.ruby-lsp"
]
"folders": [
{
"path": ".devcontainer"
},
{
"path": ".github",
},
{
"path": ".",
"name": "root"
},
{
"path": "sentry-ruby"
},
{
"path": "sentry-rails"
},
{
"path": "sentry-sidekiq"
},
{
"path": "sentry-delayed_job"
},
{
"path": "sentry-resque"
},
{
"path": "sentry-opentelemetry"
},
{
"path": "sentry-raven"
}
],
"extensions": {
"recommendations": [
"Shopify.ruby-lsp"
]
}
}
12 changes: 6 additions & 6 deletions sentry-ruby/spec/sentry/breadcrumb/redis_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "spec_helper"

RSpec.describe :redis_logger do
let(:redis) { Redis.new(host: "127.0.0.1") }
let(:redis) { Redis.new(host: REDIS_HOST) }

before do
perform_basic_setup do |config|
Expand All @@ -20,7 +20,7 @@
expect(result).to eq("OK")
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
category: "db.redis",
data: { commands: [{ command: "SET", key: "key" }], server: "127.0.0.1:6379/0" }
data: { commands: [{ command: "SET", key: "key" }], server: "#{REDIS_HOST}:6379/0" }
)
end
end
Expand All @@ -34,7 +34,7 @@
expect(result).to eq("OK")
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
category: "db.redis",
data: { commands: [{ command: "SET", key: "key", arguments: "value" }], server: "127.0.0.1:6379/0" }
data: { commands: [{ command: "SET", key: "key", arguments: "value" }], server: "#{REDIS_HOST}:6379/0" }
)
end

Expand Down Expand Up @@ -62,7 +62,7 @@
expect(result.key?("uptime_in_days")).to eq(true)
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
category: "db.redis",
data: { commands: [{ command: "INFO", key: nil }], server: "127.0.0.1:6379/0" }
data: { commands: [{ command: "INFO", key: nil }], server: "#{REDIS_HOST}:6379/0" }
)
end
end
Expand All @@ -88,7 +88,7 @@
{ command: "INCR", key: "counter" },
{ command: "EXEC", key: nil }
],
server: "127.0.0.1:6379/0"
server: "#{REDIS_HOST}:6379/0"
}
)
end
Expand All @@ -105,7 +105,7 @@
expect(result).to eq("OK")
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
category: "db.redis",
data: { commands: [{ command: "SET", key: "key" }], server: "127.0.0.1:6379/0" }
data: { commands: [{ command: "SET", key: "key" }], server: "#{REDIS_HOST}:6379/0" }
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "spec_helper"

RSpec.describe Sentry::Redis do
let(:redis) { Redis.new(host: "127.0.0.1") }
let(:redis) { Redis.new(host: REDIS_HOST) }

context "with tracing enabled" do
before do
Expand Down Expand Up @@ -33,7 +33,7 @@
expect(request_span.data).to eq({
"db.name" => 0,
"db.system" => "redis",
"server.address" => "127.0.0.1",
"server.address" => REDIS_HOST,
"server.port" => 6379
})
end
Expand Down
2 changes: 2 additions & 0 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
coverage_dir File.join(__FILE__, "../../coverage")
end

REDIS_HOST = ENV.fetch("REDIS_HOST", "127.0.0.1")

if ENV["CI"]
require 'simplecov-cobertura'
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
Expand Down
Loading