|
| 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