Skip to content

Commit 6e45dfd

Browse files
Nathan ParkerNathan Parker
authored andcommitted
api import fixes and dockerfile syntax issues
1 parent 2b52baf commit 6e45dfd

File tree

9 files changed

+569
-3
lines changed

9 files changed

+569
-3
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ USER ome
7878
EXPOSE 8001
7979

8080
# Health check
81+
# Use shell form to allow variable expansion for PORT
8182
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
82-
CMD curl -f http://localhost:${PORT:-8001}/health || exit 1
83+
CMD sh -c 'curl -f http://localhost:${PORT:-8001}/health || exit 1'
8384

8485
# Set entrypoint
8586
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

README_TESTING.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Direct Cloud Run Testing
2+
3+
This directory contains scripts for testing the Cloud Run service directly, bypassing the CI/CD pipeline.
4+
5+
## Scripts
6+
7+
### `test_cloud_run_direct.py`
8+
Direct testing script that sends requests to the deployed Cloud Run service and helps debug 500 errors.
9+
10+
**Usage:**
11+
```bash
12+
# Set the service URL (defaults to the production URL)
13+
export SERVICE_URL="https://supply-graph-ai-1085931013579.us-west1.run.app"
14+
export USE_AUTH=true
15+
16+
# Run the tests
17+
python test_cloud_run_direct.py
18+
```
19+
20+
**What it tests:**
21+
- List OKH manifests (to check storage service)
22+
- Create OKH manifest
23+
- Create OKW facility
24+
- Match OKH to OKW (if OKH creation succeeds)
25+
26+
### `check_cloud_logs.sh`
27+
Helper script to check Cloud Run logs for errors.
28+
29+
**Usage:**
30+
```bash
31+
# Set project and service name (optional, has defaults)
32+
export PROJECT_ID="nathan-playground-368310"
33+
export SERVICE_NAME="supply-graph-ai"
34+
35+
# Run the script
36+
./check_cloud_logs.sh
37+
```
38+
39+
**What it shows:**
40+
- Recent ERROR level logs
41+
- Logs with "Error" or "Exception" in text
42+
- Recent 500 errors
43+
- Full tracebacks for recent errors
44+
45+
## Workflow
46+
47+
1. **Run the test script:**
48+
```bash
49+
python test_cloud_run_direct.py
50+
```
51+
52+
2. **If you see 500 errors, check the logs:**
53+
```bash
54+
./check_cloud_logs.sh
55+
```
56+
57+
3. **Or check logs manually:**
58+
```bash
59+
# View recent errors
60+
gcloud logging read \
61+
'resource.type=cloud_run_revision AND resource.labels.service_name=supply-graph-ai AND severity>=ERROR' \
62+
--limit 50 --format json \
63+
--project=nathan-playground-368310
64+
```
65+
66+
4. **Fix the issues found in the logs**
67+
68+
5. **Re-run the test script to verify fixes**
69+
70+
## Authentication
71+
72+
The scripts use GCP identity tokens for authentication. Make sure you're authenticated:
73+
74+
```bash
75+
gcloud auth login
76+
gcloud auth application-default login
77+
```
78+
79+
Or set an explicit token:
80+
```bash
81+
export IDENTITY_TOKEN=$(gcloud auth print-identity-token)
82+
```

check_cloud_logs.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Helper script to check Cloud Run logs for errors
3+
4+
SERVICE_NAME="${SERVICE_NAME:-supply-graph-ai}"
5+
PROJECT_ID="${PROJECT_ID:-nathan-playground-368310}"
6+
7+
echo "=========================================="
8+
echo "Cloud Run Logs - Recent Errors"
9+
echo "=========================================="
10+
echo ""
11+
12+
echo "1. Recent ERROR level logs:"
13+
gcloud logging read \
14+
"resource.type=cloud_run_revision AND resource.labels.service_name=${SERVICE_NAME} AND severity>=ERROR" \
15+
--limit 20 \
16+
--format json \
17+
--project="${PROJECT_ID}" | jq -r '.[] | "\(.timestamp) [\(.severity)] \(.textPayload // .jsonPayload.message // "No message")"'
18+
19+
echo ""
20+
echo "=========================================="
21+
echo "2. Recent logs with 'Error' or 'Exception' in text:"
22+
gcloud logging read \
23+
"resource.type=cloud_run_revision AND resource.labels.service_name=${SERVICE_NAME} AND (textPayload=~\"Error\" OR textPayload=~\"Exception\" OR jsonPayload.message=~\"Error\" OR jsonPayload.message=~\"Exception\")" \
24+
--limit 20 \
25+
--format json \
26+
--project="${PROJECT_ID}" | jq -r '.[] | "\(.timestamp) [\(.severity)] \(.textPayload // .jsonPayload.message // .jsonPayload.error // "No message")"'
27+
28+
echo ""
29+
echo "=========================================="
30+
echo "3. Recent 500 errors:"
31+
gcloud logging read \
32+
"resource.type=cloud_run_revision AND resource.labels.service_name=${SERVICE_NAME} AND jsonPayload.status_code=500" \
33+
--limit 20 \
34+
--format json \
35+
--project="${PROJECT_ID}" | jq -r '.[] | "\(.timestamp) \(.jsonPayload.message // .textPayload // "No message")"'
36+
37+
echo ""
38+
echo "=========================================="
39+
echo "4. Full traceback for recent errors:"
40+
gcloud logging read \
41+
"resource.type=cloud_run_revision AND resource.labels.service_name=${SERVICE_NAME} AND severity>=ERROR" \
42+
--limit 5 \
43+
--format json \
44+
--project="${PROJECT_ID}" | jq -r '.[] | select(.textPayload != null) | "\(.timestamp)\n\(.textPayload)\n---"'
45+

