diff --git a/aenv/pyproject.toml b/aenv/pyproject.toml index 444f38bb..6de2986f 100644 --- a/aenv/pyproject.toml +++ b/aenv/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "aenvironment" -version = "0.1.2.post1" +version = "0.1.3" description = "AEnvironment Python SDK - Production-grade environment for AI agent tools" readme = "README.md" requires-python = ">=3.10" diff --git a/docs/getting_started/concepts.md b/docs/getting_started/concepts.md index e0358b4b..4c81aa97 100644 --- a/docs/getting_started/concepts.md +++ b/docs/getting_started/concepts.md @@ -62,6 +62,110 @@ This design achieves effective separation between **declarative definition** and └──────────────────────────┴───────────────────────────────┘ ``` +## Environment Instance vs Environment Service + +AEnvironment supports two deployment modes for different use cases: + +### Environment Instance + +**Purpose**: Temporary, on-demand compute resources for short-lived tasks. + +**Key Characteristics:** + +- **Time-to-Live (TTL)**: Automatic cleanup after specified duration (default: 30 minutes) +- **Ephemeral**: Designed for temporary workloads +- **Single Pod**: Runs as a single Kubernetes Pod +- **No Persistence**: No built-in persistent storage support +- **Auto-cleanup**: Automatically released when TTL expires or task completes +- **Use Cases**: + - Development and testing + - CI/CD pipeline jobs + - One-time data processing tasks + - Temporary agent interactions + +**Management Commands:** + +```bash +# Create temporary instance (auto-releases after TTL or command exit) +aenv instance create myenv@1.0.0 --ttl 1h + +# List running instances +aenv instance list + +# Delete instance +aenv instance delete instance-id +``` + +### Environment Service + +**Purpose**: Long-running, production-grade deployments for persistent services. + +**Key Characteristics:** + +- **No TTL**: Runs indefinitely until explicitly deleted +- **Multiple Replicas**: Support for horizontal scaling (1-N replicas) +- **Persistent Storage**: Built-in PVC (PersistentVolumeClaim) support +- **Kubernetes Service**: Cluster DNS service URL for load balancing +- **High Availability**: Replica management for fault tolerance +- **Production-Ready**: Designed for production workloads +- **Use Cases**: + - Production agent services + - Long-running API servers + - Stateful applications requiring persistent data + - Multi-tenant service deployments + +**Management Commands:** + +```bash +# Create persistent service with 3 replicas +aenv service create myapp@1.0.0 --replicas 3 + +# Create service with persistent storage +aenv service create myapp@1.0.0 --enable-storage + +# List running services +aenv service list + +# Update service (scale, image, env vars) +aenv service update service-id --replicas 5 + +# Delete service (keeps storage by default) +aenv service delete service-id +``` + +### Comparison Matrix + +| Feature | Environment Instance | Environment Service | +|---------|---------------------|---------------------| +| **Lifetime** | Temporary (TTL-based) | Persistent (no TTL) | +| **Replicas** | Single Pod | Multiple Replicas (1-N) | +| **Storage** | No persistent storage | PVC support (optional) | +| **Service URL** | Direct Pod IP | Cluster DNS service URL | +| **Scaling** | Not supported | Horizontal scaling supported | +| **Use Case** | Development, testing, short tasks | Production, long-running services | +| **Auto-cleanup** | Yes (TTL or manual) | No (manual deletion only) | +| **Resource Isolation** | Pod-level | Deployment + Service | +| **Cost Model** | Pay per use (TTL-based) | Continuous running | + +### When to Use Which? + +**Choose Environment Instance when:** + +- Running temporary development or test workloads +- Executing one-time data processing jobs +- Testing environment configurations +- Running CI/CD pipeline steps +- Need automatic resource cleanup + +**Choose Environment Service when:** + +- Deploying production applications +- Need high availability and load balancing +- Require persistent data storage +- Running long-term agent services +- Need to scale horizontally +- Require predictable service endpoints + ### Environment An environment is a **static definition** that contains all metadata, configuration items, and component declarations required for agent operation. It describes what capabilities the environment "possesses" and what resources it "needs", but contains no runtime state. @@ -74,7 +178,7 @@ An environment is a **static definition** that contains all metadata, configurat - **Immutability**: Once published, the environment definition content is typically immutable, with evolution managed through versioning. - **Reusability**: The same environment definition can be shared and referenced by multiple environment instances. -### Environment Instance +### Environment Instance (Detailed) An environment instance is the **concrete runtime entity** of an environment template. When an environment is actually used, the system dynamically creates corresponding instances based on its definition. diff --git a/docs/guide/cli.md b/docs/guide/cli.md index d3468664..cef7e831 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -19,10 +19,12 @@ Commands: config Manage CLI configuration. get Get specified environment details init Initialize aenv project using environmental scaffolding tools - instances List running environment instances + instance Manage environment instances (create, list, get, delete) + instances List running environment instances (legacy command) list List all environments with pagination push Push current aenv project to remote backend aenv hub release Release current aenv project + service Manage environment services (create, list, get, delete, update) test Test current aenv project by running local directly version Display version number and corresponding build/commit information ``` @@ -35,7 +37,9 @@ Commands: | | `push` | Push environment to repository | | **Environment Management** | `list` | List all environments | | | `get` | Get environment details | -| | `instances` | List running environment instances | +| **Instance Management** | `instance` | Manage environment instances | +| | `instances` | List running instances (legacy) | +| **Service Management** | `service` | Manage environment services | | **Configuration Management** | `config` | Manage CLI configuration | | **System Information** | `version` | Display version information | @@ -116,28 +120,38 @@ my-project/ ```json { - "name": "r2egym-couple-env", + "name": "aenv", "version": "1.0.0", - "tags": ["swe", "python", "linux"], + "tags": ["linux"], "status": "Ready", - "codeUrl": "oss://xxx", + "codeUrl": "", "artifacts": [], "buildConfig": { "dockerfile": "./Dockerfile" }, "testConfig": { - "script": "pytest xxx" + "script": "" }, "deployConfig": { - "cpu": "1C", - "memory": "2G", + "cpu": "1", + "memory": "2Gi", "os": "linux", - "imagePrefix": "reg.example.com/areal_agent/image", - "podTemplate": "" + "ephemeralStorage": "5Gi", + "environmentVariables": {}, + "service": { + "replicas": 1, + "port": 8081, + "enableStorage": false, + "storageName": "aenv", + "storageSize": "10Gi", + "mountPath": "/home/admin/data" + } } } ``` +> **Note**: This is the default template structure. Additional fields like `imagePrefix` and `podTemplate` can be added as needed for specific deployment scenarios. + - **Dockerfile** @@ -449,6 +463,278 @@ aenv instances - **Instance ID Format**: Instance IDs typically follow the pattern `environment-name-randomid` (e.g., `test01-tb9gp8`) - **Filtering**: Use `--name` to filter by environment name, optionally combined with `--version` for more specific filtering +### `aenv instance` - Manage Environment Instances + +Unified interface for managing environment instances with full lifecycle control. + +> **Note**: `aenv instance` is the new command group that replaces and extends the legacy `aenv instances` command with additional capabilities like creating and deleting instances. + +#### Instance Subcommands + +| Subcommand | Description | +|---|---| +| `instance create` | Create new environment instance | +| `instance list` | List running instances | +| `instance get` | Get instance details by ID | +| `instance delete` | Delete an instance | +| `instance info` | Get instance information (requires active instance) | + +#### `instance create` - Create Instance + +Create and deploy a new environment instance. + +**Basic Usage:** + +```bash +# Create using config.json in current directory +aenv instance create + +# Create with explicit environment name +aenv instance create flowise-xxx@1.0.2 + +# Create with custom TTL and environment variables +aenv instance create flowise-xxx@1.0.2 --ttl 1h -e DB_HOST=localhost -e DB_PORT=5432 + +# Create with arguments and skip health check +aenv instance create flowise-xxx@1.0.2 --arg --debug --arg --verbose --skip-health + +# Create and keep alive (doesn't auto-release) +aenv instance create flowise-xxx@1.0.2 --keep-alive +``` + +**Options:** + +| Option | Short | Description | Default | +|---|---|---|---| +| `--datasource` | `-d` | Data source for mounting | - | +| `--ttl` | `-t` | Time to live (e.g., 30m, 1h) | 30m | +| `--env` | `-e` | Environment variables (KEY=VALUE) | - | +| `--arg` | `-a` | Command line arguments | - | +| `--system-url` | | AEnv system URL | from env/config | +| `--timeout` | | Request timeout in seconds | 60.0 | +| `--startup-timeout` | | Startup timeout in seconds | 500.0 | +| `--max-retries` | | Maximum retry attempts | 10 | +| `--api-key` | | API key for authentication | from env | +| `--skip-health` | | Skip health check | false | +| `--output` | `-o` | Output format (table/json) | table | +| `--keep-alive` | | Keep instance running | false | +| `--owner` | | Owner of the instance | from config | + +**Important Notes:** + +- By default, instances are automatically released when the command exits +- Use `--keep-alive` to keep the instance running after deployment +- Without `--keep-alive`, the instance lifecycle is tied to the command execution + +#### `instance list` - List Instances + +List running environment instances with filtering options. + +```bash +# List all running instances +aenv instance list + +# List instances for a specific environment +aenv instance list --name my-env + +# List instances for a specific environment and version +aenv instance list --name my-env --version 1.0.0 + +# Output as JSON +aenv instance list --output json +``` + +#### `instance get` - Get Instance Details + +Retrieve detailed information about a specific instance by its ID. + +```bash +# Get instance information +aenv instance get flowise-xxx-abc123 + +# Get in JSON format +aenv instance get flowise-xxx-abc123 --output json +``` + +#### `instance delete` - Delete Instance + +Delete a running environment instance. + +```bash +# Delete an instance (with confirmation) +aenv instance delete flowise-xxx-abc123 + +# Delete without confirmation +aenv instance delete flowise-xxx-abc123 --yes +``` + +### `aenv service` - Manage Environment Services + +Manage long-running environment services with persistent deployments, multiple replicas, and storage support. + +> **Service vs Instance**: Services are persistent deployments without TTL, supporting multiple replicas, persistent storage, and cluster DNS service URLs. Instances are temporary with TTL and auto-cleanup. + +#### Service Subcommands + +| Subcommand | Description | +|---|---| +| `service create` | Create new service deployment | +| `service list` | List running services | +| `service get` | Get service details by ID | +| `service delete` | Delete a service | +| `service update` | Update service configuration | + +#### `service create` - Create Service + +Create a long-running service with Deployment, Service, and optionally persistent storage. + +**Basic Usage:** + +```bash +# Create using config.json in current directory +aenv service create + +# Create with explicit environment name +aenv service create myapp@1.0.0 + +# Create with 3 replicas and custom port (no storage) +aenv service create myapp@1.0.0 --replicas 3 --port 8000 + +# Create with storage enabled (storageSize must be in config.json) +aenv service create myapp@1.0.0 --enable-storage + +# Create with environment variables +aenv service create myapp@1.0.0 -e DB_HOST=postgres -e CACHE_SIZE=1024 +``` + +**Options:** + +| Option | Short | Description | Default | +|---|---|---|---| +| `--replicas` | `-r` | Number of replicas | 1 or from config | +| `--port` | `-p` | Service port | 8080 or from config | +| `--env` | `-e` | Environment variables (KEY=VALUE) | - | +| `--enable-storage` | | Enable persistent storage | false | +| `--output` | `-o` | Output format (table/json) | table | + +**Configuration Priority:** + +1. CLI parameters (`--replicas`, `--port`, `--enable-storage`) +2. `config.json`'s `deployConfig.service` (new structure) +3. `config.json`'s `deployConfig` (legacy flat structure) +4. System defaults + +**Storage Configuration:** + +Storage settings are read from `config.json`'s `deployConfig.service`: + +- `storageSize`: Storage size like "10Gi", "20Gi" (required when `--enable-storage` is used) +- `storageName`: Storage name (default: environment name) +- `mountPath`: Mount path (default: /home/admin/data) + +**Important Notes:** + +- When storage is enabled, replicas must be 1 (enforced by backend) +- Services run indefinitely without TTL +- Services get cluster DNS service URLs for internal access + +#### `service list` - List Services + +List running environment services. + +```bash +# List all services +aenv service list + +# List services for specific environment +aenv service list --name myapp + +# Output as JSON +aenv service list --output json +``` + +**Output Example:** + +```bash +$ aenv service list ++------------------+-------------+---------+--------+----------+----------+--------------+----------------------+ +| Service ID | Environment | Owner | Status | Replicas | Storage | Service URL | Created At | ++==================+=============+=========+========+==========+==========+==============+======================+ +| myapp-svc-abc123 | myapp@1.0.0 | user1 | Ready | 3/3 | myapp-pvc| myapp-svc... | 2026-01-19T10:30:00Z | ++------------------+-------------+---------+--------+----------+----------+--------------+----------------------+ +``` + +#### `service get` - Get Service Details + +Retrieve detailed information about a specific service. + +```bash +# Get service information +aenv service get myapp-svc-abc123 + +# Get in JSON format +aenv service get myapp-svc-abc123 --output json +``` + +#### `service delete` - Delete Service + +Delete a running service. By default, keeps storage for reuse. + +```bash +# Delete a service (with confirmation), keep storage +aenv service delete myapp-svc-abc123 + +# Delete without confirmation +aenv service delete myapp-svc-abc123 --yes + +# Delete service and storage +aenv service delete myapp-svc-abc123 --delete-storage +``` + +**Options:** + +| Option | Description | +|---|---| +| `--yes`, `-y` | Skip confirmation prompt | +| `--delete-storage` | Also delete associated storage (WARNING: permanent data loss) | + +**Important Notes:** + +- By default, storage is kept for reuse when deleting a service +- Use `--delete-storage` to permanently delete storage and all data + +#### `service update` - Update Service + +Update a running service's configuration. + +```bash +# Scale to 5 replicas +aenv service update myapp-svc-abc123 --replicas 5 + +# Update image +aenv service update myapp-svc-abc123 --image myapp:2.0.0 + +# Update environment variables +aenv service update myapp-svc-abc123 -e DB_HOST=newhost -e DB_PORT=3306 + +# Update multiple things at once +aenv service update myapp-svc-abc123 --replicas 3 --image myapp:2.0.0 +``` + +**Options:** + +| Option | Short | Description | +|---|---|---| +| `--replicas` | `-r` | Update number of replicas | +| `--image` | | Update container image | +| `--env` | `-e` | Environment variables (KEY=VALUE) | +| `--output` | `-o` | Output format (table/json) | + +**Important Notes:** + +- At least one of `--replicas`, `--image`, or `--env` must be provided +- Environment variable updates merge with existing variables + ### `aenv get` - Get Environment Details Retrieve detailed information about a specific environment. diff --git a/docs/guide/environments.md b/docs/guide/environments.md index b35fabd4..bebc639e 100644 --- a/docs/guide/environments.md +++ b/docs/guide/environments.md @@ -14,29 +14,39 @@ Each environment project contains a core configuration file: `config.json` ```json { - "name": "my-env", + "name": "aenv", "version": "1.0.0", - "description": "My custom environment", - "tags": ["custom", "python", "ml"], + "tags": ["linux"], "status": "Ready", + "codeUrl": "", "artifacts": [], "buildConfig": { "dockerfile": "./Dockerfile", "context": "." }, "testConfig": { - "script": "pytest tests/" + "script": "" }, "deployConfig": { - "cpu": "2C", - "memory": "4G", + "cpu": "1", + "memory": "2Gi", "os": "linux", - "imagePrefix": "registry.example.com/envs", - "podTemplate": "Default" + "ephemeralStorage": "5Gi", + "environmentVariables": {}, + "service": { + "replicas": 1, + "port": 8081, + "enableStorage": false, + "storageName": "aenv", + "storageSize": "10Gi", + "mountPath": "/home/admin/data" + } } } ``` +> **Note**: This is the default template from `aenv init`. Optional fields like `imagePrefix` and `podTemplate` can be added in `deployConfig` for advanced deployment scenarios. + ### Configuration Fields | Field | Type | Required | Description | @@ -46,6 +56,7 @@ Each environment project contains a core configuration file: `config.json` | `description` | string | No | Human-readable environment description | | `tags` | string[] | No | Searchable tag collection | | `status` | string | No | Environment status identifier | +| `codeUrl` | string | No | URL or path to the environment source code (e.g., OSS path, Git URL) | | `artifacts` | object[] | No | Build artifacts list | | `buildConfig` | object | Yes | Build configuration | | `testConfig` | object | No | Test configuration | @@ -84,29 +95,102 @@ Supports custom build parameters including image name, tags, etc. These paramete #### Deployment Configuration (DeployConfig) +**Default Configuration (from official template):** + +```json +{ + "deployConfig": { + "cpu": "1", + "memory": "2Gi", + "os": "linux", + "ephemeralStorage": "5Gi", + "environmentVariables": {}, + "service": { + "replicas": 1, + "port": 8081, + "enableStorage": false, + "storageName": "aenv", + "storageSize": "10Gi", + "mountPath": "/home/admin/data" + } + } +} +``` + +**Extended Configuration (with optional fields):** + ```json { "deployConfig": { "cpu": "2", - "memory": "4G", + "memory": "4Gi", "os": "linux", + "ephemeralStorage": "5Gi", "imagePrefix": "registry.example.com/envs", - "podTemplate": "", - "env": { + "podTemplate": "Default", + "environmentVariables": { "MODEL_PATH": "/models/llm" + }, + "service": { + "replicas": 1, + "port": 8081, + "enableStorage": false, + "storageName": "my-env", + "storageSize": "10Gi", + "mountPath": "/home/admin/data" } } } ``` -**Deployment Parameters:** - -- **cpu**: CPU specification, defaults to 2 cores -- **memory**: Memory specification, defaults to 4GB -- **os**: Operating system, currently only supports Linux -- **imagePrefix**: Image prefix used to constrain common prefixes for multiple images associated with the current environment -- **podTemplate**: Pod template, defaults to "singleContainer" (single container mode) -- **env**: Environment variable configuration +**Core Deployment Parameters:** + +- **cpu**: CPU resource specification (used as both request and limit), defaults to "1" + - Example: "1", "2", "4" +- **memory**: Memory specification (used as both request and limit), defaults to "2Gi" + - Example: "2Gi", "4Gi", "8Gi" +- **ephemeralStorage**: Ephemeral storage specification (used as both request and limit), defaults to "5Gi" + - Example: "5Gi", "10Gi", "20Gi" +- **os**: Operating system, currently only supports "linux" +- **environmentVariables**: Environment variable configuration as key-value pairs, defaults to `{}` + +**Optional Deployment Parameters:** + +- **imagePrefix**: (Optional) Image prefix used to constrain common prefixes for multiple images associated with the current environment + - Not included in default template + - Add this when you need to specify a custom image registry prefix +- **podTemplate**: (Optional) Pod template, defaults to "singleContainer" (single container mode) + - Not included in default template + - Add this when using custom pod templates like "DualContainer" + +**Service Configuration (service):** + +The `service` block contains configuration for long-running service deployments: + +- **replicas**: Number of replicas, defaults to 1 + - Used by `aenv service create` command + - Must be 1 when storage is enabled +- **port**: Service port, defaults to 8081 + - The port exposed by the service for external access +- **enableStorage**: Enable persistent storage by default, defaults to false + - Can be overridden by `--enable-storage` CLI flag +- **storageName**: Storage name, defaults to environment name + - Used as PVC (PersistentVolumeClaim) name +- **storageSize**: Storage size like "10Gi", "20Gi" + - Required when storage is enabled + - Cannot be changed after creation +- **mountPath**: Mount path for persistent storage, defaults to "/home/admin/data" + - Where the persistent volume is mounted in the container + +**Legacy Support:** + +For backward compatibility, the following legacy parameters are still supported: + +- **cpuRequest** / **cpuLimit**: If not set, both use `cpu` value +- **memoryRequest** / **memoryLimit**: If not set, both use `memory` value +- **ephemeralStorageRequest** / **ephemeralStorageLimit**: If not set, both use `ephemeralStorage` value + +> **Recommended**: Use the simplified parameters (`cpu`, `memory`, `ephemeralStorage`) instead of the legacy separate request/limit parameters. ## Environment Architecture Types