Skip to content

Commit 6907a46

Browse files
committed
update
1 parent 927fb0e commit 6907a46

1 file changed

Lines changed: 81 additions & 6 deletions

File tree

.github/workflows/deployment-strategy.yml

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ jobs:
9393
-e KC_DB_USERNAME=postgres \
9494
-e KC_DB_PASSWORD=postgres \
9595
-p 8080:8080 \
96-
quay.io/keycloak/keycloak:26.2 start-dev
96+
-v "$(pwd)/keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json:ro" \
97+
quay.io/keycloak/keycloak:26.2 start-dev --import-realm
9798
9899
# Wait for Keycloak
99100
echo "⏳ Waiting for Keycloak to be ready..."
@@ -136,26 +137,100 @@ jobs:
136137
bun install
137138
bun run build
138139
139-
# Set environment variables for backend
140+
# Set environment variables for backend (all required variables)
141+
export NODE_ENV="alpha"
142+
export BASE_URL="http://localhost:3001"
143+
export PORT=3001
140144
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/keycloak"
141145
export KEYCLOAK_BASE_URL="http://localhost:8080"
142146
export KEYCLOAK_REALM="proxy-smart"
143-
export PORT=3001
147+
export FHIR_SERVER_BASE="https://hapi.fhir.org/baseR4" # Use public FHIR server for alpha testing
148+
149+
# Start the FHIR proxy server in background with proper logging
150+
echo "🚀 Starting backend server with the following config:"
151+
echo " BASE_URL: $BASE_URL"
152+
echo " PORT: $PORT"
153+
echo " KEYCLOAK_BASE_URL: $KEYCLOAK_BASE_URL"
154+
echo " FHIR_SERVER_BASE: $FHIR_SERVER_BASE"
144155
145-
# Start the FHIR proxy server in background
146-
nohup bun run start &
156+
# Start backend and capture output
157+
nohup bun run dist/index.js > ../backend.log 2>&1 &
147158
echo $! > ../backend.pid
148159
cd ..
149160
150161
# Wait for backend to be ready
151162
echo "⏳ Waiting for FHIR backend..."
152-
if ! timeout 120s bash -c 'until curl -f http://localhost:3001/health; do sleep 5; done'; then
163+
max_backend_attempts=24 # 2 minutes with 5-second intervals
164+
backend_attempt=1
165+
166+
while [ $backend_attempt -le $max_backend_attempts ]; do
167+
echo "🔄 Checking backend connectivity... (attempt $backend_attempt/$max_backend_attempts)"
168+
169+
# First check if the port is responding at all
170+
if curl -s --connect-timeout 3 --max-time 5 http://localhost:3001 >/dev/null 2>&1; then
171+
echo "✅ Backend port is responding, checking health endpoint..."
172+
173+
# Try the simpler status endpoint first (may be more forgiving)
174+
status_response=$(curl -s --connect-timeout 3 --max-time 5 http://localhost:3001/status 2>&1)
175+
status_exit_code=$?
176+
177+
if [ $status_exit_code -eq 0 ]; then
178+
echo "✅ FHIR backend status check passed"
179+
echo "Status response: $status_response"
180+
break
181+
else
182+
echo "⚠️ Status endpoint failed, trying health endpoint..."
183+
184+
# Now try the health endpoint
185+
health_response=$(curl -s --connect-timeout 3 --max-time 5 http://localhost:3001/health 2>&1)
186+
health_exit_code=$?
187+
188+
if [ $health_exit_code -eq 0 ]; then
189+
echo "✅ FHIR backend health check passed"
190+
echo "Health response: $health_response"
191+
break
192+
else
193+
echo "⚠️ Health endpoint also failed (exit code: $health_exit_code)"
194+
echo "Health response: $health_response"
195+
echo "Status response: $status_response"
196+
echo "⏳ Backend may still be initializing, waiting..."
197+
fi
198+
fi
199+
else
200+
echo "⏳ Backend port not responding yet, waiting..."
201+
202+
# Check if process is still running
203+
if [ -f backend.pid ]; then
204+
backend_pid=$(cat backend.pid)
205+
if ! ps -p $backend_pid > /dev/null 2>&1; then
206+
echo "❌ Backend process has died! PID: $backend_pid"
207+
echo "📋 Backend logs:"
208+
cat backend.log || echo "No backend.log file found"
209+
210+
# Set failure outputs
211+
echo "fhir_server_url=" >> $GITHUB_OUTPUT
212+
echo "keycloak_url=http://localhost:8080" >> $GITHUB_OUTPUT
213+
echo "deployment_status=failed" >> $GITHUB_OUTPUT
214+
echo "deployment_target=local" >> $GITHUB_OUTPUT
215+
216+
exit 1
217+
fi
218+
fi
219+
220+
sleep 5
221+
backend_attempt=$((backend_attempt + 1))
222+
fi
223+
done
224+
225+
if [ $backend_attempt -gt $max_backend_attempts ]; then
153226
echo "❌ FHIR backend failed to start within timeout"
154227
echo "📋 Checking backend logs..."
155228
if [ -f backend.pid ]; then
156229
echo "Backend PID: $(cat backend.pid)"
157230
ps aux | grep $(cat backend.pid) || echo "Backend process not running"
158231
fi
232+
echo "📋 Backend logs:"
233+
cat backend.log || echo "No backend.log file found"
159234
160235
# Set failure outputs
161236
echo "fhir_server_url=" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)