Skip to content

Commit ca4a6d2

Browse files
authored
Multi ruby devcontainer setup (#2568)
* Add .devcontainer setup * Update code workspace configuration * Use REDIS_HOST in specs * Update CONTRIBUTING.md
1 parent 8e3a4c5 commit ca4a6d2

File tree

9 files changed

+154
-35
lines changed

9 files changed

+154
-35
lines changed

.devcontainer/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
IMAGE=bitnami/ruby
2+
3+
# Adjust as needed
4+
TAG=3.4
5+
6+
# IMAGE=jruby
7+
# TAG=latest

.devcontainer/Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
ARG IMAGE="bitnami/ruby"
2+
ARG TAG="latest"
3+
4+
FROM ${IMAGE}:${TAG}
5+
6+
USER root
7+
RUN apt-get update && apt-get install -y \
8+
gnupg \
9+
git \
10+
curl \
11+
wget \
12+
zsh \
13+
vim \
14+
build-essential \
15+
sudo \
16+
libssl-dev \
17+
libreadline-dev \
18+
zlib1g-dev \
19+
autoconf \
20+
bison \
21+
libyaml-dev \
22+
libncurses5-dev \
23+
libffi-dev \
24+
libgdbm-dev \
25+
&& apt-get clean \
26+
&& rm -rf /var/lib/apt/lists/*
27+
28+
RUN groupadd --gid 1000 sentry \
29+
&& useradd --uid 1000 --gid sentry --shell /bin/zsh --create-home sentry
30+
31+
# Add sentry to sudoers with NOPASSWD option
32+
RUN echo "sentry ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/sentry \
33+
&& chmod 0440 /etc/sudoers.d/sentry
34+
35+
WORKDIR /workspace/sentry
36+
37+
RUN chown -R sentry:sentry /workspace/sentry
38+
RUN mkdir /workspace/gems && chown -R sentry:sentry /workspace/gems
39+
40+
ARG TAG=latest
41+
42+
ENV LANG=C.UTF-8 \
43+
BUNDLE_JOBS=4 \
44+
BUNDLE_RETRY=3 \
45+
GEM_HOME=/workspace/gems/${TAG} \
46+
REDIS_HOST=redis
47+
48+
USER sentry
49+
50+
CMD ["ruby", "--version"]

.devcontainer/devcontainer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "sentry-ruby",
3+
"dockerComposeFile": "docker-compose.yml",
4+
"service": "app",
5+
"workspaceFolder": "/workspace/sentry",
6+
"customizations": {
7+
"vscode": {
8+
"extensions": [
9+
"sleistner.vscode-fileutils",
10+
"Shopify.ruby-lsp"
11+
]
12+
}
13+
},
14+
"remoteUser": "sentry",
15+
"postCreateCommand": "ruby --version"
16+
}

.devcontainer/docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
app:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
args:
7+
IMAGE: ${IMAGE}
8+
TAG: ${TAG}
9+
volumes:
10+
- ..:/workspace/sentry:cached
11+
command: sleep infinity
12+
environment:
13+
- REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
14+
depends_on:
15+
- redis
16+
17+
redis:
18+
image: redis:latest
19+
environment:
20+
- ALLOW_EMPTY_PASSWORD=yes
21+
ports:
22+
- "6379:6379"

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ And if you have any questions, please feel free to reach out on [Discord].
2222
If you use editors that support [VS Code-style multi-root workspaces](https://code.visualstudio.com/docs/editor/multi-root-workspaces),
2323
such as VS Code, Cursor...etc., opening the editor with `sentry-ruby.code-workspace` file will provide a better development experience.
2424

25+
## Working in a devcontainer
26+
27+
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.
28+
29+
The devcontainer is configured with `.devcontainer/.env` file, that you need to create:
30+
31+
```bash
32+
cp .devcontainer/.env.example .devcontainer/.env
33+
```
34+
35+
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.
36+
2537
## Contribute To Individual Gems
2638

2739
- Install the dependencies of a specific gem by running `bundle` in it's subdirectory. I.e:

sentry-ruby.code-workspace

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
11
{
2-
"folders": [
3-
{
4-
"path": "sentry-ruby"
5-
},
6-
{
7-
"path": "sentry-rails"
8-
},
9-
{
10-
"path": "sentry-sidekiq"
11-
},
12-
{
13-
"path": "sentry-delayed_job"
14-
},
15-
{
16-
"path": "sentry-resque"
17-
},
18-
{
19-
"path": "sentry-opentelemetry"
20-
},
21-
{
22-
"path": ".github"
23-
}
24-
],
25-
"extensions": {
26-
"recommendations": [
27-
"Shopify.ruby-lsp"
28-
]
2+
"folders": [
3+
{
4+
"path": ".devcontainer"
5+
},
6+
{
7+
"path": ".github",
8+
},
9+
{
10+
"path": ".",
11+
"name": "root"
12+
},
13+
{
14+
"path": "sentry-ruby"
15+
},
16+
{
17+
"path": "sentry-rails"
18+
},
19+
{
20+
"path": "sentry-sidekiq"
21+
},
22+
{
23+
"path": "sentry-delayed_job"
24+
},
25+
{
26+
"path": "sentry-resque"
27+
},
28+
{
29+
"path": "sentry-opentelemetry"
30+
},
31+
{
32+
"path": "sentry-raven"
2933
}
34+
],
35+
"extensions": {
36+
"recommendations": [
37+
"Shopify.ruby-lsp"
38+
]
39+
}
3040
}

sentry-ruby/spec/sentry/breadcrumb/redis_logger_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "spec_helper"
44

55
RSpec.describe :redis_logger do
6-
let(:redis) { Redis.new(host: "127.0.0.1") }
6+
let(:redis) { Redis.new(host: REDIS_HOST) }
77

88
before do
99
perform_basic_setup do |config|
@@ -20,7 +20,7 @@
2020
expect(result).to eq("OK")
2121
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
2222
category: "db.redis",
23-
data: { commands: [{ command: "SET", key: "key" }], server: "127.0.0.1:6379/0" }
23+
data: { commands: [{ command: "SET", key: "key" }], server: "#{REDIS_HOST}:6379/0" }
2424
)
2525
end
2626
end
@@ -34,7 +34,7 @@
3434
expect(result).to eq("OK")
3535
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
3636
category: "db.redis",
37-
data: { commands: [{ command: "SET", key: "key", arguments: "value" }], server: "127.0.0.1:6379/0" }
37+
data: { commands: [{ command: "SET", key: "key", arguments: "value" }], server: "#{REDIS_HOST}:6379/0" }
3838
)
3939
end
4040

@@ -62,7 +62,7 @@
6262
expect(result.key?("uptime_in_days")).to eq(true)
6363
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
6464
category: "db.redis",
65-
data: { commands: [{ command: "INFO", key: nil }], server: "127.0.0.1:6379/0" }
65+
data: { commands: [{ command: "INFO", key: nil }], server: "#{REDIS_HOST}:6379/0" }
6666
)
6767
end
6868
end
@@ -88,7 +88,7 @@
8888
{ command: "INCR", key: "counter" },
8989
{ command: "EXEC", key: nil }
9090
],
91-
server: "127.0.0.1:6379/0"
91+
server: "#{REDIS_HOST}:6379/0"
9292
}
9393
)
9494
end
@@ -105,7 +105,7 @@
105105
expect(result).to eq("OK")
106106
expect(Sentry.get_current_scope.breadcrumbs.peek).to have_attributes(
107107
category: "db.redis",
108-
data: { commands: [{ command: "SET", key: "key" }], server: "127.0.0.1:6379/0" }
108+
data: { commands: [{ command: "SET", key: "key" }], server: "#{REDIS_HOST}:6379/0" }
109109
)
110110
end
111111
end

sentry-ruby/spec/sentry/redis_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "spec_helper"
44

55
RSpec.describe Sentry::Redis do
6-
let(:redis) { Redis.new(host: "127.0.0.1") }
6+
let(:redis) { Redis.new(host: REDIS_HOST) }
77

88
context "with tracing enabled" do
99
before do
@@ -33,7 +33,7 @@
3333
expect(request_span.data).to eq({
3434
"db.name" => 0,
3535
"db.system" => "redis",
36-
"server.address" => "127.0.0.1",
36+
"server.address" => REDIS_HOST,
3737
"server.port" => 6379
3838
})
3939
end

sentry-ruby/spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
coverage_dir File.join(__FILE__, "../../coverage")
1919
end
2020

21+
REDIS_HOST = ENV.fetch("REDIS_HOST", "127.0.0.1")
22+
2123
if ENV["CI"]
2224
require 'simplecov-cobertura'
2325
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter

0 commit comments

Comments
 (0)