Skip to content

Commit 27a2a5a

Browse files
Nathan ParkerNathan Parker
authored andcommitted
ci/cd troubleshooting
1 parent eda5b06 commit 27a2a5a

File tree

1 file changed

+84
-13
lines changed

1 file changed

+84
-13
lines changed

.github/workflows/ci-cd.yml

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,28 +293,99 @@ jobs:
293293
--format="value(spec.template.spec.containers[0].image)" 2>/dev/null || echo "")
294294
if [ -n "${CURRENT_IMAGE}" ]; then
295295
echo "Current service image: ${CURRENT_IMAGE}"
296+
echo "Checking current service secrets..."
297+
gcloud run services describe supply-graph-ai \
298+
--region="${{ env.GCP_REGION }}" \
299+
--format="yaml(spec.template.spec.containers[0].env)" 2>/dev/null | grep -A 5 "secretKeyRef" || echo "No secrets currently configured"
296300
else
297301
echo "Service does not exist yet"
298302
fi
299303
304+
echo ""
305+
echo "Checking for secrets in Secret Manager..."
306+
echo "Available secrets:"
307+
gcloud secrets list --project="${PROJECT_ID}" --format="table(name)" 2>/dev/null || echo "Could not list secrets"
308+
300309
# Deploy with explicit image override (image flag must be provided)
301310
# Using explicit variable to ensure it's set correctly
302311
IMAGE_TO_DEPLOY="${AR_IMAGE}"
303312
echo "Final image to deploy: ${IMAGE_TO_DEPLOY}"
304313
305-
gcloud run deploy supply-graph-ai \
306-
--image "${IMAGE_TO_DEPLOY}" \
307-
--service-account "${SA_EMAIL}" \
308-
--region "${{ env.GCP_REGION }}" \
309-
--platform managed \
310-
--no-allow-unauthenticated \
311-
--set-env-vars ENVIRONMENT=production \
312-
--set-secrets API_KEYS=api-keys:latest,LLM_ENCRYPTION_KEY=llm-encryption-key:latest \
313-
--memory 1Gi \
314-
--cpu 2 \
315-
--timeout 300 \
316-
--max-instances 100 \
317-
--min-instances 1
314+
# Check if secrets exist and build secrets list conditionally
315+
SECRETS_LIST=""
316+
if gcloud secrets describe api-keys --project="${PROJECT_ID}" &>/dev/null; then
317+
echo "Found api-keys secret, including in deployment"
318+
SECRETS_LIST="API_KEYS=api-keys:latest"
319+
else
320+
echo "api-keys secret not found, skipping (optional)"
321+
fi
322+
323+
if gcloud secrets describe llm-encryption-key --project="${PROJECT_ID}" &>/dev/null; then
324+
echo "Found llm-encryption-key secret, including in deployment"
325+
if [ -n "${SECRETS_LIST}" ]; then
326+
SECRETS_LIST="${SECRETS_LIST},LLM_ENCRYPTION_KEY=llm-encryption-key:latest"
327+
else
328+
SECRETS_LIST="LLM_ENCRYPTION_KEY=llm-encryption-key:latest"
329+
fi
330+
else
331+
echo "llm-encryption-key secret not found, skipping (optional)"
332+
fi
333+
334+
# Build deployment command with conditional secrets
335+
# If secrets don't exist but service has them configured, we need to clear them
336+
echo "Executing deployment command..."
337+
338+
# Check if service exists and has secrets configured that don't exist in Secret Manager
339+
SERVICE_HAS_INVALID_SECRETS=false
340+
if gcloud run services describe supply-graph-ai --region="${{ env.GCP_REGION }}" &>/dev/null; then
341+
# Check if service has api-keys or llm-encryption-key configured
342+
if gcloud run services describe supply-graph-ai \
343+
--region="${{ env.GCP_REGION }}" \
344+
--format="value(spec.template.spec.containers[0].env)" | grep -q "api-keys\|llm-encryption-key"; then
345+
# Check if these secrets actually exist
346+
if ! gcloud secrets describe api-keys --project="${PROJECT_ID}" &>/dev/null || \
347+
! gcloud secrets describe llm-encryption-key --project="${PROJECT_ID}" &>/dev/null; then
348+
SERVICE_HAS_INVALID_SECRETS=true
349+
echo "Service has secrets configured that don't exist in Secret Manager. Will clear them."
350+
fi
351+
fi
352+
fi
353+
354+
# Build base deployment command
355+
DEPLOY_ARGS=(
356+
"supply-graph-ai"
357+
"--image" "${IMAGE_TO_DEPLOY}"
358+
"--service-account" "${SA_EMAIL}"
359+
"--region" "${{ env.GCP_REGION }}"
360+
"--platform" "managed"
361+
"--no-allow-unauthenticated"
362+
"--set-env-vars" "ENVIRONMENT=production"
363+
)
364+
365+
# Handle secrets: replace entire secrets configuration
366+
# The service has api-keys and llm-encryption-key configured but they don't exist
367+
# Use --update-secrets to replace all secrets with only the valid ones
368+
if [ -n "${SECRETS_LIST}" ]; then
369+
# Update secrets - this replaces all existing secrets with only the valid ones
370+
DEPLOY_ARGS+=("--update-secrets" "${SECRETS_LIST}")
371+
echo "Updating secrets configuration with valid secrets: ${SECRETS_LIST}"
372+
elif [ "${SERVICE_HAS_INVALID_SECRETS}" = "true" ]; then
373+
# No valid secrets exist, but service has invalid ones - clear all secrets
374+
DEPLOY_ARGS+=("--clear-secrets")
375+
echo "Clearing all secrets (none exist in Secret Manager)"
376+
fi
377+
378+
# Add remaining deployment options
379+
DEPLOY_ARGS+=(
380+
"--memory" "1Gi"
381+
"--cpu" "2"
382+
"--timeout" "300"
383+
"--max-instances" "100"
384+
"--min-instances" "1"
385+
)
386+
387+
echo "Deploying with command: gcloud run deploy ${DEPLOY_ARGS[*]}"
388+
gcloud run deploy "${DEPLOY_ARGS[@]}"
318389
319390
- name: Run smoke tests
320391
run: |

0 commit comments

Comments
 (0)