Download scripts/deploy_to_env.sh from dxdoan/WC: direct link, hf CLI and curl.
- Browser
- Download file 5.32 kB
-
https://huggingface.co/spaces/dxdoan/WC/resolve/main/scripts/deploy_to_env.sh
- Command line
-
hf download hf://spaces/dxdoan/WC/scripts/deploy_to_env.sh
-
curl -L -o deploy_to_env.sh https://huggingface.co/spaces/dxdoan/WC/resolve/main/scripts/deploy_to_env.sh
5.32 kB
| # 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 | |