Skip to content

Commit 727bf14

Browse files
authored
Improved devcontainer setup with e2e test mini infra (#2672)
* Add Gemfile.dev as the shared Gemfile for dev This enables using top-level dir as a place to run rake tasks etc. too without warnings about duped gems in Gemfiles. * Add e2e mini apps with devcontainer setup * Add a basic e2e spec for tracing * Add build_images workflow * Add e2e test workflow * Helpers for e2e tests * Small clean up * Bump docker tag * WIP * Update .gitignore * Remove obsolete vite setting * Fix git dir issue * WIP
1 parent 162ca86 commit 727bf14

File tree

33 files changed

+2346
-79
lines changed

33 files changed

+2346
-79
lines changed

.devcontainer/.env.example

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
IMAGE=bitnami/ruby
1+
# Official Ruby images
2+
IMAGE="ruby:3.4.5-slim-bookworm"
3+
VERSION="3.4.5"
24

3-
# Adjust as needed
4-
TAG=3.4
5+
# IMAGE="jruby:latest"
56

6-
# IMAGE=jruby
7-
# TAG=latest
7+
# E2E testing
8+
SENTRY_DSN="http://user:pass@sentry.localhost/project/42"
9+
SENTRY_DSN_JS="http://user:pass@sentry-js.localhost/project/43"
10+
11+
SENTRY_E2E_RAILS_APP_PORT=4000
12+
SENTRY_E2E_SVELTE_APP_PORT=4001
13+
14+
SENTRY_E2E_RAILS_APP_URL="http://localhost:4000"
15+
SENTRY_E2E_SVELTE_APP_URL="http://localhost:4001"
16+
17+
# Faster builds with compose
18+
COMPOSE_BAKE=true

.devcontainer/Dockerfile

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
ARG IMAGE="bitnami/ruby"
2-
ARG TAG="latest"
1+
ARG IMAGE="ruby"
32

4-
FROM ${IMAGE}:${TAG}
3+
FROM ${IMAGE} AS build
54

6-
USER root
7-
RUN apt-get update && apt-get install -y \
5+
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
sudo \
87
gnupg \
98
git \
109
curl \
1110
wget \
12-
zsh \
13-
vim \
1411
build-essential \
15-
sudo \
12+
pkg-config \
1613
libssl-dev \
1714
libreadline-dev \
1815
zlib1g-dev \
@@ -22,31 +19,32 @@ RUN apt-get update && apt-get install -y \
2219
libncurses5-dev \
2320
libffi-dev \
2421
libgdbm-dev \
22+
sqlite3 \
23+
nodejs \
24+
npm \
25+
chromium \
26+
chromium-driver \
2527
&& apt-get clean \
2628
&& rm -rf /var/lib/apt/lists/*
2729

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
3230
RUN echo "sentry ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/sentry \
3331
&& chmod 0440 /etc/sudoers.d/sentry
3432

33+
RUN groupadd --gid 1000 sentry \
34+
&& useradd --uid 1000 --gid sentry --shell /bin/bash --create-home sentry
35+
3536
WORKDIR /workspace/sentry
3637

3738
RUN chown -R sentry:sentry /workspace/sentry
38-
RUN mkdir /workspace/gems && chown -R sentry:sentry /workspace/gems
3939

40-
ARG TAG=latest
41-
ARG GEM_HOME="/workspace/gems/${TAG}"
40+
ARG VERSION
41+
ARG GEM_HOME="/workspace/sentry/vendor/gems/${VERSION}"
4242

4343
ENV LANG=C.UTF-8 \
4444
BUNDLE_JOBS=4 \
4545
BUNDLE_RETRY=3 \
46-
GEM_HOME=/workspace/gems/${TAG} \
46+
GEM_HOME=/workspace/sentry/vendor/gems/${VERSION} \
4747
PATH=$PATH:${GEM_HOME}/bin \
4848
REDIS_HOST=redis
4949

5050
USER sentry
51-
52-
CMD ["ruby", "--version"]

.devcontainer/devcontainer.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
{
22
"name": "sentry-ruby",
33
"dockerComposeFile": "docker-compose.yml",
4-
"service": "app",
4+
"service": "sentry-dev",
55
"workspaceFolder": "/workspace/sentry",
6+
"features": {
7+
"ghcr.io/devcontainers/features/github-cli": {},
8+
"ghcr.io/nils-geistmann/devcontainers-features/zsh": {},
9+
"ghcr.io/devcontainers-extra/features/npm-packages": {},
10+
"ghcr.io/rocker-org/devcontainer-features/apt-packages": {
11+
"packages": "inotify-tools"
12+
}
13+
},
614
"customizations": {
715
"vscode": {
816
"extensions": [
917
"sleistner.vscode-fileutils",
1018
"Shopify.ruby-lsp"
1119
],
12-
"settings": {}
13-
},
14-
"rubyLsp.rubyVersionManager": {
15-
"identifier": "none"
20+
"editor.formatOnSaveMode": "modifications",
21+
"editor.formatOnSave": true,
22+
"rubyLsp.rubyVersionManager": {
23+
"identifier": "auto"
24+
},
25+
"rubyLsp.formatter": "auto"
1626
}
1727
},
18-
"remoteUser": "sentry",
19-
"postCreateCommand": "ruby --version"
28+
"remoteUser": "sentry"
2029
}

.devcontainer/docker-compose.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
services:
2-
app:
2+
sentry-build: &sentry-build
3+
image: ${DOCKER_IMAGE:-sentry-ruby-devcontainer}:${DOCKER_TAG:-latest}
34
build:
4-
context: .
5-
dockerfile: Dockerfile
5+
context: ..
6+
dockerfile: .devcontainer/Dockerfile
67
args:
78
IMAGE: ${IMAGE}
8-
TAG: ${TAG}
9+
VERSION: ${VERSION}
910
volumes:
1011
- ..:/workspace/sentry:cached
11-
command: sleep infinity
12-
environment:
13-
- REDIS_URL=${REDIS_URL:-redis://redis:6379/0}
12+
working_dir: /workspace/sentry
13+
env_file: [".env"]
14+
15+
sentry-dev:
16+
<<: *sentry-build
17+
entrypoint: ".devcontainer/run --service dev"
18+
command: "sleep infinity"
1419
depends_on:
1520
- redis
1621

22+
sentry-test:
23+
<<: *sentry-build
24+
entrypoint: ".devcontainer/run --service test"
25+
command: ["foreman", "start"]
26+
ports:
27+
- "${SENTRY_E2E_RAILS_APP_PORT}:4000"
28+
- "${SENTRY_E2E_SVELTE_APP_PORT}:4001"
29+
1730
redis:
1831
image: redis:latest
1932
environment:

.devcontainer/run

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd /workspace/sentry
6+
7+
sudo mkdir -p vendor/gems
8+
sudo chown -R sentry:sentry vendor/gems
9+
10+
git config --global --add safe.directory /workspace/sentry
11+
git config --global --add safe.directory /workspace/sentry/vendor/gems/*
12+
13+
sudo chown -R sentry:sentry .
14+
15+
run_service_setup() {
16+
local service="$1"
17+
18+
echo "🚀 Running setup for service: $service"
19+
20+
case "$service" in
21+
"dev")
22+
if ! .devcontainer/setup --with-foreman --only-bundle; then
23+
echo "❌ Setup failed for service: $service"
24+
exit 1
25+
fi
26+
;;
27+
"test")
28+
if ! .devcontainer/setup --with-foreman --only .,spec/apps/rails-mini; then
29+
echo "❌ Setup failed for service: $service"
30+
exit 1
31+
fi
32+
;;
33+
*)
34+
echo "❌ Unknown service: $service"
35+
echo "Available services: dev, test"
36+
exit 1
37+
;;
38+
esac
39+
40+
echo "✅ Setup completed for service: $service"
41+
}
42+
43+
# Function to start services in background
44+
start_services_if_needed() {
45+
# Check if we're running tests (bundle exec rake)
46+
if [[ "$*" == *"bundle exec rake"* ]]; then
47+
echo "🚀 Starting e2e services in background for test execution..."
48+
49+
# Start foreman in background
50+
foreman start &
51+
FOREMAN_PID=$!
52+
53+
# Wait for services to be ready
54+
echo "⏳ Waiting for services to start..."
55+
for i in {1..30}; do
56+
if curl -f http://localhost:4000/health >/dev/null 2>&1 && \
57+
curl -f http://localhost:4001/health >/dev/null 2>&1; then
58+
echo "✅ Services are ready!"
59+
break
60+
fi
61+
62+
if [ $i -eq 30 ]; then
63+
echo "❌ Services failed to start within timeout"
64+
kill $FOREMAN_PID 2>/dev/null || true
65+
exit 1
66+
fi
67+
68+
sleep 2
69+
done
70+
71+
# Set up cleanup trap
72+
trap "echo '🧹 Stopping services...'; kill $FOREMAN_PID 2>/dev/null || true; wait $FOREMAN_PID 2>/dev/null || true" EXIT
73+
fi
74+
}
75+
76+
# Parse arguments
77+
if [ "$1" = "--service" ] && [ -n "$2" ]; then
78+
service="$2"
79+
shift 2
80+
81+
run_service_setup "$service"
82+
83+
if [ $# -gt 0 ]; then
84+
start_services_if_needed "$@"
85+
exec "$@"
86+
else
87+
exec bash
88+
fi
89+
else
90+
start_services_if_needed "$@"
91+
exec "$@"
92+
fi

0 commit comments

Comments
 (0)