|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to Qoder (qoder.com) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +FC3 is a Serverless Devs component for Alibaba Cloud Function Compute 3.0, providing full lifecycle management for serverless functions. Written in TypeScript, it handles creating, developing, debugging, deploying, and operating functions. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Build & Test |
| 12 | +```bash |
| 13 | +# Build the project (uses ncc to bundle) |
| 14 | +npm run build |
| 15 | + |
| 16 | +# Run all tests with coverage |
| 17 | +npm test |
| 18 | + |
| 19 | +# Run specific test file |
| 20 | +npm test -- path/to/test_file |
| 21 | + |
| 22 | +# Run tests matching pattern |
| 23 | +npm test -- -t "test pattern" |
| 24 | + |
| 25 | +# Run without coverage |
| 26 | +npm test -- --no-coverage |
| 27 | + |
| 28 | +# Format code |
| 29 | +npm run format |
| 30 | + |
| 31 | +# Lint code |
| 32 | +npm run lint |
| 33 | + |
| 34 | +# Fix lint issues |
| 35 | +npm run fix |
| 36 | +``` |
| 37 | + |
| 38 | +### Development |
| 39 | +```bash |
| 40 | +# Watch mode for development |
| 41 | +npm run watch |
| 42 | + |
| 43 | +# Generate JSON schema from TypeScript interfaces |
| 44 | +npm run generate-schema |
| 45 | +``` |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +### Entry Point Flow |
| 50 | +1. **Main Entry** (`src/index.ts`): Fc class extends Base, routes to subcommands |
| 51 | +2. **Base Class** (`src/base.ts`): Common functionality, `handlePreRun` preprocessing: |
| 52 | + - Handles credential management |
| 53 | + - Role ARN completion and validation |
| 54 | + - Default config application (FUNCTION_DEFAULT_CONFIG vs FUNCTION_CUSTOM_DEFAULT_CONFIG) |
| 55 | + - Trigger role initialization (auto-creates default roles for OSS, SLS, CDN, TableStore, MNS_TOPIC, EventBridge triggers) |
| 56 | + - Base directory resolution from yaml.path |
| 57 | + |
| 58 | +### Module Organization |
| 59 | +- **subCommands/**: Each subcommand (deploy, build, local, invoke, etc.) in separate directory with index.ts |
| 60 | +- **resources/**: Cloud service management modules |
| 61 | + - `fc/`: Function Compute operations (main FC API client, retry logic, deployment) |
| 62 | + - `ram/`: Role and permission management |
| 63 | + - `sls/`: Log service integration |
| 64 | + - `vpc-nas/`: VPC and NAS configuration |
| 65 | + - `acr/`: Container registry operations |
| 66 | +- **utils/**: Shared utility functions |
| 67 | +- **interface/**: TypeScript interfaces and type definitions |
| 68 | +- **default/**: Default configurations (FUNCTION_DEFAULT_CONFIG, FUNCTION_CUSTOM_DEFAULT_CONFIG, IMAGE_ACCELERATION_REGION) |
| 69 | +- **commands-help/**: Help text definitions |
| 70 | + |
| 71 | +### Build System |
| 72 | +BuilderFactory pattern with multiple builder types: |
| 73 | +- **DefaultBuilder**: Standard code builds |
| 74 | +- **ImageDockerBuilder**: Docker-based container builds |
| 75 | +- **ImageKanikoBuilder**: Kaniko builds (for App Center) |
| 76 | +- **ImageBuildKitBuilder**: BuildKit builds (for YunXiao) |
| 77 | + |
| 78 | +Runtime detection in FC class determines which builder to use. |
| 79 | + |
| 80 | +### Key Architectural Patterns |
| 81 | +1. **Subcommand Pattern**: Each public method in Fc class calls `handlePreRun()` then instantiates corresponding subcommand class |
| 82 | +2. **Dynamic Method Dispatch**: Some subcommands (version, alias, concurrency, provision, scaling, layer, session, instance, model) use `subCommand` property to route to internal methods |
| 83 | +3. **Credential Lazy Loading**: Credentials fetched only when needed via `inputs.getCredential()` |
| 84 | +4. **Role ARN Completion**: Role names automatically completed to full ARN format using AccountID |
| 85 | + |
| 86 | +### Testing Structure |
| 87 | +- **__tests__/ut/**: Unit tests |
| 88 | +- **__tests__/it/**: Integration tests |
| 89 | +- **__tests__/e2e/**: End-to-end tests |
| 90 | +- Test naming pattern: `{module}_test.ts` |
| 91 | +- Uses Jest with ts-jest transformer |
| 92 | +- testTimeout: 30000ms |
| 93 | +- Current coverage: ~58% statements, ~54% branches |
| 94 | + |
| 95 | +### Important Implementation Details |
| 96 | +- Custom container runtime uses different default configs (FUNCTION_CUSTOM_DEFAULT_CONFIG) |
| 97 | +- Image acceleration only available in specific regions (IMAGE_ACCELERATION_REGION) |
| 98 | +- NAS mount points default `enableTLS: false` if not specified |
| 99 | +- Triggers without explicit invocationRole get auto-created default roles |
| 100 | +- Docker check required for local and custom container builds |
| 101 | +- FC deployment includes retry logic (FC_DEPLOY_RETRY_COUNT) |
| 102 | + |
| 103 | +## Project-Specific Notes |
| 104 | + |
| 105 | +### Role Handling |
| 106 | +The component automatically handles IAM roles: |
| 107 | +- Converts role names to full ARN format using AccountID |
| 108 | +- Creates default trigger roles when not specified (OSS, SLS, MNS_TOPIC, CDN, TableStore) |
| 109 | +- Creates service linked roles for EventBridge triggers |
| 110 | + |
| 111 | +### Runtime Types |
| 112 | +- Custom container runtime (`custom-container`): Uses Docker/Kaniko/BuildKit builders |
| 113 | +- Custom runtime (`custom`, `custom.debian10`): Uses FUNCTION_CUSTOM_DEFAULT_CONFIG |
| 114 | +- Standard runtimes: Uses FUNCTION_DEFAULT_CONFIG |
| 115 | + |
| 116 | +### Default Config Alignment |
| 117 | +When memory is 512MB and cpu/diskSize are unset, defaults to cpu=0.35, diskSize=512 (matches console behavior) |
0 commit comments