anycloud 0.0.28 → 0.0.30
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/binaries/anycloud-darwin-arm64 +0 -0
- package/binaries/anycloud-darwin-x64 +0 -0
- package/binaries/anycloud-linux-arm64 +0 -0
- package/binaries/anycloud-linux-x64 +0 -0
- package/dist/cli/commands/config/edit.js +3 -3
- package/dist/cli/commands/config/edit.js.map +1 -1
- package/dist/cli/commands/config/new.js +3 -3
- package/dist/cli/commands/config/new.js.map +1 -1
- package/dist/cli/commands/credentials/edit.js +16 -15
- package/dist/cli/commands/credentials/edit.js.map +1 -1
- package/dist/cli/commands/credentials/new.js +8 -7
- package/dist/cli/commands/credentials/new.js.map +1 -1
- package/dist/cli/commands/list.js +12 -14
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/logs.js +39 -0
- package/dist/cli/commands/logs.js.map +1 -0
- package/dist/cli/commands/ssh.js +23 -158
- package/dist/cli/commands/ssh.js.map +1 -1
- package/dist/cli/commands/status.js +21 -23
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/terminate.js +16 -16
- package/dist/cli/commands/terminate.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/services/config.js +3 -34
- package/dist/cli/services/config.js.map +1 -1
- package/dist/cli/services/non-interactive.js +4 -3
- package/dist/cli/services/non-interactive.js.map +1 -1
- package/dist/cli/services/ssh.js +197 -0
- package/dist/cli/services/ssh.js.map +1 -0
- package/dist/shared/cloud-config.js +159 -0
- package/dist/shared/cloud-config.js.map +1 -0
- package/dist/shared/types.js +33 -106
- package/dist/shared/types.js.map +1 -1
- package/dist/shared/utils.js +72 -2
- package/dist/shared/utils.js.map +1 -1
- package/package.json +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { exitWithError } from '../utils/output.js';
|
|
2
|
+
import { CloudType } from '../../shared/types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Check if we're in non-interactive mode
|
|
4
5
|
*/
|
|
@@ -66,7 +67,7 @@ export function getCredentialsFromEnv() {
|
|
|
66
67
|
*/
|
|
67
68
|
function getAWSCredentialsFromEnv() {
|
|
68
69
|
return {
|
|
69
|
-
cloudProvider:
|
|
70
|
+
cloudProvider: CloudType.AWS,
|
|
70
71
|
accessKeyId: getEnvOrExit('AWS_ACCESS_KEY_ID', 'AWS Access Key ID'),
|
|
71
72
|
secretAccessKey: getEnvOrExit('AWS_SECRET_ACCESS_KEY', 'AWS Secret Access Key'),
|
|
72
73
|
};
|
|
@@ -76,7 +77,7 @@ function getAWSCredentialsFromEnv() {
|
|
|
76
77
|
*/
|
|
77
78
|
function getAzureCredentialsFromEnv() {
|
|
78
79
|
return {
|
|
79
|
-
cloudProvider:
|
|
80
|
+
cloudProvider: CloudType.Azure,
|
|
80
81
|
applicationId: getEnvOrExit('AZURE_APPLICATION_ID', 'Azure Application ID'),
|
|
81
82
|
secret: getEnvOrExit('AZURE_SECRET', 'Azure Secret'),
|
|
82
83
|
subscriptionId: getEnvOrExit('AZURE_SUBSCRIPTION_ID', 'Azure Subscription ID'),
|
|
@@ -88,7 +89,7 @@ function getAzureCredentialsFromEnv() {
|
|
|
88
89
|
*/
|
|
89
90
|
function getGCPCredentialsFromEnv() {
|
|
90
91
|
return {
|
|
91
|
-
cloudProvider:
|
|
92
|
+
cloudProvider: CloudType.GCP,
|
|
92
93
|
projectId: getEnvOrExit('GCP_PROJECT_ID', 'GCP Project ID'),
|
|
93
94
|
clientEmail: getEnvOrExit('GCP_CLIENT_EMAIL', 'GCP Client Email'),
|
|
94
95
|
privateKey: getEnvOrExit('GCP_PRIVATE_KEY', 'GCP Private Key'),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"non-interactive.js","sourceRoot":"","sources":["../../../src/cli/services/non-interactive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"non-interactive.js","sourceRoot":"","sources":["../../../src/cli/services/non-interactive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,MAAM;QAC/C,OAAO,CAAC,GAAG,CAAC,wBAAwB,KAAK,GAAG;QAC5C,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAC1B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,WAAmB;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,aAAa,CACX,yBAAyB,WAAW,cAAc;YAChD,iBAAiB,IAAI,wBAAwB,CAChD,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,0CAA0C;IAC1C,MAAM,QAAQ,GAAG,cAAc,CAAC,yBAAyB,CAAC,CAAC;IAE3D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,iDAAiD;QACjD,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;YACvE,OAAO,wBAAwB,EAAE,CAAC;QACpC,CAAC;QAED,IACE,OAAO,CAAC,GAAG,CAAC,oBAAoB;YAChC,OAAO,CAAC,GAAG,CAAC,YAAY;YACxB,OAAO,CAAC,GAAG,CAAC,qBAAqB;YAC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C,GAAG;QAC5B,SAAS,EAAE,YAAY,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;QAC3D,WAAW,EAAE,YAAY,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;QACjE,UAAU,EAAE,YAAY,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;KAC/D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO,cAAc,CAAC,2BAA2B,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import { writeFileSync, unlinkSync } from 'fs';
|
|
3
|
+
import { tmpdir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
import { getGitHubToken } from './auth.js';
|
|
7
|
+
import { getDeploymentStatus, listDeployments, loadSshKey, loadDeploymentCredentials, } from './api-client.js';
|
|
8
|
+
import { printInfo, printError, createSpinner, selectDeployment, } from '../utils/output.js';
|
|
9
|
+
import { isNonInteractive, getEnvOptional } from './non-interactive.js';
|
|
10
|
+
import { DeploymentState, isExitedState, } from '../../shared/types.js';
|
|
11
|
+
import packageJson from '../../../package.json' with { type: 'json' };
|
|
12
|
+
/**
|
|
13
|
+
* Resolves deployment ID, credentials, SSH key, and VM IP for SSH-based commands.
|
|
14
|
+
* Returns null if user cancels selection.
|
|
15
|
+
*/
|
|
16
|
+
export async function resolveSSHContext(options = {}) {
|
|
17
|
+
let deploymentId = options.id;
|
|
18
|
+
let isCompletedJob = false;
|
|
19
|
+
// Get GitHub token
|
|
20
|
+
const accessToken = await getGitHubToken();
|
|
21
|
+
// If no ID provided, fetch and prompt for selection
|
|
22
|
+
if (!deploymentId) {
|
|
23
|
+
if (isNonInteractive()) {
|
|
24
|
+
deploymentId = getEnvOptional('ANYCLOUD_DEPLOYMENT_ID');
|
|
25
|
+
if (!deploymentId) {
|
|
26
|
+
printError('Non-interactive mode: Deployment ID required.\n' +
|
|
27
|
+
' Provide ID as argument or set ANYCLOUD_DEPLOYMENT_ID environment variable.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const loadingSpinner = createSpinner('Loading deployments...').start();
|
|
33
|
+
const deployments = await listDeployments({
|
|
34
|
+
accessToken,
|
|
35
|
+
version: packageJson.version,
|
|
36
|
+
});
|
|
37
|
+
loadingSpinner.stop();
|
|
38
|
+
if (deployments.length === 0) {
|
|
39
|
+
printInfo('No deployments found.');
|
|
40
|
+
process.exit(0);
|
|
41
|
+
}
|
|
42
|
+
console.log('');
|
|
43
|
+
const selectedDeployment = await selectDeployment(deployments.filter((d) => (d.vmCount ?? 1) > 0));
|
|
44
|
+
if (!selectedDeployment) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
// Block container SSH during starting if requested
|
|
48
|
+
if (options.filterStarting &&
|
|
49
|
+
selectedDeployment.state === DeploymentState.Starting) {
|
|
50
|
+
printError(`Deployment is still starting (container may not be ready).\n` +
|
|
51
|
+
' Use "anycloud ssh --vm" to SSH directly to the VM.\n' +
|
|
52
|
+
' Or wait for the deployment to be running.');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
deploymentId = selectedDeployment.id;
|
|
56
|
+
isCompletedJob = isExitedState(selectedDeployment.state);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Load credentials and SSH key for this deployment
|
|
60
|
+
let credentials;
|
|
61
|
+
let sshPrivateKey;
|
|
62
|
+
try {
|
|
63
|
+
credentials = await loadDeploymentCredentials(deploymentId);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
printError(`Credentials not found for deployment ${deploymentId}.\n` +
|
|
67
|
+
' This deployment may have been created from a different machine.\n' +
|
|
68
|
+
' Email support@anycloud.sh to reclaim it.');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
sshPrivateKey = await loadSshKey(deploymentId);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
printError(`SSH key not found for deployment ${deploymentId}.\n` +
|
|
76
|
+
' This deployment may have been created from a different machine.\n' +
|
|
77
|
+
' Email support@anycloud.sh to reclaim it.');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
// Get VM IPs
|
|
81
|
+
const spinner = createSpinner('Getting VM info...').start();
|
|
82
|
+
const statusRequest = {
|
|
83
|
+
id: deploymentId,
|
|
84
|
+
credentials,
|
|
85
|
+
accessToken,
|
|
86
|
+
version: packageJson.version,
|
|
87
|
+
sshPrivateKey,
|
|
88
|
+
};
|
|
89
|
+
const response = await getDeploymentStatus(statusRequest);
|
|
90
|
+
spinner.stop();
|
|
91
|
+
if (!response.vmStatuses || response.vmStatuses.length === 0) {
|
|
92
|
+
printError('No VMs found for this deployment.');
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
// Select VM IP
|
|
96
|
+
let vmIp;
|
|
97
|
+
if (response.vmStatuses.length === 1) {
|
|
98
|
+
vmIp = response.vmStatuses[0].ip;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Multiple VMs - prompt for selection
|
|
102
|
+
const vmSelection = await prompts({
|
|
103
|
+
type: 'select',
|
|
104
|
+
name: 'ip',
|
|
105
|
+
message: 'Select VM to connect to:',
|
|
106
|
+
choices: response.vmStatuses.map((vm) => ({
|
|
107
|
+
title: vm.ip,
|
|
108
|
+
value: vm.ip,
|
|
109
|
+
})),
|
|
110
|
+
});
|
|
111
|
+
if (!vmSelection.ip) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
vmIp = vmSelection.ip;
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
deploymentId,
|
|
118
|
+
vmIp,
|
|
119
|
+
sshPrivateKey,
|
|
120
|
+
isCompletedJob,
|
|
121
|
+
response,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Spawns an SSH process to the given VM.
|
|
126
|
+
* Handles key file creation/cleanup and process lifecycle.
|
|
127
|
+
*/
|
|
128
|
+
export function spawnSSH(options) {
|
|
129
|
+
const { deploymentId, vmIp, sshPrivateKey, command, interactive } = options;
|
|
130
|
+
// Write SSH key to temp file
|
|
131
|
+
const keyFile = join(tmpdir(), `anycloud-ssh-${deploymentId}-${Date.now()}`);
|
|
132
|
+
writeFileSync(keyFile, sshPrivateKey, { mode: 0o600 });
|
|
133
|
+
// Build SSH args
|
|
134
|
+
const sshArgs = [
|
|
135
|
+
'-i',
|
|
136
|
+
keyFile,
|
|
137
|
+
'-p',
|
|
138
|
+
'22',
|
|
139
|
+
'-o',
|
|
140
|
+
'StrictHostKeyChecking=no',
|
|
141
|
+
'-o',
|
|
142
|
+
'UserKnownHostsFile=/dev/null',
|
|
143
|
+
'-o',
|
|
144
|
+
'LogLevel=ERROR',
|
|
145
|
+
];
|
|
146
|
+
if (interactive) {
|
|
147
|
+
sshArgs.push('-t');
|
|
148
|
+
}
|
|
149
|
+
sshArgs.push(`root@${vmIp}`);
|
|
150
|
+
if (command) {
|
|
151
|
+
sshArgs.push(command);
|
|
152
|
+
}
|
|
153
|
+
const sshProcess = spawn('ssh', sshArgs, { stdio: 'inherit' });
|
|
154
|
+
// Clean up key file when SSH exits
|
|
155
|
+
sshProcess.on('close', (code) => {
|
|
156
|
+
try {
|
|
157
|
+
unlinkSync(keyFile);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Ignore cleanup errors
|
|
161
|
+
}
|
|
162
|
+
if (code !== 0) {
|
|
163
|
+
console.log('');
|
|
164
|
+
const exitCode = code ?? 1;
|
|
165
|
+
if (exitCode === 255) {
|
|
166
|
+
printError(`SSH connection failed (exit code ${exitCode}).\n` +
|
|
167
|
+
` The VM at ${vmIp} may not be reachable.\n` +
|
|
168
|
+
' Possible causes:\n' +
|
|
169
|
+
' - VM is still starting up\n' +
|
|
170
|
+
' - VM has been terminated\n' +
|
|
171
|
+
' - Network/firewall issue\n' +
|
|
172
|
+
' Run "anycloud status" to check VM state.');
|
|
173
|
+
}
|
|
174
|
+
else if (exitCode === 1) {
|
|
175
|
+
printError(`SSH session ended with an error (exit code ${exitCode}).\n` +
|
|
176
|
+
' The container may have exited or the command failed.\n' +
|
|
177
|
+
' Try "anycloud ssh --vm" to connect directly to the VM.');
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
printError(`SSH exited with code ${exitCode}.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
process.exit(code ?? 0);
|
|
184
|
+
});
|
|
185
|
+
sshProcess.on('error', (err) => {
|
|
186
|
+
try {
|
|
187
|
+
unlinkSync(keyFile);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// Ignore cleanup errors
|
|
191
|
+
}
|
|
192
|
+
printError(`SSH failed: ${err.message}`);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
});
|
|
195
|
+
return sshProcess;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=ssh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssh.js","sourceRoot":"","sources":["../../../src/cli/services/ssh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,UAAU,EAC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AC;YAC3B,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;gBACrB,UAAU,CACR,oCAAoC,QAAQ,MAAM;oBAChD,gBAAgB,IAAI,0BAA0B;oBAC9C,uBAAuB;oBACvB,gCAAgC;oBAChC,+BAA+B;oBAC/B,+BAA+B;oBAC/B,6CAA6C,CAChD,CAAC;YACJ,CAAC;iBAAM,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;gBAC1B,UAAU,CACR,8CAA8C,QAAQ,MAAM;oBAC1D,2DAA2D;oBAC3D,2DAA2D,CAC9D,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,wBAAwB,QAAQ,GAAG,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC7B,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,CAAC,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,wBAAwB;QAC1B,CAAC;QACD,UAAU,CAAC,eAAe,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudConfig utilities.
|
|
3
|
+
* Functions for working with CloudConfig across CLI and Conductor.
|
|
4
|
+
*/
|
|
5
|
+
import AWSRegionsPerType from './assets/clouds/aws/regions-per-type.json' with { type: 'json' };
|
|
6
|
+
import GCPRegionsPerType from './assets/clouds/gcp/regions-per-type.json' with { type: 'json' };
|
|
7
|
+
import AzureRegionsPerType from './assets/clouds/azure/regions-per-type.json' with { type: 'json' };
|
|
8
|
+
import AWSTypesPerRegion from './assets/clouds/aws/types-per-region.json' with { type: 'json' };
|
|
9
|
+
import GCPTypesPerRegion from './assets/clouds/gcp/types-per-region.json' with { type: 'json' };
|
|
10
|
+
import AzureTypesPerRegion from './assets/clouds/azure/types-per-region.json' with { type: 'json' };
|
|
11
|
+
import { CloudType, } from './types.js';
|
|
12
|
+
// Default values when no region and vmType defined by the user.
|
|
13
|
+
// Default region: us-east
|
|
14
|
+
// Default vm type: Free tier per cloud. 1 vCPU, 1GB memory (0.5GB memory for gcp)
|
|
15
|
+
const DEFAULT_VM_TYPES_AND_REGIONS = {
|
|
16
|
+
AWS: {
|
|
17
|
+
region: 'us-east-1',
|
|
18
|
+
vmType: 't2.micro',
|
|
19
|
+
},
|
|
20
|
+
GCP: {
|
|
21
|
+
region: 'us-east4-a',
|
|
22
|
+
vmType: 'f1-micro',
|
|
23
|
+
},
|
|
24
|
+
Azure: {
|
|
25
|
+
region: 'eastus',
|
|
26
|
+
vmType: 'Standard_B1s',
|
|
27
|
+
},
|
|
28
|
+
Local: {
|
|
29
|
+
region: 'local',
|
|
30
|
+
vmType: 'local',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Complete a CloudConfig with default values for missing region/vmType.
|
|
35
|
+
* Returns a new object without mutating the input.
|
|
36
|
+
*/
|
|
37
|
+
export function completeCloudConfig(config) {
|
|
38
|
+
if (!config.vmType && !config.region) {
|
|
39
|
+
// If nothing defined, set default values
|
|
40
|
+
return {
|
|
41
|
+
...config,
|
|
42
|
+
region: DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].region,
|
|
43
|
+
vmType: DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].vmType,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (!config.vmType && config.region) {
|
|
47
|
+
// Get vm type for this region
|
|
48
|
+
// Default vmTypes defined are available on every region for all clouds except
|
|
49
|
+
// the Azure one that it is not available in two India regions.
|
|
50
|
+
return {
|
|
51
|
+
...config,
|
|
52
|
+
vmType: DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].vmType,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else if (!config.region && config.vmType) {
|
|
56
|
+
// Get region for this vm type
|
|
57
|
+
return {
|
|
58
|
+
...config,
|
|
59
|
+
region: getRegionByVMType(config.vmType, config.cloudProvider),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return config;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get a US region (preferred) or first available region for a VM type.
|
|
66
|
+
*/
|
|
67
|
+
export function getRegionByVMType(vmType, cloudProvider) {
|
|
68
|
+
let regionsPerType;
|
|
69
|
+
switch (cloudProvider) {
|
|
70
|
+
case CloudType.AWS:
|
|
71
|
+
regionsPerType = AWSRegionsPerType[vmType];
|
|
72
|
+
break;
|
|
73
|
+
case CloudType.GCP:
|
|
74
|
+
regionsPerType = GCPRegionsPerType[vmType];
|
|
75
|
+
break;
|
|
76
|
+
case CloudType.Azure:
|
|
77
|
+
regionsPerType = AzureRegionsPerType[vmType];
|
|
78
|
+
break;
|
|
79
|
+
case CloudType.Local:
|
|
80
|
+
return 'local';
|
|
81
|
+
default:
|
|
82
|
+
throw new Error(`Unsupported cloud provider: ${cloudProvider}`);
|
|
83
|
+
}
|
|
84
|
+
if (!regionsPerType?.length) {
|
|
85
|
+
throw new Error(`No regions available for VM type "${vmType}" on ${cloudProvider}`);
|
|
86
|
+
}
|
|
87
|
+
return getUSRegionOrFirst(regionsPerType);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get a US region from the list if available, otherwise return the first region.
|
|
91
|
+
*/
|
|
92
|
+
export function getUSRegionOrFirst(regionsPerType) {
|
|
93
|
+
if (!regionsPerType?.length) {
|
|
94
|
+
throw new Error('No regions available for VM type');
|
|
95
|
+
}
|
|
96
|
+
const USRegions = regionsPerType.filter((r) => r.includes('us'));
|
|
97
|
+
return USRegions.length ? USRegions[0] : regionsPerType[0];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get all available regions for a cloud provider.
|
|
101
|
+
*/
|
|
102
|
+
export function getRegions(cloudProvider) {
|
|
103
|
+
switch (cloudProvider) {
|
|
104
|
+
case CloudType.AWS:
|
|
105
|
+
return Object.keys(AWSTypesPerRegion);
|
|
106
|
+
case CloudType.GCP:
|
|
107
|
+
return Object.keys(GCPTypesPerRegion);
|
|
108
|
+
case CloudType.Azure:
|
|
109
|
+
return Object.keys(AzureTypesPerRegion);
|
|
110
|
+
case CloudType.Local:
|
|
111
|
+
return ['local'];
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unsupported cloud provider: ${cloudProvider}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get available VM types for a cloud provider and region.
|
|
118
|
+
*/
|
|
119
|
+
export function getVMTypes(cloudProvider, region) {
|
|
120
|
+
switch (cloudProvider) {
|
|
121
|
+
case CloudType.AWS:
|
|
122
|
+
return AWSTypesPerRegion[region] || [];
|
|
123
|
+
case CloudType.GCP:
|
|
124
|
+
return GCPTypesPerRegion[region] || [];
|
|
125
|
+
case CloudType.Azure:
|
|
126
|
+
return AzureTypesPerRegion[region] || [];
|
|
127
|
+
case CloudType.Local:
|
|
128
|
+
return ['local'];
|
|
129
|
+
default:
|
|
130
|
+
throw new Error(`Unsupported cloud provider: ${cloudProvider}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Extract credential fields from CloudCredentials (removes cloudProvider discriminator).
|
|
135
|
+
* Used when building CloudConfig from credentials.
|
|
136
|
+
*/
|
|
137
|
+
export function extractCredentials(credentials) {
|
|
138
|
+
switch (credentials.cloudProvider) {
|
|
139
|
+
case CloudType.AWS:
|
|
140
|
+
return {
|
|
141
|
+
accessKeyId: credentials.accessKeyId,
|
|
142
|
+
secretAccessKey: credentials.secretAccessKey,
|
|
143
|
+
};
|
|
144
|
+
case CloudType.GCP:
|
|
145
|
+
return {
|
|
146
|
+
projectId: credentials.projectId,
|
|
147
|
+
privateKey: credentials.privateKey,
|
|
148
|
+
clientEmail: credentials.clientEmail,
|
|
149
|
+
};
|
|
150
|
+
case CloudType.Azure:
|
|
151
|
+
return {
|
|
152
|
+
applicationId: credentials.applicationId,
|
|
153
|
+
secret: credentials.secret,
|
|
154
|
+
directoryId: credentials.directoryId,
|
|
155
|
+
subscriptionId: credentials.subscriptionId,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=cloud-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-config.js","sourceRoot":"","sources":["../../src/shared/cloud-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,iBAAiB,MAAM,2CAA2C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChG,OAAO,iBAAiB,MAAM,2CAA2C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChG,OAAO,mBAAmB,MAAM,6CAA6C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpG,OAAO,iBAAiB,MAAM,2CAA2C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChG,OAAO,iBAAiB,MAAM,2CAA2C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChG,OAAO,mBAAmB,MAAM,6CAA6C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAEpG,OAAO,EACL,SAAS,GAMV,MAAM,YAAY,CAAC;AAEpB,gEAAgE;AAChE,0BAA0B;AAC1B,kFAAkF;AAClF,MAAM,4BAA4B,GAG9B;IACF,GAAG,EAAE;QACH,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,UAAU;KACnB;IACD,GAAG,EAAE;QACH,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,UAAU;KACnB;IACD,KAAK,EAAE;QACL,MA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CAAC;IACpB,CAAC;AACH,CAAC"}
|
package/dist/shared/types.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
* Shared types for anycloud CLI and conductor
|
|
3
3
|
* These types are used across the client-server boundary
|
|
4
4
|
*/
|
|
5
|
-
import AWSRegionsPerType from './assets/clouds/aws/regions-per-type.json' with { type: 'json' };
|
|
6
|
-
import GCPRegionsPerType from './assets/clouds/gcp/regions-per-type.json' with { type: 'json' };
|
|
7
|
-
import AzureRegionsPerType from './assets/clouds/azure/regions-per-type.json' with { type: 'json' };
|
|
8
|
-
import AWSTypesPerRegion from './assets/clouds/aws/types-per-region.json' with { type: 'json' };
|
|
9
|
-
import GCPTypesPerRegion from './assets/clouds/gcp/types-per-region.json' with { type: 'json' };
|
|
10
|
-
import AzureTypesPerRegion from './assets/clouds/azure/types-per-region.json' with { type: 'json' };
|
|
11
5
|
// Cloud provider enum
|
|
12
6
|
export var CloudType;
|
|
13
7
|
(function (CloudType) {
|
|
@@ -25,18 +19,35 @@ export var DeploymentType;
|
|
|
25
19
|
// Deployment state enum for fast list
|
|
26
20
|
export var DeploymentState;
|
|
27
21
|
(function (DeploymentState) {
|
|
22
|
+
// Deploy steps (ordered)
|
|
28
23
|
DeploymentState["Provisioning"] = "provisioning";
|
|
24
|
+
DeploymentState["Registering"] = "registering";
|
|
25
|
+
DeploymentState["Initializing"] = "initializing";
|
|
29
26
|
DeploymentState["Starting"] = "starting";
|
|
27
|
+
DeploymentState["Syncing"] = "syncing";
|
|
28
|
+
// Running (after all steps complete)
|
|
30
29
|
DeploymentState["Running"] = "running";
|
|
30
|
+
// Terminal states
|
|
31
31
|
DeploymentState["Completed"] = "completed";
|
|
32
32
|
DeploymentState["Failed"] = "failed";
|
|
33
33
|
DeploymentState["Errored"] = "errored";
|
|
34
34
|
DeploymentState["Terminating"] = "terminating";
|
|
35
35
|
DeploymentState["Terminated"] = "terminated";
|
|
36
36
|
})(DeploymentState || (DeploymentState = {}));
|
|
37
|
+
// Step order for deploy workflow
|
|
38
|
+
export const DEPLOY_STEPS = [
|
|
39
|
+
DeploymentState.Provisioning,
|
|
40
|
+
DeploymentState.Registering,
|
|
41
|
+
DeploymentState.Initializing,
|
|
42
|
+
DeploymentState.Starting,
|
|
43
|
+
DeploymentState.Syncing,
|
|
44
|
+
];
|
|
37
45
|
export const stateEmoji = {
|
|
38
46
|
[DeploymentState.Provisioning]: '🏗️',
|
|
47
|
+
[DeploymentState.Registering]: '📝',
|
|
48
|
+
[DeploymentState.Initializing]: '⚙️',
|
|
39
49
|
[DeploymentState.Starting]: '🚀',
|
|
50
|
+
[DeploymentState.Syncing]: '🔄',
|
|
40
51
|
[DeploymentState.Running]: '⚡',
|
|
41
52
|
[DeploymentState.Completed]: '✅',
|
|
42
53
|
[DeploymentState.Failed]: '❌',
|
|
@@ -47,43 +58,40 @@ export const stateEmoji = {
|
|
|
47
58
|
// State groupings for filtering
|
|
48
59
|
export const ACTIVE_STATES = [
|
|
49
60
|
DeploymentState.Provisioning,
|
|
61
|
+
DeploymentState.Registering,
|
|
62
|
+
DeploymentState.Initializing,
|
|
50
63
|
DeploymentState.Starting,
|
|
64
|
+
DeploymentState.Syncing,
|
|
51
65
|
DeploymentState.Running,
|
|
52
66
|
DeploymentState.Terminating,
|
|
53
67
|
];
|
|
54
|
-
|
|
55
|
-
DeploymentState.Completed,
|
|
56
|
-
DeploymentState.Failed,
|
|
57
|
-
DeploymentState.Errored,
|
|
58
|
-
DeploymentState.Terminated,
|
|
59
|
-
];
|
|
60
|
-
// States where the job ran and container exited (distinct from Failed/Terminated)
|
|
68
|
+
// States where the container ran and exited (VM may exist if persisted)
|
|
61
69
|
// - Completed: container exited with code 0
|
|
62
70
|
// - Errored: container exited with non-zero code
|
|
63
|
-
// Used for SSH to offer container snapshot access
|
|
64
71
|
export const EXITED_STATES = [
|
|
65
72
|
DeploymentState.Completed,
|
|
66
73
|
DeploymentState.Errored,
|
|
67
74
|
];
|
|
75
|
+
// States where the VM is gone for sure
|
|
76
|
+
// - Failed: provisioning/infrastructure failed
|
|
77
|
+
// - Terminated: user explicitly terminated
|
|
78
|
+
export const TERMINATED_STATES = [
|
|
79
|
+
DeploymentState.Failed,
|
|
80
|
+
DeploymentState.Terminated,
|
|
81
|
+
];
|
|
82
|
+
// All final states (superset of EXITED_STATES + TERMINATED_STATES)
|
|
83
|
+
export const TERMINAL_STATES = [
|
|
84
|
+
...EXITED_STATES,
|
|
85
|
+
...TERMINATED_STATES,
|
|
86
|
+
];
|
|
68
87
|
/** Deployment is no longer active (final state) */
|
|
69
88
|
export function isTerminalState(state) {
|
|
70
89
|
return TERMINAL_STATES.includes(state);
|
|
71
90
|
}
|
|
72
|
-
/** Deployment is active (not yet in terminal state) */
|
|
73
|
-
export function isActiveState(state) {
|
|
74
|
-
return ACTIVE_STATES.includes(state);
|
|
75
|
-
}
|
|
76
91
|
/** Container ran and exited (for SSH snapshot access) */
|
|
77
92
|
export function isExitedState(state) {
|
|
78
93
|
return EXITED_STATES.includes(state);
|
|
79
94
|
}
|
|
80
|
-
/** VM is accessible (not provisioning, failed, or terminated) */
|
|
81
|
-
export function isVmAccessible(state) {
|
|
82
|
-
return (state !== DeploymentState.Provisioning &&
|
|
83
|
-
state !== DeploymentState.Failed &&
|
|
84
|
-
state !== DeploymentState.Terminating &&
|
|
85
|
-
state !== DeploymentState.Terminated);
|
|
86
|
-
}
|
|
87
95
|
// Credential classes
|
|
88
96
|
export class AWSCreds {
|
|
89
97
|
}
|
|
@@ -91,85 +99,4 @@ export class GCPCreds {
|
|
|
91
99
|
}
|
|
92
100
|
export class AzureCreds {
|
|
93
101
|
}
|
|
94
|
-
// Set default values when no region and vmType defined by the user.
|
|
95
|
-
// Default region: us-east
|
|
96
|
-
// Default vm type: Free tier per cloud. 1 vCPU, 1GB memory (0.5GB memory for gcp)
|
|
97
|
-
const DEFAULT_VM_TYPES_AND_REGIONS = {
|
|
98
|
-
AWS: {
|
|
99
|
-
region: 'us-east-1',
|
|
100
|
-
vmType: 't2.micro',
|
|
101
|
-
},
|
|
102
|
-
GCP: {
|
|
103
|
-
region: 'us-east4-a',
|
|
104
|
-
vmType: 'f1-micro',
|
|
105
|
-
},
|
|
106
|
-
Azure: {
|
|
107
|
-
region: 'eastus',
|
|
108
|
-
vmType: 'Standard_B1s',
|
|
109
|
-
},
|
|
110
|
-
Local: {
|
|
111
|
-
region: 'local',
|
|
112
|
-
vmType: 'local',
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
// Cloud configuration class
|
|
116
|
-
export class CloudConfig {
|
|
117
|
-
static maybeCompleteCloudConfig(config) {
|
|
118
|
-
if (!config.vmType && !config.region) {
|
|
119
|
-
// If nothing defined, set default values
|
|
120
|
-
config.region = DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].region;
|
|
121
|
-
config.vmType = DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].vmType;
|
|
122
|
-
}
|
|
123
|
-
else if (!config.vmType && config.region) {
|
|
124
|
-
// Get vm type for this region
|
|
125
|
-
// Default vmTypes defined are available on every region for all clouds except
|
|
126
|
-
// the Azure one that it is not available in two India regions.
|
|
127
|
-
config.vmType = DEFAULT_VM_TYPES_AND_REGIONS[config.cloudProvider].vmType;
|
|
128
|
-
}
|
|
129
|
-
else if (!config.region && config.vmType) {
|
|
130
|
-
// Get random region for this vm type
|
|
131
|
-
config.region = CloudConfig.getRegionByVMType(config.vmType, config.cloudProvider);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
static getRegionByVMType(vmType, cloudProvider) {
|
|
135
|
-
switch (cloudProvider) {
|
|
136
|
-
case CloudType.AWS:
|
|
137
|
-
return CloudConfig.getUSRegionOrFirst(AWSRegionsPerType[vmType]);
|
|
138
|
-
case CloudType.GCP:
|
|
139
|
-
return CloudConfig.getUSRegionOrFirst(GCPRegionsPerType[vmType]);
|
|
140
|
-
case CloudType.Azure:
|
|
141
|
-
return CloudConfig.getUSRegionOrFirst(AzureRegionsPerType[vmType]);
|
|
142
|
-
default:
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
static getUSRegionOrFirst(regionsPerType) {
|
|
147
|
-
const USRegions = regionsPerType.filter((r) => r.includes('us'));
|
|
148
|
-
return USRegions.length ? USRegions[0] : regionsPerType[0];
|
|
149
|
-
}
|
|
150
|
-
static getRegions(cloudProvider) {
|
|
151
|
-
switch (cloudProvider) {
|
|
152
|
-
case CloudType.AWS:
|
|
153
|
-
return Object.keys(AWSTypesPerRegion);
|
|
154
|
-
case CloudType.GCP:
|
|
155
|
-
return Object.keys(GCPTypesPerRegion);
|
|
156
|
-
case CloudType.Azure:
|
|
157
|
-
return Object.keys(AzureTypesPerRegion);
|
|
158
|
-
default:
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
static getVMTypes(cloudProvider, region) {
|
|
163
|
-
switch (cloudProvider) {
|
|
164
|
-
case CloudType.AWS:
|
|
165
|
-
return AWSTypesPerRegion[region] || [];
|
|
166
|
-
case CloudType.GCP:
|
|
167
|
-
return GCPTypesPerRegion[region] || [];
|
|
168
|
-
case CloudType.Azure:
|
|
169
|
-
return AzureTypesPerRegion[region] || [];
|
|
170
|
-
default:
|
|
171
|
-
return [];
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
102
|
//# sourceMappingURL=types.js.map
|
package/dist/shared/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,4BAAe,CAAA;IACf,4BAAe,CAAA;AACjB,CAAC,E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