This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 2.6 kB View raw
1#!/usr/bin/env bash 2# Build image (Cloud Build), push to Artifact Registry, deploy Cloud Run Service. 3# 4# Usage (from repo root): 5# ./recommendation/deploy.sh 6# 7# Optional overrides: 8# PROJECT_ID=cleveland-464404-m0 REGION=europe-west1 ./recommendation/deploy.sh 9# 10# Requires: gcloud auth, .env with DB_CONNECTION_STRING (repo root or recommendation/.env). 11 12set -euo pipefail 13 14ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 15SERVICE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 16ENV_FILE="${ENV_FILE:-}" 17if [[ -z "$ENV_FILE" ]]; then 18 if [[ -f "$ROOT/.env" ]]; then 19 ENV_FILE="$ROOT/.env" 20 elif [[ -f "$SERVICE_DIR/.env" ]]; then 21 ENV_FILE="$SERVICE_DIR/.env" 22 fi 23fi 24 25REGION="${REGION:-europe-west1}" 26REPOSITORY="${REPOSITORY:-tangled}" 27IMAGE_NAME="${IMAGE_NAME:-recommendation-api}" 28SERVICE_NAME="${SERVICE_NAME:-tangled-recommendation}" 29MEMORY="${MEMORY:-512Mi}" 30CPU="${CPU:-1}" 31MIN_INSTANCES="${MIN_INSTANCES:-0}" 32MAX_INSTANCES="${MAX_INSTANCES:-3}" 33ALLOW_UNAUTHENTICATED="${ALLOW_UNAUTHENTICATED:-1}" 34 35PROJECT_ID="${PROJECT_ID:-$(gcloud config get-value project 2>/dev/null)}" 36if [[ -z "$PROJECT_ID" || "$PROJECT_ID" == "(unset)" ]]; then 37 echo "ERROR: Set PROJECT_ID or run: gcloud config set project YOUR_PROJECT_ID" >&2 38 exit 1 39fi 40 41if [[ -z "$ENV_FILE" || ! -f "$ENV_FILE" ]]; then 42 echo "ERROR: Env file not found. Set ENV_FILE or create $ROOT/.env" >&2 43 exit 1 44fi 45 46IMAGE="${REGION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE_NAME}:latest" 47 48echo "==> Project: $PROJECT_ID" 49echo "==> Region: $REGION" 50echo "==> Image: $IMAGE" 51echo "==> Service: $SERVICE_NAME" 52echo "==> Env file: $ENV_FILE" 53echo 54 55echo "==> Build & push (Cloud Build)" 56gcloud builds submit \ 57 --project="$PROJECT_ID" \ 58 --config="$SERVICE_DIR/cloudbuild.yaml" \ 59 "$SERVICE_DIR" 60 61echo 62echo "==> Deploy Cloud Run Service" 63DEPLOY_ARGS=( 64 run deploy "$SERVICE_NAME" 65 --project="$PROJECT_ID" 66 --region="$REGION" 67 --image="$IMAGE" 68 --env-vars-file="$ENV_FILE" 69 --port=8000 70 --memory="$MEMORY" 71 --cpu="$CPU" 72 --min-instances="$MIN_INSTANCES" 73 --max-instances="$MAX_INSTANCES" 74 --timeout=60 75) 76 77if [[ "$ALLOW_UNAUTHENTICATED" == "1" ]]; then 78 DEPLOY_ARGS+=(--allow-unauthenticated) 79else 80 DEPLOY_ARGS+=(--no-allow-unauthenticated) 81fi 82 83gcloud "${DEPLOY_ARGS[@]}" 84 85echo 86echo "==> Service URL" 87gcloud run services describe "$SERVICE_NAME" \ 88 --project="$PROJECT_ID" \ 89 --region="$REGION" \ 90 --format='value(status.url)' 91 92echo 93echo "Smoke test:" 94URL="$(gcloud run services describe "$SERVICE_NAME" --project="$PROJECT_ID" --region="$REGION" --format='value(status.url)')" 95echo " curl \"${URL}/health\""