Spaces:
Running
Running
File size: 1,849 Bytes
a63cedf ffa411f a63cedf ffa411f a63cedf ffa411f a63cedf ffa411f a63cedf ffa411f a63cedf ffa411f a63cedf | 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 | #!/bin/bash
set -e
# Load .env file if it exists
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
# Check for PROJECT_ID
if [ -z "$PROJECT_ID" ] || [ "$PROJECT_ID" == "your-project-id" ]; then
echo "Error: PROJECT_ID is not set. Please set it in .env or export it."
echo "Example: export PROJECT_ID=my-gcp-project-id"
exit 1
fi
GOOGLE_CLOUD_PROJECT=$PROJECT_ID
SERVICE_NAME="${SERVICE_NAME:-medgemma-app}"
REGION="${REGION:-europe-west1}"
REPOSITORY="${REPOSITORY:-dermatolog-scan}"
# Hardware Configuration
MEMORY="${MEMORY:-8Gi}"
CPU="${CPU:-4}"
echo "========================================================"
echo " Deploying $SERVICE_NAME to Cloud Run ($REGION)"
echo " Mode: Self-Contained (Local Inference)"
echo "========================================================"
# Image path in Artifact Registry
IMAGE_PATH="$REGION-docker.pkg.dev/$GOOGLE_CLOUD_PROJECT/$REPOSITORY/$SERVICE_NAME"
# 1. Build and Submit Container (Using Cloud Build)
echo "[1/3] Building container image..."
gcloud builds submit --config cloudbuild.yaml \
--substitutions=_HF_TOKEN="$HF_TOKEN",_SERVICE_NAME="$SERVICE_NAME",_REPOSITORY="$REPOSITORY",_REGION="$REGION" .
# 2. Deploy to Cloud Run
echo "[2/3] Deploying to Cloud Run..."
gcloud run deploy $SERVICE_NAME \
--image $IMAGE_PATH \
--region $REGION \
--platform managed \
--allow-unauthenticated \
--memory $MEMORY \
--cpu $CPU \
--cpu-boost \
--max-instances 1 \
--timeout 300 \
--concurrency 10 \
--port 8080 \
--set-env-vars="HF_TOKEN=$HF_TOKEN"
# Note: If HF_TOKEN is not set in your local shell, this will be empty.
# The app handles missing token by falling back to public model.
echo "========================================================"
echo " Deployment Complete!"
echo "========================================================"
|