File size: 5,324 Bytes
e251b13 47f7c7b e251b13 47f7c7b e251b13 47f7c7b e251b13 d9d5490 e251b13 47f7c7b e251b13 47f7c7b e251b13 2d36370 e251b13 2d36370 e251b13 | 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | #!/bin/bash
# Deployment script for World Cup AI Assistant
# Deploys to different HF Spaces based on environment
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}βΉοΈ $1${NC}"
}
print_success() {
echo -e "${GREEN}β
$1${NC}"
}
print_warning() {
echo -e "${YELLOW}β οΈ $1${NC}"
}
print_error() {
echo -e "${RED}β $1${NC}"
}
# Check if we're in the right directory
if [ ! -f "environments.py" ]; then
print_error "Please run this script from the worldcup-ui-app root directory"
exit 1
fi
# Function to show usage
show_usage() {
echo "π World Cup AI Assistant - Environment Deployment Script"
echo ""
echo "Usage: $0 <environment> [branch]"
echo ""
echo "Environments:"
echo " prod - Deploy to production (WC space)"
echo " staging - Deploy to staging (WC-Staging space)"
echo " dev - Deploy to development (WC-Dev space)"
echo ""
echo "Examples:"
echo " $0 prod # Deploy main branch to production"
echo " $0 staging # Deploy staging branch to staging (main on HF)"
echo " $0 dev # Deploy dev branch to development (main on HF)"
echo " $0 prod main # Deploy main branch to production"
echo " $0 staging feature # Deploy feature branch to staging (main on HF)"
echo ""
echo "Available remotes:"
git remote -v | grep hf
}
# Function to deploy to environment
# Note: All HF Spaces build from their main branch, so we always push to main
deploy_to_environment() {
local env=$1
local branch=${2:-$env} # Default branch name matches environment
# Override default branch for prod environment
if [ "$env" = "prod" ] || [ "$env" = "production" ]; then
branch=${2:-"main"} # Default to main branch for production
fi
print_info "π Deploying to $env environment..."
# Determine remote and branch mapping
case $env in
"prod"|"production")
remote="hf"
target_branch="main"
space_name="WC (Production)"
;;
"staging")
remote="hf-staging"
target_branch="main"
space_name="WC-Staging"
;;
"dev"|"development")
remote="hf-dev"
target_branch="main"
space_name="WC-Dev"
;;
*)
print_error "Invalid environment: $env"
print_error "Valid environments: prod, staging, dev"
exit 1
;;
esac
# Check if remote exists
if ! git remote get-url "$remote" >/dev/null 2>&1; then
print_error "Remote '$remote' not found!"
print_error "Available remotes:"
git remote -v | grep hf
exit 1
fi
# Check if we're on the right branch
current_branch=$(git branch --show-current)
if [ "$current_branch" != "$branch" ]; then
print_warning "You're currently on branch '$current_branch', but deploying branch '$branch'"
print_info "Switching to branch '$branch'..."
git checkout "$branch"
fi
# Check if branch exists
if ! git show-ref --verify --quiet refs/heads/"$branch"; then
print_error "Branch '$branch' does not exist!"
print_error "Available branches:"
git branch
exit 1
fi
# Show deployment info
print_info "Deployment Details:"
echo " Environment: $env"
echo " Space: $space_name"
echo " Remote: $remote"
echo " Source Branch: $branch"
echo " Target Branch: $target_branch"
echo ""
# Confirm deployment
read -p "π€ Proceed with deployment? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_warning "Deployment cancelled"
exit 0
fi
# Deploy
print_info "π€ Pushing to $space_name..."
# Try normal push first
if git push "$remote" "$branch:$target_branch"; then
print_success "π Successfully deployed to $space_name!"
print_info "Your app should be building now on Hugging Face"
print_info "Check the space for build status and logs"
else
print_warning "β οΈ Normal push failed. This might be a new space with initial content."
print_info "Attempting force push to overwrite remote content..."
if git push "$remote" "$branch:$target_branch" --force; then
print_success "π Successfully force deployed to $space_name!"
print_info "Your app should be building now on Hugging Face"
print_info "Check the space for build status and logs"
else
print_error "β Force deployment also failed!"
exit 1
fi
fi
}
# Main script logic
if [ $# -eq 0 ]; then
show_usage
exit 0
fi
ENVIRONMENT=$1
BRANCH=$2
# Validate environment
case $ENVIRONMENT in
"prod"|"production"|"staging"|"dev"|"development")
deploy_to_environment "$ENVIRONMENT" "$BRANCH"
;;
"help"|"-h"|"--help")
show_usage
;;
*)
print_error "Invalid environment: $ENVIRONMENT"
show_usage
exit 1
;;
esac
|