@ucloud-sdks/ucloud-sandbox-cli 0.1.0-beta.5
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/LICENSE +12 -0
- package/README.md +1 -0
- package/dist/index.js +407 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/python-build-async.hbs +21 -0
- package/dist/templates/python-build-sync.hbs +16 -0
- package/dist/templates/python-template.hbs +36 -0
- package/dist/templates/readme.hbs +99 -0
- package/dist/templates/typescript-build.hbs +17 -0
- package/dist/templates/typescript-template.hbs +34 -0
- package/package.json +99 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from ucloud_sandbox import AsyncTemplate, default_build_logger
|
|
3
|
+
from .template import template
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main():
|
|
7
|
+
await AsyncTemplate.build(
|
|
8
|
+
template,
|
|
9
|
+
alias="{{alias}}",
|
|
10
|
+
{{#if cpuCount}}
|
|
11
|
+
cpu_count={{cpuCount}},
|
|
12
|
+
{{/if}}
|
|
13
|
+
{{#if memoryMB}}
|
|
14
|
+
memory_mb={{memoryMB}},
|
|
15
|
+
{{/if}}
|
|
16
|
+
on_build_logs=default_build_logger(),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == "__main__":
|
|
21
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ucloud_sandbox import Template, default_build_logger
|
|
2
|
+
from .template import template
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
if __name__ == "__main__":
|
|
6
|
+
Template.build(
|
|
7
|
+
template,
|
|
8
|
+
alias="{{alias}}",
|
|
9
|
+
{{#if cpuCount}}
|
|
10
|
+
cpu_count={{cpuCount}},
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if memoryMB}}
|
|
13
|
+
memory_mb={{memoryMB}},
|
|
14
|
+
{{/if}}
|
|
15
|
+
on_build_logs=default_build_logger(),
|
|
16
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from ucloud_sandbox import {{#if isAsync}}AsyncTemplate{{else}}Template{{/if}}
|
|
2
|
+
|
|
3
|
+
template = (
|
|
4
|
+
{{#if isAsync}}AsyncTemplate{{else}}Template{{/if}}()
|
|
5
|
+
{{#if fromImage}}
|
|
6
|
+
.from_image("{{{fromImage}}}")
|
|
7
|
+
{{/if}}
|
|
8
|
+
{{#each steps}}
|
|
9
|
+
{{#eq type "WORKDIR"}}
|
|
10
|
+
.set_workdir("{{{args.[0]}}}")
|
|
11
|
+
{{/eq}}
|
|
12
|
+
{{#eq type "USER"}}
|
|
13
|
+
.set_user("{{{args.[0]}}}")
|
|
14
|
+
{{/eq}}
|
|
15
|
+
{{#eq type "ENV"}}
|
|
16
|
+
.set_envs({
|
|
17
|
+
{{#each envVars}}
|
|
18
|
+
"{{{@key}}}": "{{{this}}}",
|
|
19
|
+
{{/each}}
|
|
20
|
+
})
|
|
21
|
+
{{/eq}}
|
|
22
|
+
{{#eq type "RUN"}}
|
|
23
|
+
.run_cmd("{{{args.[0]}}}")
|
|
24
|
+
{{/eq}}
|
|
25
|
+
{{#eq type "COPY"}}
|
|
26
|
+
.copy("{{{src}}}", "{{{dest}}}")
|
|
27
|
+
{{/eq}}
|
|
28
|
+
{{/each}}
|
|
29
|
+
{{#if startCmd}}
|
|
30
|
+
{{#if readyCmd}}
|
|
31
|
+
.set_start_cmd("sudo {{{escapeDoubleQuotes startCmd}}}", "{{{escapeDoubleQuotes readyCmd}}}")
|
|
32
|
+
{{/if}}
|
|
33
|
+
{{else if readyCmd}}
|
|
34
|
+
.set_ready_cmd("sudo {{{escapeDoubleQuotes readyCmd}}}")
|
|
35
|
+
{{/if}}
|
|
36
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# {{alias}} - UCloud Sandbox Template
|
|
2
|
+
|
|
3
|
+
This is a UCloud sandbox template that allows you to run code in a controlled environment.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
Before you begin, make sure you have:
|
|
8
|
+
- A UCloud account
|
|
9
|
+
- Your UCloud Sandbox API key (get it from the UCloud console)
|
|
10
|
+
{{#if isTypeScript}}- Node.js and npm/yarn (or similar) installed{{else if isPython}}- Python installed{{/if}}
|
|
11
|
+
|
|
12
|
+
## Configuration
|
|
13
|
+
|
|
14
|
+
1. Create a `.env` file in your project root or set the environment variable:
|
|
15
|
+
```
|
|
16
|
+
UCLOUD_SANDBOX_API_KEY=your_api_key_here
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Installing Dependencies
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
{{#if isTypeScript}}
|
|
23
|
+
npm install ucloud_sandbox
|
|
24
|
+
{{else if isPython}}
|
|
25
|
+
pip install ucloud_sandbox
|
|
26
|
+
{{/if}}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Building the Template
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
{{#if isTypeScript}}
|
|
33
|
+
# For development
|
|
34
|
+
npm run sandbox:build:dev
|
|
35
|
+
|
|
36
|
+
# For production
|
|
37
|
+
npm run sandbox:build:prod
|
|
38
|
+
{{else if isPython}}
|
|
39
|
+
# For development
|
|
40
|
+
make sandbox:build:dev
|
|
41
|
+
|
|
42
|
+
# For production
|
|
43
|
+
make sandbox:build:prod
|
|
44
|
+
{{/if}}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Using the Template in a Sandbox
|
|
48
|
+
|
|
49
|
+
Once your template is built, you can use it in your UCloud sandbox:
|
|
50
|
+
|
|
51
|
+
{{#if isTypeScript}}
|
|
52
|
+
```typescript
|
|
53
|
+
import { Sandbox } from 'ucloud_sandbox'
|
|
54
|
+
|
|
55
|
+
// Create a new sandbox instance
|
|
56
|
+
const sandbox = await Sandbox.create('{{alias}}')
|
|
57
|
+
|
|
58
|
+
// Your sandbox is ready to use!
|
|
59
|
+
console.log('Sandbox created successfully')
|
|
60
|
+
```
|
|
61
|
+
{{else if isPythonSync}}
|
|
62
|
+
```python
|
|
63
|
+
from ucloud_sandbox import Sandbox
|
|
64
|
+
|
|
65
|
+
# Create a new sandbox instance
|
|
66
|
+
sandbox = Sandbox.create('{{alias}}')
|
|
67
|
+
|
|
68
|
+
# Your sandbox is ready to use!
|
|
69
|
+
print('Sandbox created successfully')
|
|
70
|
+
```
|
|
71
|
+
{{else if isPythonAsync}}
|
|
72
|
+
```python
|
|
73
|
+
from ucloud_sandbox import AsyncSandbox
|
|
74
|
+
import asyncio
|
|
75
|
+
|
|
76
|
+
async def main():
|
|
77
|
+
# Create a new sandbox instance
|
|
78
|
+
sandbox = await AsyncSandbox.create('{{alias}}')
|
|
79
|
+
|
|
80
|
+
# Your sandbox is ready to use!
|
|
81
|
+
print('Sandbox created successfully')
|
|
82
|
+
|
|
83
|
+
# Run the async function
|
|
84
|
+
asyncio.run(main())
|
|
85
|
+
```
|
|
86
|
+
{{/if}}
|
|
87
|
+
|
|
88
|
+
## Template Structure
|
|
89
|
+
|
|
90
|
+
- `{{templateFile}}` - Defines the sandbox template configuration
|
|
91
|
+
- `{{buildDevFile}}` - Builds the template for development
|
|
92
|
+
- `{{buildProdFile}}` - Builds the template for production
|
|
93
|
+
|
|
94
|
+
## Next Steps
|
|
95
|
+
|
|
96
|
+
1. Customize the template in `{{templateFile}}` to fit your needs
|
|
97
|
+
2. Build the template using one of the methods above
|
|
98
|
+
3. Use the template in your UCloud sandbox code
|
|
99
|
+
4. Check out the UCloud Sandbox documentation at https://sandbox.ucloudai.com/docs for more advanced usage
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Template, defaultBuildLogger } from 'ucloud_sandbox'
|
|
2
|
+
import { template } from './template'
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
await Template.build(template, {
|
|
6
|
+
alias: '{{alias}}',
|
|
7
|
+
{{#if cpuCount}}
|
|
8
|
+
cpuCount: {{cpuCount}},
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if memoryMB}}
|
|
11
|
+
memoryMB: {{memoryMB}},
|
|
12
|
+
{{/if}}
|
|
13
|
+
onBuildLogs: defaultBuildLogger(),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Template } from 'ucloud_sandbox'
|
|
2
|
+
|
|
3
|
+
export const template = Template()
|
|
4
|
+
{{#if fromImage}}
|
|
5
|
+
.fromImage('{{{fromImage}}}')
|
|
6
|
+
{{/if}}
|
|
7
|
+
{{#each steps}}
|
|
8
|
+
{{#eq type "WORKDIR"}}
|
|
9
|
+
.setWorkdir('{{{args.[0]}}}')
|
|
10
|
+
{{/eq}}
|
|
11
|
+
{{#eq type "USER"}}
|
|
12
|
+
.setUser('{{{args.[0]}}}')
|
|
13
|
+
{{/eq}}
|
|
14
|
+
{{#eq type "ENV"}}
|
|
15
|
+
.setEnvs({
|
|
16
|
+
{{#each envVars}}
|
|
17
|
+
'{{{@key}}}': '{{{this}}}',
|
|
18
|
+
{{/each}}
|
|
19
|
+
})
|
|
20
|
+
{{/eq}}
|
|
21
|
+
{{#eq type "RUN"}}
|
|
22
|
+
.runCmd('{{{args.[0]}}}')
|
|
23
|
+
{{/eq}}
|
|
24
|
+
{{#eq type "COPY"}}
|
|
25
|
+
.copy('{{{src}}}', '{{{dest}}}')
|
|
26
|
+
{{/eq}}
|
|
27
|
+
{{/each}}
|
|
28
|
+
{{#if startCmd}}
|
|
29
|
+
{{#if readyCmd}}
|
|
30
|
+
.setStartCmd('sudo {{{escapeQuotes startCmd}}}', '{{{escapeQuotes readyCmd}}}')
|
|
31
|
+
{{/if}}
|
|
32
|
+
{{else if readyCmd}}
|
|
33
|
+
.setReadyCmd('sudo {{{escapeQuotes readyCmd}}}')
|
|
34
|
+
{{/if}}
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ucloud-sdks/ucloud-sandbox-cli",
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
|
+
"description": "CLI for managing UCloud sandbox templates",
|
|
5
|
+
"homepage": "https://ucloud.cn",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "jason.mei"
|
|
9
|
+
},
|
|
10
|
+
"bugs": "https://github.com/ucloud/ucloud-sandbox-cli/issues",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ucloud/ucloud-sandbox-cli.git",
|
|
14
|
+
"directory": "packages/cli"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ucloud",
|
|
21
|
+
"ai-agents",
|
|
22
|
+
"agents",
|
|
23
|
+
"ai",
|
|
24
|
+
"code-interpreter",
|
|
25
|
+
"sandbox",
|
|
26
|
+
"code",
|
|
27
|
+
"cli",
|
|
28
|
+
"runtime",
|
|
29
|
+
"vm",
|
|
30
|
+
"nodejs",
|
|
31
|
+
"javascript",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prepublishOnly": "pnpm build",
|
|
37
|
+
"build": "tsc --noEmit --skipLibCheck && tsup --minify",
|
|
38
|
+
"dev": "tsup --watch",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"format": "prettier --write src",
|
|
41
|
+
"test:interactive": "pnpm build && ./dist/index.js",
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"test:watch": "vitest watch",
|
|
44
|
+
"test:coverage": "vitest run --coverage",
|
|
45
|
+
"check-deps": "knip",
|
|
46
|
+
"update-deps": "ncu -u && pnpm i",
|
|
47
|
+
"generate-ref": "./scripts/generate_sdk_ref.sh"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"e2b": "file:./packages/js-sdk",
|
|
51
|
+
"@types/command-exists": "^1.2.3",
|
|
52
|
+
"@types/handlebars": "^4.1.0",
|
|
53
|
+
"@types/inquirer": "^9.0.7",
|
|
54
|
+
"@types/json2md": "^1.5.4",
|
|
55
|
+
"@types/node": "^20.19.19",
|
|
56
|
+
"@types/npmcli__package-json": "^4.0.4",
|
|
57
|
+
"@types/statuses": "^2.0.5",
|
|
58
|
+
"@types/update-notifier": "6.0.5",
|
|
59
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
60
|
+
"json2md": "^2.0.1",
|
|
61
|
+
"knip": "^5.43.6",
|
|
62
|
+
"npm-check-updates": "^16.14.6",
|
|
63
|
+
"tsup": "^8.4.0",
|
|
64
|
+
"typescript": "^5.2.2",
|
|
65
|
+
"vitest": "^3.2.4"
|
|
66
|
+
},
|
|
67
|
+
"files": [
|
|
68
|
+
"dist",
|
|
69
|
+
"LICENSE",
|
|
70
|
+
"README.md",
|
|
71
|
+
"package.json"
|
|
72
|
+
],
|
|
73
|
+
"bin": {
|
|
74
|
+
"ucloud-sandbox-cli": "dist/index.js"
|
|
75
|
+
},
|
|
76
|
+
"dependencies": {
|
|
77
|
+
"@iarna/toml": "^2.2.5",
|
|
78
|
+
"@inquirer/prompts": "^7.9.0",
|
|
79
|
+
"@npmcli/package-json": "^5.2.1",
|
|
80
|
+
"async-listen": "^3.0.1",
|
|
81
|
+
"boxen": "^7.1.1",
|
|
82
|
+
"chalk": "^5.3.0",
|
|
83
|
+
"cli-highlight": "^2.1.11",
|
|
84
|
+
"command-exists": "^1.2.9",
|
|
85
|
+
"commander": "^11.1.0",
|
|
86
|
+
"console-table-printer": "^2.11.2",
|
|
87
|
+
"dockerfile-ast": "^0.6.1",
|
|
88
|
+
"handlebars": "^4.7.8",
|
|
89
|
+
"inquirer": "^12.10.0",
|
|
90
|
+
"open": "^9.1.0",
|
|
91
|
+
"statuses": "^2.0.1",
|
|
92
|
+
"strip-ansi": "^7.1.0",
|
|
93
|
+
"update-notifier": "^6.0.2",
|
|
94
|
+
"yup": "^1.3.2"
|
|
95
|
+
},
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=20"
|
|
98
|
+
}
|
|
99
|
+
}
|