-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathdeploy.js
More file actions
212 lines (177 loc) · 6.71 KB
/
deploy.js
File metadata and controls
212 lines (177 loc) · 6.71 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#!/usr/bin/env node
/**
* AgentOS Copilot Extension - Deployment Script
*
* Usage:
* node deploy.js vercel - Deploy to Vercel
* node deploy.js azure - Deploy to Azure
* node deploy.js docker - Build Docker image
* node deploy.js check - Check deployment readiness
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const colors = {
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
reset: '\x1b[0m'
};
function log(color, message) {
console.log(`${colors[color]}${message}${colors.reset}`);
}
function exec(cmd, options = {}) {
try {
return execSync(cmd, { stdio: 'inherit', ...options });
} catch (error) {
if (!options.ignoreError) {
throw error;
}
}
}
function checkFile(filePath, description) {
const exists = fs.existsSync(filePath);
if (exists) {
log('green', `✅ ${description}`);
} else {
log('red', `❌ ${description} - Missing: ${filePath}`);
}
return exists;
}
function checkEnv(varName, required = true) {
const exists = !!process.env[varName];
if (exists) {
log('green', `✅ ${varName} is set`);
} else if (required) {
log('red', `❌ ${varName} is not set (required)`);
} else {
log('yellow', `⚠️ ${varName} is not set (optional)`);
}
return exists;
}
async function checkDeploymentReadiness() {
log('blue', '\n🔍 Checking deployment readiness...\n');
let ready = true;
// Check required files
log('blue', '📁 Required Files:');
ready &= checkFile('dist/index.js', 'Built JavaScript');
ready &= checkFile('package.json', 'Package manifest');
ready &= checkFile('.env.example', 'Environment template');
// Check optional files
log('blue', '\n📁 Deployment Configs:');
checkFile('vercel.json', 'Vercel config');
checkFile('Dockerfile', 'Docker config');
checkFile('github-app-manifest.json', 'GitHub App manifest');
// Check assets
log('blue', '\n🎨 Visual Assets:');
checkFile('assets/logo.svg', 'Logo (SVG)');
checkFile('assets/feature-card.svg', 'Feature card (SVG)');
// Check environment
log('blue', '\n🔐 Environment Variables:');
// Load .env if exists
if (fs.existsSync('.env')) {
require('dotenv').config();
}
const hasGitHubAppId = checkEnv('GITHUB_APP_ID');
const hasGitHubClientId = checkEnv('GITHUB_CLIENT_ID');
const hasGitHubClientSecret = checkEnv('GITHUB_CLIENT_SECRET');
const hasWebhookSecret = checkEnv('GITHUB_WEBHOOK_SECRET');
checkEnv('GITHUB_PRIVATE_KEY', false);
checkEnv('SERVER_URL', false);
if (!hasGitHubAppId || !hasGitHubClientId) {
log('yellow', '\n⚠️ GitHub App not configured. Create one at:');
log('yellow', ' https://github.com/settings/apps/new');
}
// Summary
log('blue', '\n📊 Summary:');
if (ready) {
log('green', '✅ Basic deployment requirements met');
} else {
log('red', '❌ Missing required files - run `npm run build` first');
}
return ready;
}
async function deployVercel() {
log('blue', '\n🚀 Deploying to Vercel...\n');
// Check if vercel CLI is installed
try {
execSync('vercel --version', { stdio: 'pipe' });
} catch {
log('yellow', 'Installing Vercel CLI...');
exec('npm install -g vercel');
}
// Deploy
log('blue', 'Deploying (this will prompt for login if needed)...\n');
exec('vercel --prod');
log('green', '\n✅ Deployment complete!');
log('blue', '\nNext steps:');
log('blue', '1. Note your deployment URL');
log('blue', '2. Update your GitHub App settings with the URL');
log('blue', '3. Set environment variables in Vercel dashboard');
}
async function deployAzure() {
log('blue', '\n🚀 Deploying to Azure...\n');
// Check if Azure CLI is installed
try {
execSync('az --version', { stdio: 'pipe' });
} catch {
log('red', '❌ Azure CLI not installed');
log('blue', 'Install from: https://docs.microsoft.com/cli/azure/install-azure-cli');
process.exit(1);
}
const appName = process.env.AZURE_APP_NAME || 'agentos-copilot';
log('blue', `Deploying to Azure App Service: ${appName}\n`);
exec(`az webapp up --name ${appName} --runtime "NODE:20-lts" --sku B1`);
log('green', '\n✅ Deployment complete!');
log('blue', `\nYour app URL: https://${appName}.azurewebsites.net`);
}
async function buildDocker() {
log('blue', '\n🐳 Building Docker image...\n');
const imageName = 'agentos-copilot';
const tag = process.env.DOCKER_TAG || 'latest';
exec(`docker build -t ${imageName}:${tag} .`);
log('green', '\n✅ Docker image built!');
log('blue', `\nImage: ${imageName}:${tag}`);
log('blue', '\nTo run locally:');
log('blue', ` docker run -p 3000:3000 --env-file .env ${imageName}:${tag}`);
log('blue', '\nTo push to registry:');
log('blue', ` docker tag ${imageName}:${tag} your-registry/${imageName}:${tag}`);
log('blue', ` docker push your-registry/${imageName}:${tag}`);
}
async function main() {
const command = process.argv[2] || 'check';
log('blue', '═══════════════════════════════════════════════');
log('blue', ' AgentOS Copilot Extension - Deployment Tool');
log('blue', '═══════════════════════════════════════════════');
switch (command) {
case 'check':
await checkDeploymentReadiness();
break;
case 'vercel':
await checkDeploymentReadiness();
await deployVercel();
break;
case 'azure':
await checkDeploymentReadiness();
await deployAzure();
break;
case 'docker':
await checkDeploymentReadiness();
await buildDocker();
break;
default:
log('yellow', `Unknown command: ${command}`);
log('blue', '\nUsage:');
log('blue', ' node deploy.js check - Check deployment readiness');
log('blue', ' node deploy.js vercel - Deploy to Vercel');
log('blue', ' node deploy.js azure - Deploy to Azure');
log('blue', ' node deploy.js docker - Build Docker image');
}
}
main().catch(error => {
log('red', `\n❌ Error: ${error.message}`);
process.exit(1);
});