File size: 3,617 Bytes
81e8bb6 | 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 | #!/bin/bash
# ATOM Web-Dev Cloud Preview Deployment Script
# Automatically deploys to free cloud providers from GitHub
set -e
echo "🚀 ATOM Cloud Preview Deployment Starting..."
# Configuration
REPO_URL=${GITHUB_REPO:-$(git config --get remote.origin.url)}
BRANCH=${GITHUB_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Functions
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
exit 1
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if we're in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
error "Not in a git repository. Please initialize git first."
fi
# Install Netlify CLI if not present
if ! command -v netlify &> /dev/null; then
log "Installing Netlify CLI..."
npm install -g netlify-cli
fi
# Install Vercel CLI if not present
if ! command -v vercel &> /dev/null; then
log "Installing Vercel CLI..."
npm install -g vercel
fi
# Build the application
log "Building ATOM web application..."
cd frontend-nextjs/app_build_docker
npm ci --silent
npm run build
log "Build completed successfully"
# Cloud deployment functions
deploy_netlify() {
log "Deploying to Netlify..."
# Check if netlify.toml exists
if [ ! -f "netlify.toml" ]; then
log "Creating netlify.toml..."
cat > netlify.toml << EOF
[build]
command = "npm run build"
publish = ".next"
[build.environment]
NODE_VERSION = "18"
[[plugins]]
package = "@netlify/plugin-nextjs"
[context.deploy-preview]
command = "npm run build"
EOF
fi
# Deploy
netlify deploy --prod --dir=.next --build
}
deploy_vercel() {
log "Deploying to Vercel..."
# Create vercel.json if it doesn't exist
if [ ! -f "vercel.json" ]; then
cat > vercel.json << EOF
{
"version": 2,
"builds": [{ "src": "package.json", "use": "@vercel/next" }],
"github": {
"autoAlias": true
}
}
EOF
fi
# Check if VERCEL_TOKEN is set
if [ -z "$VERCEL_TOKEN" ]; then
log "Please set VERCEL_TOKEN environment variable for auto-deployment"
vercel --prod
else
vercel --token $VERCEL_TOKEN --prod --yes
fi
}
deploy_fly() {
log "Deploying to fly.io..."
# Check if fly.toml exists
if [ ! -f "fly.toml" ]; then
log "Creating fly.toml configuration..."
cat > fly.toml << EOF
app = "atom-web-dev"
primary_region = "iad"
[build]
[build.args]
NEXT_PUBLIC_ANALYTICS_ID = "your-analytics-id"
[[services]]
http_checks = []
internal_port = 3000
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
EOF
fi
fly deploy --remote-only
}
# Main deployment logic
case "${CLOUD_PROVIDER:-auto}" in
netlify)
deploy_netlify
;;
vercel)
deploy_vercel
;;
fly)
deploy_fly
;;
auto)
log "Auto-detecting best cloud provider..."
# Check for existing configurations
if [ -f "../../../config/deployment/netlify.toml" ]; then
log "Found netlify.toml, deploying to Netlify..."
deploy_netlify
elif [ -f "../../../
|