-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
72 lines (63 loc) · 2.3 KB
/
deploy.sh
File metadata and controls
72 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
# Despliegue a Cloud Run en un solo paso (bash).
#
# Requisitos previos:
# 1. gcloud auth login && gcloud auth application-default login
# 2. gcloud config set project <PROJECT_ID>
# 3. Guarda tu clave de Anthropic en Secret Manager:
# gcloud secrets create ANTHROPIC_API_KEY --replication-policy=automatic
# printf 'sk-ant-...' | gcloud secrets versions add ANTHROPIC_API_KEY --data-file=-
#
# Uso:
# PROJECT_ID=mi-proyecto ./deploy.sh
# PROJECT_ID=mi-proyecto REGION=europe-west1 SERVICE=spec-agent ./deploy.sh
set -euo pipefail
: "${PROJECT_ID:?PROJECT_ID es obligatorio}"
REGION="${REGION:-us-central1}"
REPO="${REPO:-spec-agent}"
SERVICE="${SERVICE:-spec-agent}"
SECRET_NAME="${SECRET_NAME:-ANTHROPIC_API_KEY}"
IMAGE="${REGION}-docker.pkg.dev/${PROJECT_ID}/${REPO}/${SERVICE}:latest"
echo "Proyecto : ${PROJECT_ID}"
echo "Region : ${REGION}"
echo "Servicio : ${SERVICE}"
echo "Imagen : ${IMAGE}"
echo
echo "==> Habilitando APIs necesarias"
gcloud services enable \
run.googleapis.com \
artifactregistry.googleapis.com \
cloudbuild.googleapis.com \
secretmanager.googleapis.com \
--project "${PROJECT_ID}"
echo "==> Asegurando que existe el repositorio de Artifact Registry"
if ! gcloud artifacts repositories describe "${REPO}" \
--location="${REGION}" --project="${PROJECT_ID}" >/dev/null 2>&1; then
gcloud artifacts repositories create "${REPO}" \
--repository-format=docker \
--location="${REGION}" \
--description="Imagenes del agente dirigido por specs" \
--project="${PROJECT_ID}"
fi
echo "==> Compilando imagen con Cloud Build"
gcloud builds submit --tag "${IMAGE}" --project "${PROJECT_ID}"
echo "==> Desplegando a Cloud Run"
gcloud run deploy "${SERVICE}" \
--image="${IMAGE}" \
--region="${REGION}" \
--platform=managed \
--allow-unauthenticated \
--port=8080 \
--memory=1Gi \
--cpu=1 \
--timeout=600s \
--concurrency=8 \
--max-instances=5 \
--set-env-vars="OUTPUT_DIR=/tmp/output,STREAMLIT_SERVER_HEADLESS=true" \
--set-secrets="ANTHROPIC_API_KEY=${SECRET_NAME}:latest" \
--project="${PROJECT_ID}"
echo
echo "==> Listo. URL del servicio:"
gcloud run services describe "${SERVICE}" \
--region="${REGION}" --project="${PROJECT_ID}" \
--format='value(status.url)'