get_cloud_run_token.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Helper script to get a valid identity token for Cloud Run
3+
4+
SERVICE_URL="${1:-https://supply-graph-ai-1085931013579.us-west1.run.app}"
5+
6+
echo "Getting identity token for Cloud Run service..."
7+
echo "Service URL: $SERVICE_URL"
8+
echo ""
9+
10+
# Try with audience first (for service accounts)
11+
echo "Attempting to get token with audience..."
12+
if gcloud auth print-identity-token --audiences="$SERVICE_URL" 2>/dev/null; then
13+
echo ""
14+
echo "✓ Success! Token generated with correct audience."
15+
exit 0
16+
fi
17+
18+
# Try without audience (for user accounts - may not work)
19+
echo "Attempting to get token without audience..."
20+
if TOKEN=$(gcloud auth print-identity-token 2>/dev/null); then
21+
echo "$TOKEN"
22+
echo ""
23+
echo "⚠ Token generated but may not work for Cloud Run."
24+
echo "If you get 401 errors, you may need to:"
25+
echo " 1. Grant yourself the invoker role:"
26+
echo " gcloud run services add-iam-policy-binding supply-graph-ai \\"
27+
echo " --member='user:$(gcloud config get-value account)' \\"
28+
echo " --role='roles/run.invoker' \\"
29+
echo " --region=us-west1"
30+
echo ""
31+
echo " 2. Or use a service account:"
32+
echo " gcloud auth activate-service-account SERVICE_ACCOUNT_EMAIL --key-file=KEY_FILE"
33+
exit 0
34+
fi
35+
36+
echo "❌ Failed to get identity token"
37+
echo ""
38+
echo "Make sure you're authenticated:"
39+
echo " gcloud auth login"
40+
echo " gcloud auth application-default login"
41+
exit 1

get_token_user_account.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Get identity token for user account to access Cloud Run
3+
4+
SERVICE_URL="${1:-https://supply-graph-ai-1085931013579.us-west1.run.app}"
5+
SERVICE_ACCOUNT="${2:-supply-graph-ai@nathan-playground-368310.iam.gserviceaccount.com}"
6+
7+
echo "Getting identity token for Cloud Run service..."
8+
echo "Service URL: $SERVICE_URL"
9+
echo "Service Account: $SERVICE_ACCOUNT"
10+
echo ""
11+
12+
# Method 1: Try impersonating the service account (if you have permission)
13+
echo "Method 1: Impersonating service account..."
14+
if TOKEN=$(gcloud auth print-identity-token --impersonate-service-account="$SERVICE_ACCOUNT" --audiences="$SERVICE_URL" 2>/dev/null); then
15+
echo "$TOKEN"
16+
echo ""
17+
echo "✓ Success! Token generated using service account impersonation."
18+
exit 0
19+
fi
20+
21+
# Method 2: Try without impersonation (user account token)
22+
echo "Method 2: Using user account token (may not work)..."
23+
if TOKEN=$(gcloud auth print-identity-token 2>/dev/null); then
24+
echo "$TOKEN"
25+
echo ""
26+
echo "⚠ Token generated but may not work for Cloud Run."
27+
echo ""
28+
echo "If you get 401 errors, try:"
29+
echo " 1. Grant yourself permission to impersonate the service account:"
30+
echo " gcloud iam service-accounts add-iam-policy-binding $SERVICE_ACCOUNT \\"
31+
echo " --member='user:$(gcloud config get-value account)' \\"
32+
echo " --role='roles/iam.serviceAccountTokenCreator'"
33+
echo ""
34+
echo " 2. Then use service account impersonation:"
35+
echo " gcloud auth print-identity-token --impersonate-service-account=$SERVICE_ACCOUNT --audiences=$SERVICE_URL"
36+
exit 0
37+
fi
38+
39+
echo "❌ Failed to get identity token"
40+
exit 1

src/core/api/routes/okh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ async def create_okh(
147147
processing_time = (datetime.now() - start_time).total_seconds()
148148

149149
# Create enhanced response using the proper OKHResponse structure
150-
from ...models.base import APIStatus
150+
# APIStatus is already imported at the top of the file
151151

152152
result_dict = result.to_dict() if hasattr(result, "to_dict") else result
153153
response_data = {

src/core/api/routes/okw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ async def create_okw(
200200
processing_time = (datetime.now() - start_time).total_seconds()
201201

202202
# Create enhanced response matching OKWResponse structure
203-
from ...models.base import APIStatus
203+
# APIStatus is already imported at the top of the file
204204

205205
response_data = {
206206
**facility_dict, # Include all facility fields directly

0 commit comments

Comments
 (0)