#!/bin/bash # Deploy SAM3 to both HuggingFace and Azure AI Foundry set -e # Colors for output GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ SAM3 Dual Deployment Script ║${NC}" echo -e "${BLUE}║ HuggingFace + Azure AI Foundry ║${NC}" echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" echo "" # Configuration HF_REGISTRY="sam3acr4hf.azurecr.io" HF_IMAGE="sam3-hf:latest" AZURE_REGISTRY="sam3acr.azurecr.io" AZURE_IMAGE="sam3-foundry:latest" # Parse arguments DEPLOY_HF=false DEPLOY_AZURE=false while [[ $# -gt 0 ]]; do case $1 in --hf) DEPLOY_HF=true shift ;; --azure) DEPLOY_AZURE=true shift ;; --all) DEPLOY_HF=true DEPLOY_AZURE=true shift ;; --help) echo "Usage: ./deploy_all.sh [options]" echo "" echo "Options:" echo " --hf Deploy to HuggingFace only" echo " --azure Deploy to Azure AI Foundry only" echo " --all Deploy to both platforms" echo " --help Show this help message" echo "" echo "Examples:" echo " ./deploy_all.sh --hf # Deploy to HuggingFace" echo " ./deploy_all.sh --azure # Deploy to Azure AI Foundry" echo " ./deploy_all.sh --all # Deploy to both" exit 0 ;; *) echo "Unknown option: $1" echo "Use --help for usage information" exit 1 ;; esac done # Default to HuggingFace if no option specified if [ "$DEPLOY_HF" = false ] && [ "$DEPLOY_AZURE" = false ]; then echo -e "${YELLOW}No deployment target specified. Defaulting to HuggingFace.${NC}" echo -e "${YELLOW}Use --all to deploy to both platforms.${NC}" echo "" DEPLOY_HF=true fi # Step 1: Build Docker image echo -e "${BLUE}[1/4] Building Docker image...${NC}" docker build -t sam3:latest -f docker/Dockerfile . echo -e "${GREEN}✓ Build complete${NC}" echo "" # Step 2: Deploy to HuggingFace if [ "$DEPLOY_HF" = true ]; then echo -e "${BLUE}[2/4] Deploying to HuggingFace...${NC}" # Tag for HuggingFace docker tag sam3:latest ${HF_REGISTRY}/${HF_IMAGE} echo " Tagged: ${HF_REGISTRY}/${HF_IMAGE}" # Login to HF ACR echo " Logging in to HuggingFace ACR..." az acr login --name sam3acr4hf # Push to HF ACR echo " Pushing to HuggingFace ACR..." docker push ${HF_REGISTRY}/${HF_IMAGE} echo -e "${GREEN}✓ HuggingFace deployment complete${NC}" echo "" else echo -e "${YELLOW}[2/4] Skipping HuggingFace deployment${NC}" echo "" fi # Step 3: Deploy to Azure AI Foundry if [ "$DEPLOY_AZURE" = true ]; then echo -e "${BLUE}[3/4] Deploying to Azure AI Foundry...${NC}" # Tag for Azure docker tag sam3:latest ${AZURE_REGISTRY}/${AZURE_IMAGE} echo " Tagged: ${AZURE_REGISTRY}/${AZURE_IMAGE}" # Login to Azure ACR echo " Logging in to Azure ACR..." az acr login --name sam3acr # Push to Azure ACR echo " Pushing to Azure ACR..." docker push ${AZURE_REGISTRY}/${AZURE_IMAGE} echo -e "${GREEN}✓ Azure AI Foundry image pushed${NC}" echo -e "${YELLOW} ⚠ Note: Azure AI Foundry endpoint deployment pending GPU quota${NC}" echo -e "${YELLOW} ⚠ See DEPLOYMENT.md for endpoint deployment instructions${NC}" echo "" else echo -e "${YELLOW}[3/4] Skipping Azure AI Foundry deployment${NC}" echo "" fi # Step 4: Summary echo -e "${BLUE}[4/4] Deployment Summary${NC}" echo "════════════════════════════════════════════════════════════" if [ "$DEPLOY_HF" = true ]; then echo -e "${GREEN}✅ HuggingFace:${NC}" echo " Registry: ${HF_REGISTRY}" echo " Image: ${HF_IMAGE}" echo " Endpoint: https://p6irm2x7y9mwp4l4.us-east-1.aws.endpoints.huggingface.cloud" echo "" echo " Restart endpoint with:" echo " python3 -c 'from huggingface_hub import HfApi; api = HfApi(); e = api.get_inference_endpoint(\"sam3-segmentation\", namespace=\"Logiroad\"); e.pause(); e.resume()'" echo "" fi if [ "$DEPLOY_AZURE" = true ]; then echo -e "${YELLOW}⏳ Azure AI Foundry:${NC}" echo " Registry: ${AZURE_REGISTRY}" echo " Image: ${AZURE_IMAGE}" echo " Status: Image ready, endpoint deployment pending GPU quota" echo "" echo " Once GPU quota is approved, deploy with:" echo " az ml online-endpoint create --name sam3-foundry ..." echo " See DEPLOYMENT.md for complete instructions" echo "" fi echo "════════════════════════════════════════════════════════════" echo -e "${GREEN}✓ Deployment complete!${NC}" echo "" echo "Test the deployment:" echo " python3 scripts/test/test_api.py" echo "" echo "For more information:" echo " cat README.md # HuggingFace usage" echo " cat docs/DEPLOYMENT.md # Dual deployment guide"