OSVauco/infrastructure/02-deploy.sh
Chris Christiansen 05030edf61 fix: Set executable bit on shell and python scripts
Per the task in `docs/TODO.md`, this change runs `git update-index --chmod=+x` on all relevant `.sh` and `.py` files in the repository.

This prevents intermittent 'Permission denied' errors when scripts are run in CI/CD environments or after being edited via the GitHub web interface, which can strip file permissions.
2026-05-26 13:23:18 +00:00

64 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# 02-deploy.sh — Build and deploy orchestrator agent to Cloud Run
# Idempotent: updates existing service if present
# Source .env before running: source .env
set -euo pipefail
: "${PROJECT_ID:?Set PROJECT_ID}"
: "${REGION:?Set REGION}"
: "${AGENT_SA:?Set AGENT_SA}"
: "${ARTIFACT_REPO:?Set ARTIFACT_REPO}"
: "${CLOUD_RUN_SERVICE:?Set CLOUD_RUN_SERVICE}"
IMAGE="${REGION}-docker.pkg.dev/${PROJECT_ID}/${ARTIFACT_REPO}/${CLOUD_RUN_SERVICE}:latest"
echo "=== 02: Building and deploying ${CLOUD_RUN_SERVICE} ==="
bash "$(dirname "$0")/00-authcheck.sh"
# 1. Ensure Artifact Registry repo exists
if ! gcloud artifacts repositories describe "${ARTIFACT_REPO}" \
--location="${REGION}" --project="${PROJECT_ID}" >/dev/null 2>&1; then
gcloud artifacts repositories create "${ARTIFACT_REPO}" \
--repository-format=docker \
--location="${REGION}" \
--project="${PROJECT_ID}" --quiet
echo "✓ Artifact Registry repo created: ${ARTIFACT_REPO}"
fi
# 2. Configure Docker auth
gcloud auth configure-docker "${REGION}-docker.pkg.dev" --quiet
# 3. Build image via Cloud Build (no local Docker required)
gcloud builds submit agents/core-logic \
--tag="${IMAGE}" \
--project="${PROJECT_ID}" \
--quiet
echo "✓ Image built: ${IMAGE}"
# 4. Deploy to Cloud Run
gcloud run deploy "${CLOUD_RUN_SERVICE}" \
--image="${IMAGE}" \
--platform=managed \
--region="${REGION}" \
--service-account="${AGENT_SA}" \
--no-allow-unauthenticated \
--min-instances=1 \
--max-instances=10 \
--concurrency=80 \
--timeout=300s \
--memory=1Gi \
--cpu=1 \
--set-env-vars="PROJECT_ID=${PROJECT_ID},REGION=${REGION}" \
--labels="env=prod,team=osvaucoe,agent=orchestrator" \
--quiet
SERVICE_URL=$(gcloud run services describe "${CLOUD_RUN_SERVICE}" \
--region="${REGION}" \
--format="value(status.url)")
echo ""
echo "=== 02: Deploy COMPLETE ==="
echo " Service URL: ${SERVICE_URL}"
echo " REMINDER: Run 03-teardown.sh at end of workday to stop billing."