@ostro-cloud/cli 0.0.0-stage → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -2
- package/bin/ostro.js +233 -0
- package/lib/client.js +186 -0
- package/lib/commands/configure.js +35 -0
- package/lib/commands/deploy.js +61 -0
- package/lib/commands/formation.js +666 -0
- package/lib/commands/k8s.js +44 -0
- package/lib/commands/login.js +154 -0
- package/lib/commands/s3.js +88 -0
- package/lib/commands/serverless.js +104 -0
- package/lib/commands/status.js +41 -0
- package/lib/commands/tunnel.js +129 -0
- package/package.json +38 -5
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ostro/cli — Ostro Cloud Global Deployment CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official Command Line Interface (CLI) for **Ostro Cloud** to orchestrate Serverless functions, S3 Object Storage, Kubernetes workloads, and CloudFormation IaC stacks from local developer machines and automated CI/CD pipelines (GitLab CI, GitHub Actions).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
|
|
9
|
+
Install globally via npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @ostro/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Verify installation:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
ostro --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ⚡ Quick Start
|
|
24
|
+
|
|
25
|
+
### 1. Configure Credentials & Region
|
|
26
|
+
```bash
|
|
27
|
+
ostro configure --endpoint http://localhost:8080 --region in-bihar-1 --env production
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Check Cloud Cluster Health
|
|
31
|
+
```bash
|
|
32
|
+
ostro status
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Smart Universal Deploy
|
|
36
|
+
Automatically deploys `template.yaml` (CloudFormation), `serverless.yaml`, `k8s.yaml`, or static build directories (`dist`/`build`):
|
|
37
|
+
```bash
|
|
38
|
+
ostro deploy --env production
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🛠️ Service Commands
|
|
44
|
+
|
|
45
|
+
### Ostro Serverless (FaaS)
|
|
46
|
+
```bash
|
|
47
|
+
# List functions in active environment
|
|
48
|
+
ostro serverless list --env production
|
|
49
|
+
|
|
50
|
+
# Deploy a function from local source
|
|
51
|
+
ostro serverless deploy calculateTaxes --file index.js --runtime nodejs20.x --env production
|
|
52
|
+
|
|
53
|
+
# Invoke a function with JSON payload
|
|
54
|
+
ostro serverless invoke calculateTaxes --data '{"amount": 1000, "taxRate": 0.18}'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Ostro Bucket (S3 Object Storage)
|
|
58
|
+
```bash
|
|
59
|
+
# List all buckets
|
|
60
|
+
ostro s3 ls
|
|
61
|
+
|
|
62
|
+
# Sync local build directory to S3 bucket (Static Website Hosting)
|
|
63
|
+
ostro s3 sync ./dist s3://my-webapp-bucket --env production
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Ostro Formation (CloudFormation IaC)
|
|
67
|
+
```bash
|
|
68
|
+
# Deploy a CloudFormation / SAM YAML template
|
|
69
|
+
ostro formation deploy --stack-name ecommerce-prod --template template.yaml --env production
|
|
70
|
+
|
|
71
|
+
# List stacks and status
|
|
72
|
+
ostro formation list
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Kubernetes Engine
|
|
76
|
+
```bash
|
|
77
|
+
# Apply a Kubernetes manifest
|
|
78
|
+
ostro k8s apply -f deployment.yaml --env production
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## 🦊 GitLab CI/CD Integration
|
|
84
|
+
|
|
85
|
+
Add `.gitlab-ci.yml` to the root of your repository:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
image: node:20-alpine
|
|
89
|
+
|
|
90
|
+
stages:
|
|
91
|
+
- deploy
|
|
92
|
+
|
|
93
|
+
deploy:production:
|
|
94
|
+
stage: deploy
|
|
95
|
+
script:
|
|
96
|
+
- npm install -g @ostro/cli
|
|
97
|
+
- ostro configure --endpoint $OSTRO_ENDPOINT --token $OSTRO_API_KEY
|
|
98
|
+
- ostro deploy --env production
|
|
99
|
+
only:
|
|
100
|
+
- main
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 🇮🇳 Region Support
|
|
106
|
+
* **`in-bihar-1 (Bihar, India)`** (Primary Cloud Datacenter)
|
package/bin/ostro.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const http = require('http');
|
|
5
|
+
|
|
6
|
+
const { validateTemplate, createStack, deployStack, listStacks, deleteStack, describeStack, packageStack, buildAndDeployService } = require('../lib/commands/formation');
|
|
7
|
+
const { universalDeploy } = require('../lib/commands/deploy');
|
|
8
|
+
const { listFunctions, deployFunction, invokeFunction } = require('../lib/commands/serverless');
|
|
9
|
+
const { listBuckets, syncDirectory } = require('../lib/commands/s3');
|
|
10
|
+
const { applyManifest } = require('../lib/commands/k8s');
|
|
11
|
+
const { listTunnels, createTunnel, deleteTunnel } = require('../lib/commands/tunnel');
|
|
12
|
+
const { configureCli } = require('../lib/commands/configure');
|
|
13
|
+
const { login } = require('../lib/commands/login');
|
|
14
|
+
const { checkStatus } = require('../lib/commands/status');
|
|
15
|
+
|
|
16
|
+
program
|
|
17
|
+
.name('ostro')
|
|
18
|
+
.description('Ostro Cloud — Unified Developer & Infrastructure CLI (CloudFormation, K8s, Serverless, DNS, APIGateway)')
|
|
19
|
+
.version('2.0.0');
|
|
20
|
+
|
|
21
|
+
// Universal Deploy
|
|
22
|
+
program
|
|
23
|
+
.command('deploy')
|
|
24
|
+
.description('Universal deployment orchestrator for Ostro Cloud (supports template.yaml, serverless.yaml, k8s.yaml)')
|
|
25
|
+
.option('-s, --stack <stackName>', 'Stack name')
|
|
26
|
+
.option('-t, --template <path>', 'Template YAML/JSON path')
|
|
27
|
+
.option('-r, --region <region>', 'Deployment region')
|
|
28
|
+
.action(universalDeploy);
|
|
29
|
+
|
|
30
|
+
// CloudFormation / Ostro Formation
|
|
31
|
+
const cloudformation = program.command('cloudformation').alias('formation').alias('cfn').description('Ostro Formation (CloudFormation) orchestration engine');
|
|
32
|
+
|
|
33
|
+
cloudformation
|
|
34
|
+
.command('validate')
|
|
35
|
+
.alias('validate-template')
|
|
36
|
+
.description('Validate an Ostro Formation template syntax, schema, and dependencies')
|
|
37
|
+
.option('-t, --template <path>', 'Path to CloudFormation template YAML/JSON (default: template.yaml)')
|
|
38
|
+
.option('-p, --parameters <params...>', 'Parameter key=value pairs')
|
|
39
|
+
.option('-r, --region <region>', 'Deployment region')
|
|
40
|
+
.action(validateTemplate);
|
|
41
|
+
|
|
42
|
+
cloudformation
|
|
43
|
+
.command('create')
|
|
44
|
+
.alias('create-stack')
|
|
45
|
+
.description('Create a new Ostro Formation stack (fails if stack already exists)')
|
|
46
|
+
.requiredOption('-s, --stack-name <stackName>', 'Name of the CloudFormation stack')
|
|
47
|
+
.requiredOption('-t, --template <path>', 'Path to CloudFormation template YAML/JSON')
|
|
48
|
+
.option('-p, --parameters <params...>', 'Parameter key=value pairs')
|
|
49
|
+
.option('--disable-rollback', 'Disable rollback on failure')
|
|
50
|
+
.option('--termination-protection', 'Enable termination protection for the stack')
|
|
51
|
+
.option('--role-arn <roleArn>', 'Execution IAM role ARN for Formation')
|
|
52
|
+
.option('-r, --region <region>', 'Deployment region')
|
|
53
|
+
.option('--skip-build', 'Skip Dockerfile build and use the Image parameter from the template as-is')
|
|
54
|
+
.option('-i, --image <image>', 'Override the Image parameter (skips build)')
|
|
55
|
+
.action(createStack);
|
|
56
|
+
|
|
57
|
+
cloudformation
|
|
58
|
+
.command('deploy')
|
|
59
|
+
.description('Deploy a CloudFormation template to Ostro Cloud (idempotent create or update)')
|
|
60
|
+
.requiredOption('-t, --template <path>', 'Path to CloudFormation template YAML/JSON')
|
|
61
|
+
.requiredOption('-s, --stack-name <stackName>', 'Name of the CloudFormation stack')
|
|
62
|
+
.option('-p, --parameters <params...>', 'Parameter key=value pairs')
|
|
63
|
+
.option('-r, --region <region>', 'Deployment region')
|
|
64
|
+
.option('--no-build', 'Skip remote Docker image build')
|
|
65
|
+
.option('-i, --image <image>', 'Override the Image parameter (skips build)')
|
|
66
|
+
.option('--formation-url <url>', 'Override Ostro Formation API URL')
|
|
67
|
+
.action(deployStack);
|
|
68
|
+
|
|
69
|
+
cloudformation
|
|
70
|
+
.command('list')
|
|
71
|
+
.description('List deployed CloudFormation stacks')
|
|
72
|
+
.option('-r, --region <region>', 'Region filter')
|
|
73
|
+
.action(listStacks);
|
|
74
|
+
|
|
75
|
+
cloudformation
|
|
76
|
+
.command('describe <stackName>')
|
|
77
|
+
.description('Get details and resources for a CloudFormation stack')
|
|
78
|
+
.action(describeStack);
|
|
79
|
+
|
|
80
|
+
cloudformation
|
|
81
|
+
.command('delete <stackName>')
|
|
82
|
+
.description('Delete a CloudFormation stack and its resources')
|
|
83
|
+
.action(deleteStack);
|
|
84
|
+
|
|
85
|
+
cloudformation
|
|
86
|
+
.command('package')
|
|
87
|
+
.description('Package local artifact paths in a template to S3 (like aws cloudformation package)')
|
|
88
|
+
.requiredOption('-t, --template <path>', 'Path to template YAML/JSON with local Code:/Source: paths')
|
|
89
|
+
.requiredOption('--s3-bucket <bucket>', 'S3 bucket for artifact uploads')
|
|
90
|
+
.option('--s3-prefix <prefix>', 'S3 key prefix for uploads (default: ostro-formation)')
|
|
91
|
+
.option('-o, --output-template <path>', 'Output path for the packaged template (default: <template>-packaged.yaml)')
|
|
92
|
+
.action(packageStack);
|
|
93
|
+
|
|
94
|
+
cloudformation
|
|
95
|
+
.command('build-deploy <serviceDir>')
|
|
96
|
+
.description('Build a service locally (UI first → ostro-build) then rsync .dist/ to SSH server (OPS-08/09)')
|
|
97
|
+
.option('--host <user@host>', 'SSH destination (or set OSTRO_DEPLOY_HOST)')
|
|
98
|
+
.option('--remote-path <path>', 'Remote base path (default: /opt/ostro-cloud)')
|
|
99
|
+
.option('--skip-ui', 'Skip vite UI build step')
|
|
100
|
+
.action(buildAndDeployService);
|
|
101
|
+
|
|
102
|
+
// Kubernetes Engine
|
|
103
|
+
const k8s = program.command('k8s').alias('eks').description('Ostro Kubernetes Engine (EKS) management');
|
|
104
|
+
k8s
|
|
105
|
+
.command('apply <file>')
|
|
106
|
+
.description('Apply a Kubernetes manifest to Ostro cluster')
|
|
107
|
+
.option('-n, --namespace <namespace>', 'Target namespace')
|
|
108
|
+
.action(applyManifest);
|
|
109
|
+
|
|
110
|
+
// Serverless / Lambda
|
|
111
|
+
const serverless = program.command('serverless').alias('lambda').description('Ostro Serverless & FaaS functions');
|
|
112
|
+
serverless
|
|
113
|
+
.command('list')
|
|
114
|
+
.description('List serverless functions')
|
|
115
|
+
.option('-r, --region <region>', 'Region filter')
|
|
116
|
+
.action(listFunctions);
|
|
117
|
+
|
|
118
|
+
serverless
|
|
119
|
+
.command('deploy <name>')
|
|
120
|
+
.description('Deploy a standalone serverless function')
|
|
121
|
+
.requiredOption('-f, --file <file>', 'Handler file path')
|
|
122
|
+
.option('-r, --region <region>', 'Region')
|
|
123
|
+
.option('--runtime <runtime>', 'Runtime (e.g. nodejs20.x, python3.11)')
|
|
124
|
+
.option('--handler <handler>', 'Handler function (e.g. index.handler)')
|
|
125
|
+
.action(deployFunction);
|
|
126
|
+
|
|
127
|
+
serverless
|
|
128
|
+
.command('invoke <name>')
|
|
129
|
+
.description('Invoke a serverless function')
|
|
130
|
+
.option('-d, --data <data>', 'Input payload string / JSON')
|
|
131
|
+
.action(invokeFunction);
|
|
132
|
+
|
|
133
|
+
// S3 Storage
|
|
134
|
+
const s3 = program.command('s3').alias('storage').description('Ostro Bucket S3 Object Storage');
|
|
135
|
+
s3
|
|
136
|
+
.command('list')
|
|
137
|
+
.description('List S3 buckets')
|
|
138
|
+
.option('-r, --region <region>', 'Region filter')
|
|
139
|
+
.action(listBuckets);
|
|
140
|
+
|
|
141
|
+
s3
|
|
142
|
+
.command('sync <dir> <bucketUri>')
|
|
143
|
+
.description('Sync a local directory to an S3 bucket (e.g. ostro s3 sync ./dist s3://my-bucket)')
|
|
144
|
+
.option('-r, --region <region>', 'Region')
|
|
145
|
+
.action(syncDirectory);
|
|
146
|
+
|
|
147
|
+
// Ingress Tunnel & DNS
|
|
148
|
+
const tunnel = program.command('tunnel').description('Ostro Ingress Tunnel & DNS management');
|
|
149
|
+
tunnel
|
|
150
|
+
.command('list')
|
|
151
|
+
.description('List active tunnels')
|
|
152
|
+
.option('-r, --region <region>', 'Filter by region (optional)')
|
|
153
|
+
.action(listTunnels);
|
|
154
|
+
|
|
155
|
+
tunnel
|
|
156
|
+
.command('create <name>')
|
|
157
|
+
.description('Create an ingress tunnel')
|
|
158
|
+
.requiredOption('-h, --hostname <hostname>', 'Public hostname (e.g. app.ostro-cloud.com)')
|
|
159
|
+
.requiredOption('-t, --target <target>', 'Target origin host:port or IP:port')
|
|
160
|
+
.option('-p, --provider <provider>', 'Tunnel provider (CLOUDFLARE, AWS_DIRECT, TAILSCALE)')
|
|
161
|
+
.option('-r, --region <region>', 'Edge region')
|
|
162
|
+
.action(createTunnel);
|
|
163
|
+
|
|
164
|
+
tunnel
|
|
165
|
+
.command('delete <nameOrId>')
|
|
166
|
+
.description('Delete an ingress tunnel by name, id, or hostname')
|
|
167
|
+
.action(deleteTunnel);
|
|
168
|
+
|
|
169
|
+
// Status & Diagnostics
|
|
170
|
+
program
|
|
171
|
+
.command('status')
|
|
172
|
+
.description('Check health and connectivity of all Ostro Cloud microservices')
|
|
173
|
+
.action(checkStatus);
|
|
174
|
+
|
|
175
|
+
program
|
|
176
|
+
.command('configure')
|
|
177
|
+
.description('Configure Ostro CLI cloud domain, region, and credentials')
|
|
178
|
+
.option('--domain <domain>', 'Cloud domain (default: ostro-cloud.com)')
|
|
179
|
+
.option('--region <region>', 'Default region (default: in-bihar-1)')
|
|
180
|
+
.option('--token <token>', 'API Token / Secret')
|
|
181
|
+
.option('--session-token <token>', 'Temporary STS Session Token')
|
|
182
|
+
.option('--role <roleArn>', 'Assumed Execution Role ARN')
|
|
183
|
+
.option('--endpoint <url>', '(deprecated) Use --domain instead')
|
|
184
|
+
.action(configureCli);
|
|
185
|
+
|
|
186
|
+
program
|
|
187
|
+
.command('login')
|
|
188
|
+
.description('Authenticate with Ostro Cloud (uses iam.<region>.ostro-cloud.com by default)')
|
|
189
|
+
.option('-u, --username <username>', 'Username or root email')
|
|
190
|
+
.option('-p, --password <password>', 'Password')
|
|
191
|
+
.option('--endpoint <url>', '(deprecated) Use --domain via configure instead')
|
|
192
|
+
.action(login);
|
|
193
|
+
|
|
194
|
+
// Doctor
|
|
195
|
+
const SERVICES = [
|
|
196
|
+
{ name: 'Unified Console', host: 'console.ostro-cloud.com', path: '/api/health' },
|
|
197
|
+
{ name: 'Kubernetes Engine', host: 'console.ostro-cloud.com', path: '/kubernetes/api/health' },
|
|
198
|
+
{ name: 'Ostro Serverless', host: 'console.ostro-cloud.com', path: '/serverless/api/health' },
|
|
199
|
+
{ name: 'Ostro Bucket S3', host: 'console.ostro-cloud.com', path: '/storage/api/s3/health' },
|
|
200
|
+
{ name: 'Ostro Formation', host: 'console.ostro-cloud.com', path: '/formation/api/health' },
|
|
201
|
+
{ name: 'API Gateway', host: 'console.ostro-cloud.com', path: '/gateway/api/health' },
|
|
202
|
+
{ name: 'Ostro DNS', host: 'console.ostro-cloud.com', path: '/dns/api/health' },
|
|
203
|
+
{ name: 'Message Broker', host: 'console.ostro-cloud.com', path: '/broker/api/health' },
|
|
204
|
+
{ name: 'CloudWatch Logs', host: 'console.ostro-cloud.com', path: '/cloudwatch/api/health' }
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
async function checkService(svc) {
|
|
208
|
+
return new Promise((resolve) => {
|
|
209
|
+
const req = http.get({
|
|
210
|
+
host: svc.host,
|
|
211
|
+
port: 80,
|
|
212
|
+
path: svc.path,
|
|
213
|
+
timeout: 1500
|
|
214
|
+
}, (res) => {
|
|
215
|
+
resolve(res.statusCode === 200);
|
|
216
|
+
});
|
|
217
|
+
req.on('error', () => resolve(false));
|
|
218
|
+
req.on('timeout', () => { req.destroy(); resolve(false); });
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
program
|
|
223
|
+
.command('doctor')
|
|
224
|
+
.description('Check connectivity to all core services')
|
|
225
|
+
.action(async () => {
|
|
226
|
+
console.log('Checking Ostro Cloud Local Microservices...');
|
|
227
|
+
for (const svc of SERVICES) {
|
|
228
|
+
const ok = await checkService(svc);
|
|
229
|
+
console.log(` ${ok ? '✔' : '✖'} ${svc.name}`);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
program.parse(process.argv);
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
|
|
5
|
+
const CONFIG_FILE = path.join(os.homedir(), '.ostro', 'config.json');
|
|
6
|
+
|
|
7
|
+
// Single-domain path-based routing — Cloudflare-compatible
|
|
8
|
+
// Pattern: https://console.ostro-cloud.com/<service>
|
|
9
|
+
const DEFAULT_CONSOLE_HOST = 'https://console.ostro-cloud.com';
|
|
10
|
+
const DEFAULT_CLOUD_DOMAIN = 'ostro-cloud.com';
|
|
11
|
+
const DEFAULT_REGION = 'in-bihar-1';
|
|
12
|
+
|
|
13
|
+
// Service path segments — console.ostro-cloud.com/<path>
|
|
14
|
+
const SERVICE_PATHS = {
|
|
15
|
+
formation: 'formation',
|
|
16
|
+
serverless: 'serverless',
|
|
17
|
+
storage: 's3',
|
|
18
|
+
kubernetes: 'eks',
|
|
19
|
+
gateway: 'apigateway',
|
|
20
|
+
tunnel: 'tunnel',
|
|
21
|
+
dns: 'route53',
|
|
22
|
+
iam: 'iam',
|
|
23
|
+
ec2: 'ec2',
|
|
24
|
+
rds: 'rds',
|
|
25
|
+
cache: 'elasticache',
|
|
26
|
+
secrets: 'secretsmanager',
|
|
27
|
+
cloudwatch: 'logs',
|
|
28
|
+
sns: 'sns',
|
|
29
|
+
sqs: 'sqs',
|
|
30
|
+
efs: 'efs',
|
|
31
|
+
elb: 'elb',
|
|
32
|
+
registry: 'ecr',
|
|
33
|
+
broker: 'mq',
|
|
34
|
+
scheduler: 'scheduler',
|
|
35
|
+
organizations: 'organizations',
|
|
36
|
+
vpc: 'vpc',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns the base URL for a service.
|
|
41
|
+
* Pattern: https://console.ostro-cloud.com/<service>
|
|
42
|
+
*/
|
|
43
|
+
function defaultServiceUrl(service, _region, _domain) {
|
|
44
|
+
const seg = SERVICE_PATHS[service] || service;
|
|
45
|
+
const host = process.env.OSTRO_CONSOLE_HOST || DEFAULT_CONSOLE_HOST;
|
|
46
|
+
return `${host.replace(/\/+$/, '')}/${seg}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getStoredConfig() {
|
|
50
|
+
let fileConfig = {};
|
|
51
|
+
try {
|
|
52
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
53
|
+
fileConfig = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
|
|
54
|
+
}
|
|
55
|
+
} catch {}
|
|
56
|
+
|
|
57
|
+
const domain = fileConfig.domain || process.env.OSTRO_DOMAIN || DEFAULT_CLOUD_DOMAIN;
|
|
58
|
+
const region = fileConfig.region || process.env.OSTRO_REGION || process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || DEFAULT_REGION;
|
|
59
|
+
|
|
60
|
+
// Per-service URL resolution: explicit config/env → domain-derived default
|
|
61
|
+
const svcUrl = (svc, envVar, configKey) =>
|
|
62
|
+
fileConfig[configKey] || process.env[envVar] || defaultServiceUrl(svc, region, domain);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
domain,
|
|
66
|
+
region,
|
|
67
|
+
consoleUrl: fileConfig.consoleUrl || process.env.OSTRO_CONSOLE_URL || `https://console.${domain}`,
|
|
68
|
+
formationUrl: svcUrl('formation', 'OSTRO_FORMATION_URL', 'formationUrl'),
|
|
69
|
+
serverlessUrl: svcUrl('serverless', 'OSTRO_SERVERLESS_URL', 'serverlessUrl'),
|
|
70
|
+
s3Url: svcUrl('storage', 'OSTRO_S3_URL', 's3Url'),
|
|
71
|
+
k8sUrl: svcUrl('kubernetes', 'OSTRO_K8S_URL', 'k8sUrl'),
|
|
72
|
+
gatewayUrl: svcUrl('gateway', 'OSTRO_GATEWAY_URL', 'gatewayUrl'),
|
|
73
|
+
tunnelUrl: svcUrl('tunnel', 'OSTRO_TUNNEL_URL', 'tunnelUrl'),
|
|
74
|
+
dnsUrl: svcUrl('dns', 'OSTRO_DNS_URL', 'dnsUrl'),
|
|
75
|
+
iamUrl: svcUrl('iam', 'OSTRO_IAM_URL', 'iamUrl'),
|
|
76
|
+
ec2Url: svcUrl('ec2', 'OSTRO_EC2_URL', 'ec2Url'),
|
|
77
|
+
rdsUrl: svcUrl('rds', 'OSTRO_RDS_URL', 'rdsUrl'),
|
|
78
|
+
cacheUrl: svcUrl('cache', 'OSTRO_CACHE_URL', 'cacheUrl'),
|
|
79
|
+
secretsUrl: svcUrl('secrets', 'OSTRO_SECRETS_URL', 'secretsUrl'),
|
|
80
|
+
cloudwatchUrl: svcUrl('cloudwatch', 'OSTRO_CLOUDWATCH_URL', 'cloudwatchUrl'),
|
|
81
|
+
snsUrl: svcUrl('sns', 'OSTRO_SNS_URL', 'snsUrl'),
|
|
82
|
+
sqsUrl: svcUrl('sqs', 'OSTRO_SQS_URL', 'sqsUrl'),
|
|
83
|
+
efsUrl: svcUrl('efs', 'OSTRO_EFS_URL', 'efsUrl'),
|
|
84
|
+
elbUrl: svcUrl('elb', 'OSTRO_ELB_URL', 'elbUrl'),
|
|
85
|
+
registryUrl: svcUrl('registry', 'OSTRO_REGISTRY_URL', 'registryUrl'),
|
|
86
|
+
brokerUrl: svcUrl('broker', 'OSTRO_BROKER_URL', 'brokerUrl'),
|
|
87
|
+
schedulerUrl: svcUrl('scheduler', 'OSTRO_SCHEDULER_URL', 'schedulerUrl'),
|
|
88
|
+
organizationsUrl: svcUrl('organizations','OSTRO_ORGS_URL', 'organizationsUrl'),
|
|
89
|
+
vpcUrl: svcUrl('vpc', 'OSTRO_VPC_URL', 'vpcUrl'),
|
|
90
|
+
buildHost: fileConfig.buildHost || process.env.OSTRO_BUILD_HOST || null,
|
|
91
|
+
buildUser: fileConfig.buildUser || process.env.OSTRO_BUILD_USER || null,
|
|
92
|
+
accessKeyId: fileConfig.accessKeyId || process.env.OSTRO_ACCESS_KEY_ID || process.env.AWS_ACCESS_KEY_ID || null,
|
|
93
|
+
secretAccessKey: fileConfig.secretAccessKey || process.env.OSTRO_SECRET_ACCESS_KEY || process.env.AWS_SECRET_ACCESS_KEY || null,
|
|
94
|
+
token: fileConfig.token || process.env.OSTRO_SESSION_TOKEN || process.env.AWS_SESSION_TOKEN || process.env.OSTRO_API_KEY || null,
|
|
95
|
+
sessionToken: fileConfig.sessionToken || process.env.OSTRO_SESSION_TOKEN || process.env.AWS_SESSION_TOKEN || null,
|
|
96
|
+
roleArn: fileConfig.roleArn || process.env.OSTRO_ROLE_ARN || null,
|
|
97
|
+
clientId: fileConfig.clientId || process.env.OSTRO_CLIENT_ID || null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Service key → config field name
|
|
102
|
+
const SERVICE_URL_KEYS = {
|
|
103
|
+
formation: 'formationUrl',
|
|
104
|
+
serverless: 'serverlessUrl',
|
|
105
|
+
storage: 's3Url',
|
|
106
|
+
kubernetes: 'k8sUrl',
|
|
107
|
+
gateway: 'gatewayUrl',
|
|
108
|
+
tunnel: 'tunnelUrl',
|
|
109
|
+
dns: 'dnsUrl',
|
|
110
|
+
iam: 'iamUrl',
|
|
111
|
+
ec2: 'ec2Url',
|
|
112
|
+
rds: 'rdsUrl',
|
|
113
|
+
cache: 'cacheUrl',
|
|
114
|
+
secrets: 'secretsUrl',
|
|
115
|
+
cloudwatch: 'cloudwatchUrl',
|
|
116
|
+
sns: 'snsUrl',
|
|
117
|
+
sqs: 'sqsUrl',
|
|
118
|
+
efs: 'efsUrl',
|
|
119
|
+
elb: 'elbUrl',
|
|
120
|
+
registry: 'registryUrl',
|
|
121
|
+
broker: 'brokerUrl',
|
|
122
|
+
scheduler: 'schedulerUrl',
|
|
123
|
+
organizations: 'organizationsUrl',
|
|
124
|
+
vpc: 'vpcUrl',
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function resolveServiceUrl(servicePath, explicitUrl) {
|
|
128
|
+
if (explicitUrl) return explicitUrl;
|
|
129
|
+
const config = getStoredConfig();
|
|
130
|
+
const key = SERVICE_URL_KEYS[servicePath] || `${servicePath}Url`;
|
|
131
|
+
if (config[key]) return config[key];
|
|
132
|
+
// Final fallback: derive from domain + region
|
|
133
|
+
return defaultServiceUrl(servicePath, config.region, config.domain);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function saveConfig(newConfig) {
|
|
137
|
+
const dir = path.dirname(CONFIG_FILE);
|
|
138
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
139
|
+
let current = {};
|
|
140
|
+
try {
|
|
141
|
+
if (fs.existsSync(CONFIG_FILE)) current = JSON.parse(fs.readFileSync(CONFIG_FILE, 'utf-8'));
|
|
142
|
+
} catch {}
|
|
143
|
+
const merged = { ...current, ...newConfig };
|
|
144
|
+
fs.writeFileSync(CONFIG_FILE, JSON.stringify(merged, null, 2));
|
|
145
|
+
return merged;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function request(url, options = {}) {
|
|
149
|
+
const config = getStoredConfig();
|
|
150
|
+
const authToken = config.sessionToken || config.token;
|
|
151
|
+
if (!authToken && !options.skipAuth) {
|
|
152
|
+
throw new Error('Authentication required. Run "ostro-cloud login" or set OSTRO_SESSION_TOKEN.');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const headers = {
|
|
156
|
+
'Accept': 'application/json',
|
|
157
|
+
'Content-Type': 'application/json',
|
|
158
|
+
...(authToken ? { 'Authorization': `Bearer ${authToken}` } : {}),
|
|
159
|
+
...(config.sessionToken ? { 'X-Ostro-Session-Token': config.sessionToken } : {}),
|
|
160
|
+
...(config.roleArn ? { 'X-Ostro-Role-Arn': config.roleArn } : {}),
|
|
161
|
+
...(config.clientId ? { 'X-Ostro-Client-Id': config.clientId } : {}),
|
|
162
|
+
...(options.headers || {})
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const response = await fetch(url, { ...options, headers });
|
|
166
|
+
|
|
167
|
+
const contentType = response.headers.get('content-type') || '';
|
|
168
|
+
if (contentType.includes('application/json')) {
|
|
169
|
+
const data = await response.json();
|
|
170
|
+
if (!response.ok) throw new Error(data.message || data.error || `HTTP ${response.status}`);
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
const text = await response.text();
|
|
174
|
+
if (!response.ok) throw new Error(text || `HTTP ${response.status}`);
|
|
175
|
+
return text;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = {
|
|
179
|
+
getStoredConfig,
|
|
180
|
+
resolveServiceUrl,
|
|
181
|
+
saveConfig,
|
|
182
|
+
request,
|
|
183
|
+
defaultServiceUrl,
|
|
184
|
+
DEFAULT_CLOUD_DOMAIN,
|
|
185
|
+
DEFAULT_REGION,
|
|
186
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const { saveConfig, getStoredConfig, defaultServiceUrl, DEFAULT_CLOUD_DOMAIN, DEFAULT_REGION } = require('../client');
|
|
2
|
+
|
|
3
|
+
async function configureCli(options = {}) {
|
|
4
|
+
const updates = {};
|
|
5
|
+
|
|
6
|
+
if (options.domain) updates.domain = options.domain;
|
|
7
|
+
if (options.region) updates.region = options.region;
|
|
8
|
+
if (options.token) updates.token = options.token;
|
|
9
|
+
if (options.sessionToken) updates.sessionToken = options.sessionToken;
|
|
10
|
+
if (options.role) updates.roleArn = options.role;
|
|
11
|
+
// Keep --endpoint for backwards-compat but warn it is superseded by --domain
|
|
12
|
+
if (options.endpoint && !options.domain) {
|
|
13
|
+
console.warn('\x1b[33m⚠ --endpoint is deprecated. Use --domain <ostro-cloud.com> to set the cloud domain.\x1b[0m');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const saved = saveConfig(updates);
|
|
17
|
+
|
|
18
|
+
const domain = saved.domain || DEFAULT_CLOUD_DOMAIN;
|
|
19
|
+
const region = saved.region || DEFAULT_REGION;
|
|
20
|
+
|
|
21
|
+
const consoleHost = `https://console.${domain}`;
|
|
22
|
+
console.log('\x1b[32m✔ Ostro Cloud CLI configured.\x1b[0m\n');
|
|
23
|
+
console.log(` Console: \x1b[34m${consoleHost}\x1b[0m`);
|
|
24
|
+
console.log(` Region: \x1b[33m${region}\x1b[0m`);
|
|
25
|
+
console.log(` Domain: \x1b[90m${domain}\x1b[0m`);
|
|
26
|
+
console.log(` Token: \x1b[90m${saved.token ? `${saved.token.slice(0, 15)}…` : 'N/A'}\x1b[0m`);
|
|
27
|
+
console.log(`\n Service endpoints (path-based routing):`);
|
|
28
|
+
for (const svc of ['formation', 'serverless', 'storage', 'kubernetes', 'gateway', 'dns', 'iam', 'ec2', 'rds', 'cloudwatch', 'secrets', 'sns', 'sqs']) {
|
|
29
|
+
const url = defaultServiceUrl(svc, region, domain);
|
|
30
|
+
console.log(` \x1b[36m${svc.padEnd(14)}\x1b[0m ${url}`);
|
|
31
|
+
}
|
|
32
|
+
console.log('');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { configureCli };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { getStoredConfig } = require('../client');
|
|
4
|
+
const { deployFunction } = require('./serverless');
|
|
5
|
+
const { deployStack } = require('./formation');
|
|
6
|
+
const { applyManifest } = require('./k8s');
|
|
7
|
+
const { syncDirectory } = require('./s3');
|
|
8
|
+
|
|
9
|
+
async function universalDeploy(options = {}) {
|
|
10
|
+
const config = getStoredConfig();
|
|
11
|
+
const region = options.region || config.region || null;
|
|
12
|
+
const regionLabel = region ? ` in ${region}` : '';
|
|
13
|
+
console.log(`\x1b[36m🚀 Ostro Cloud Universal Deployer${regionLabel}\x1b[0m\n`);
|
|
14
|
+
|
|
15
|
+
const cwd = process.cwd();
|
|
16
|
+
const templatePath = options.template || (fs.existsSync(path.join(cwd, 'template.yaml')) ? 'template.yaml' : (fs.existsSync(path.join(cwd, 'template.yml')) ? 'template.yml' : null));
|
|
17
|
+
|
|
18
|
+
if (templatePath && fs.existsSync(path.join(cwd, templatePath))) {
|
|
19
|
+
console.log(` Found CloudFormation / SAM template: \x1b[33m${templatePath}\x1b[0m`);
|
|
20
|
+
await deployStack({
|
|
21
|
+
template: templatePath,
|
|
22
|
+
stackName: options.stack || path.basename(cwd) + '-stack',
|
|
23
|
+
region
|
|
24
|
+
});
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (fs.existsSync(path.join(cwd, 'serverless.yaml')) || fs.existsSync(path.join(cwd, 'serverless.yml'))) {
|
|
29
|
+
console.log(` Found Serverless configuration...`);
|
|
30
|
+
const file = fs.existsSync(path.join(cwd, 'serverless.yaml')) ? 'serverless.yaml' : 'serverless.yml';
|
|
31
|
+
await deployFunction('appFunction', { file: 'index.js', region });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (fs.existsSync(path.join(cwd, 'k8s.yaml')) || fs.existsSync(path.join(cwd, 'deployment.yaml'))) {
|
|
36
|
+
console.log(` Found Kubernetes manifest...`);
|
|
37
|
+
const file = fs.existsSync(path.join(cwd, 'k8s.yaml')) ? 'k8s.yaml' : 'deployment.yaml';
|
|
38
|
+
await applyManifest(file, { region });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(path.join(cwd, 'public')) || fs.existsSync(path.join(cwd, 'dist')) || fs.existsSync(path.join(cwd, 'build'))) {
|
|
43
|
+
const staticDir = fs.existsSync(path.join(cwd, 'dist')) ? 'dist' : (fs.existsSync(path.join(cwd, 'build')) ? 'build' : 'public');
|
|
44
|
+
console.log(` Found static website build directory [${staticDir}]...`);
|
|
45
|
+
await syncDirectory(staticDir, 's3://static-websites', { region });
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (fs.existsSync(path.join(cwd, 'index.js'))) {
|
|
50
|
+
console.log(` Deploying index.js as standalone serverless function...`);
|
|
51
|
+
await deployFunction('customWorker', { file: 'index.js', region });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log(`\x1b[33mℹ No deployment manifest (template.yaml, serverless.yaml, k8s.yaml) found in current directory.\x1b[0m`);
|
|
56
|
+
console.log(` Run \x1b[36mostro --help\x1b[0m to see specific service deployment commands.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
universalDeploy
|
|
61
|
+
};
|