cfmanager / quickstart.py
HFHash789's picture
Upload folder using huggingface_hub
32e4bbf verified
#!/usr/bin/env python3
"""
Quick Start Script for Cloudflare Manager
This script provides the fastest way to:
1. Deploy a Pages project
2. Bind a domain
3. Get nameservers
"""
import sys
from cloudflare_manager import CloudflareManager, CloudflareAccount
def quickstart():
"""Quick start deployment"""
print("""
╔══════════════════════════════════════════════════════════╗
β•‘ Cloudflare Manager - Quick Start β•‘
β•‘ Deploy Pages + Bind Domain + Get Nameservers β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
""")
# Configuration
print("\nπŸ“ Configuration")
print("="*60)
email = input("Cloudflare Email: ").strip()
token = input("Cloudflare API Token: ").strip()
if not email or not token:
print("βœ— Email and Token are required!")
return
print("\nπŸ“ Project Information")
print("="*60)
project_name = input("Pages Project Name: ").strip()
directory = input("Directory to deploy (default: .): ").strip() or "."
domain = input("Domain to bind (optional): ").strip()
if not project_name:
print("βœ— Project name is required!")
return
# Initialize
print("\nπŸ”§ Initializing Cloudflare Manager...")
account = CloudflareAccount(email=email, token=token)
cf = CloudflareManager(account)
# Step 1: Create project
print(f"\nπŸ“ Step 1/4: Creating Pages project '{project_name}'...")
project = cf.create_pages_project(project_name, "main")
if not project:
print("βœ— Failed to create project")
return
print(f"βœ“ Project created: https://{project.get('subdomain')}")
# Step 2: Deploy
print(f"\nπŸ“¦ Step 2/4: Deploying from '{directory}'...")
deployment = cf.deploy_pages_project(
project_name=project_name,
directory=directory,
branch="main",
commit_message="Quickstart deployment"
)
if not deployment:
print("βœ— Failed to deploy")
return
print(f"βœ“ Deployed: {deployment.get('url')}")
# Step 3: Domain (if provided)
zone_id = None
if domain:
print(f"\n🌐 Step 3/4: Setting up domain '{domain}'...")
# Create zone
zone = cf.create_zone(domain)
if zone:
zone_id = zone.get("id")
nameservers = zone.get("name_servers", [])
print(f"\nπŸ“‹ Nameservers (add these to your domain registrar):")
print("="*60)
for ns in nameservers:
print(f" {ns}")
print("="*60)
# Bind to Pages
result = cf.add_pages_domain(project_name, domain)
if result:
print(f"βœ“ Domain bound to Pages project")
if result.get('validation_data'):
val = result['validation_data']
print(f"\nπŸ“‹ DNS Validation Record:")
print(f" Type: {val.get('type')}")
print(f" Name: {val.get('name')}")
print(f" Value: {val.get('value')}")
else:
print("\n⏭️ Step 3/4: Skipping domain setup (no domain provided)")
# Step 4: Summary
print(f"\nβœ… Step 4/4: Summary")
print("="*60)
print(f"βœ“ Project: {project_name}")
print(f"βœ“ URL: {deployment.get('url')}")
if domain:
print(f"βœ“ Domain: {domain}")
print(f"\nπŸ“ Next steps:")
print(f" 1. Update nameservers at your domain registrar")
print(f" 2. Wait for DNS propagation (5-30 minutes)")
print(f" 3. Visit https://{domain}")
else:
print(f"\nπŸ“ Next steps:")
print(f" 1. Visit {deployment.get('url')}")
print(f" 2. (Optional) Add a custom domain later")
print("="*60)
print("\nπŸŽ‰ Quickstart completed successfully!")
if __name__ == "__main__":
try:
quickstart()
except KeyboardInterrupt:
print("\n\n⚠️ Interrupted by user")
sys.exit(0)
except Exception as e:
print(f"\nβœ— Error: {e}")
sys.exit(1)