|
1 | 1 | #!/bin/bash |
2 | | - |
3 | | -set -e |
| 2 | +# |
| 3 | +# Container entrypoint. Ruby and other toolchains are pre-installed in the |
| 4 | +# image; this script only handles per-run setup (ownership, mise activation) |
| 5 | +# and hands off to whatever docker-compose passes as `command`. |
| 6 | +# |
| 7 | +set -euo pipefail |
4 | 8 |
|
5 | 9 | cd /workspace/sentry |
6 | 10 |
|
7 | | -sudo mkdir -p vendor/gems |
8 | | -sudo chown -R sentry:sentry vendor/gems |
9 | | - |
10 | | -# git config --global --replace-all safe.directory /workspace/sentry |
11 | | -# git config --global --replace-all 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 |
| 11 | +# In CI the workspace is checked out by the runner user (e.g. UID 1001) and |
| 12 | +# then bind-mounted into the container where we run as sentry (UID 1000). |
| 13 | +# Fix ownership once here so bundler, git, etc. can write freely. |
| 14 | +sudo chown -R sentry:sentry /workspace/sentry 2>/dev/null || true |
| 15 | +MISE_BIN="/home/sentry/.local/bin/mise" |
39 | 16 |
|
40 | | - echo "✅ Setup completed for service: $service" |
41 | | -} |
| 17 | +# Git also refuses to operate in directories owned by a different user. |
| 18 | +git config --global --add safe.directory /workspace/sentry 2>/dev/null || true |
42 | 19 |
|
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 | | -} |
| 20 | +if [[ ! -x "$MISE_BIN" ]]; then |
| 21 | + echo "❌ mise not found at $MISE_BIN (it should be installed by the Dockerfile)" |
| 22 | + exit 1 |
| 23 | +fi |
75 | 24 |
|
76 | | -# Parse arguments |
77 | | -if [ "$1" = "--service" ] && [ -n "$2" ]; then |
78 | | - service="$2" |
79 | | - shift 2 |
| 25 | +# Activate mise for this shell so PATH/shims are resolved correctly. |
| 26 | +eval "$("$MISE_BIN" activate bash)" |
80 | 27 |
|
81 | | - run_service_setup "$service" |
| 28 | +# Trust the workspace config so mise will use it without prompting. |
| 29 | +"$MISE_BIN" trust /workspace/sentry >/dev/null |
82 | 30 |
|
83 | | - if [ $# -gt 0 ]; then |
84 | | - start_services_if_needed "$@" |
85 | | - exec "$@" |
86 | | - else |
87 | | - exec bash |
88 | | - fi |
| 31 | +if [[ $# -eq 0 ]]; then |
| 32 | + exec sleep infinity |
89 | 33 | else |
90 | | - start_services_if_needed "$@" |
91 | 34 | exec "$@" |
92 | 35 | fi |
0 commit comments