|
| 1 | +# Huawei FunctionGraph Deploy Action |
| 2 | + |
| 3 | +The Huawei FunctionGraph Deploy Action is a GitHub Action that deploys functions to Huawei Cloud's FunctionGraph. It supports both ZIP code deployments and custom Docker image deployments using SWR, and provides options for VPC configuration, environment variable injection, and trigger creation. |
| 4 | + |
| 5 | +> **Disclaimer:** This project is currently in version 0.1.0 and does not yet implement all functionalities available in Huawei Cloud's CLI (KooCli). Contributions are welcome to enhance and expand the project's features. |
| 6 | +
|
| 7 | +## Overview |
| 8 | + |
| 9 | +This action performs the following tasks: |
| 10 | + |
| 11 | +1. **Authentication:** Authenticates with Huawei Cloud using the provided access keys and region. |
| 12 | +2. **CLI Setup:** Sets up the Huawei Cloud CLI (KooCli). |
| 13 | +3. **Project Configuration:** Retrieves and sets the Huawei FunctionGraph Project ID. |
| 14 | +4. **Argument Building:** Constructs command-line arguments for VPC settings, function code, environment variables, and custom image parameters. |
| 15 | +5. **Docker Operations (if applicable):** Logs into the Docker repository and builds/pushes a Docker image when using a custom Docker image. |
| 16 | +6. **Function Deployment:** Checks if the function exists, updating its code/configuration if it does or creating a new function if it does not. |
| 17 | +7. **Trigger Management:** Creates or updates function triggers based on provided trigger configurations. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +- A Huawei Cloud account with the necessary permissions. |
| 22 | +- Valid Huawei Cloud **Access Key ID** and **Secret Access Key**. |
| 23 | +- Appropriate configuration values for the region, VPC, custom image parameters, etc. |
| 24 | +- GitHub Secrets and Variables configured for sensitive data and environment-specific values. |
| 25 | + |
| 26 | +## Inputs |
| 27 | + |
| 28 | +### Credentials |
| 29 | + |
| 30 | +- **`access_key_id`** (required): Huawei Cloud Access Key ID. |
| 31 | +- **`secret_access_key`** (required): Huawei Cloud Secret Access Key. |
| 32 | + |
| 33 | +### Function Configuration |
| 34 | + |
| 35 | +- **`region`** (required): Region where the function will be deployed (e.g., `la-south-2`). |
| 36 | +- **`func_name`** (required): Name of the function to create. |
| 37 | +- **`package`**: Function package (default: `"default"`). |
| 38 | +- **`runtime`** (required): Function runtime (e.g., `Python3.10` or `Custom Image`). |
| 39 | +- **`timeout`** (required): Maximum execution time (in seconds, range: 3-259200). |
| 40 | +- **`handler`** (required): Function handler (e.g., `main.handler`). |
| 41 | +- **`memory_size`** (required): Memory allocated to the function in MB (e.g., `256`). |
| 42 | + |
| 43 | +### Code Settings |
| 44 | + |
| 45 | +- **`code_path`**: Path to the folder containing the function code (relative to the repository). |
| 46 | +- **`code_type`**: Function code type. Options: `inline`, `zip`, `obs`, `jar`, `Custom-Image-Swr` (default: `"zip"`). |
| 47 | +- **`code_filename`**: Code file name (required if `code_type` is `zip`). |
| 48 | +- **`code_link`**: URL for the function code. |
| 49 | + |
| 50 | +### VPC Configuration |
| 51 | + |
| 52 | +- **`func_vpc_domain_id`**: Domain name ID for the VPC. |
| 53 | +- **`func_vpc_namespace`**: Project ID for the VPC. |
| 54 | +- **`func_vpc_vpc_name`**: VPC name. |
| 55 | +- **`func_vpc_vpc_id`**: VPC ID (required if VPC is configured). |
| 56 | +- **`func_vpc_subnet_name`**: Subnet name. |
| 57 | +- **`func_vpc_subnet_id`**: Subnet ID (required if VPC is configured). |
| 58 | +- **`func_vpc_cidr`**: Subnet mask (CIDR). |
| 59 | +- **`func_vpc_gateway`**: Gateway. |
| 60 | +- **`func_vpc_security_groups`**: Security groups (comma-separated values). |
| 61 | +- **`xrole`**: Huawei Cloud Agency name with permissions (required when configuring VPC). |
| 62 | + |
| 63 | +### Custom Image (SWR) Settings |
| 64 | + |
| 65 | +- **`dockerfile_path`**: Path to the Dockerfile for building the image (relative to the repository). |
| 66 | +- **`custom_image_enabled`**: Enables the use of Custom Image (`true`/`false`, default: `"false"`). |
| 67 | +- **`custom_image_image`**: Full image address. If left empty, it is generated using `custom_image_organization`, `custom_image_image_name`, and `custom_image_image_tag`. |
| 68 | +- **`custom_image_image_tag`**: Image tag (default: `"latest"`). |
| 69 | +- **`custom_image_organization`**: Organization to build the image. |
| 70 | +- **`custom_image_image_name`**: Image name. |
| 71 | +- **`custom_image_command`**: Command to start the container image. |
| 72 | +- **`custom_image_args`**: Command-line parameters to start the image. |
| 73 | +- **`custom_image_working_dir`**: Container working directory. |
| 74 | +- **`custom_image_uid`**: User ID for the container. |
| 75 | +- **`custom_image_gid`**: User group ID for the container. |
| 76 | + |
| 77 | +### Trigger Settings |
| 78 | + |
| 79 | +- **`trigger_enabled`**: Enables the creation of triggers for the function (`true`/`false`, default: `"false"`). |
| 80 | +- **`trigger_configs`**: Trigger configuration in JSON array format. Each object must include at least the `trigger_type_code` parameter and may include additional parameters that will be added with the prefix `--event_data.` (default: `"[]"`). |
| 81 | + |
| 82 | +### Environment Variables for Function Data |
| 83 | + |
| 84 | +The action also processes environment variables prefixed with: |
| 85 | + |
| 86 | +- **`FGE_`**: These are passed as encrypted environment variables. |
| 87 | +- **`FG_`**: These are passed as user environment variables. |
| 88 | + |
| 89 | +## Examples |
| 90 | + |
| 91 | +### Example 1: Deploy Function Using ZIP Code with VPC and Python Runtime |
| 92 | + |
| 93 | +```yaml |
| 94 | +name: Deploy FunctionGraph |
| 95 | + |
| 96 | +on: |
| 97 | + push: |
| 98 | + branches: [ main ] |
| 99 | + |
| 100 | +jobs: |
| 101 | + deploy: |
| 102 | + runs-on: ubuntu-latest |
| 103 | + env: |
| 104 | + FGE_API_KEY: ${{ secrets.FGE_API_KEY }} |
| 105 | + FG_OTHER_VAR: "example-value" |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout Repository |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Deploy Function (ZIP Code, VPC, Python) |
| 112 | + uses: Buronn/huaweicloud-functiongraph-action@v0.1.0 |
| 113 | + with: |
| 114 | + access_key_id: ${{ secrets.HW_ACCESS_KEY }} |
| 115 | + secret_access_key: ${{ secrets.HW_SECRET_KEY }} |
| 116 | + region: ${{ vars.HW_REGION }} |
| 117 | + func_name: "zip-function-vpc" |
| 118 | + package: "default" |
| 119 | + runtime: "Python3.10" |
| 120 | + timeout: 30 |
| 121 | + handler: "index.handler" |
| 122 | + memory_size: 256 |
| 123 | + code_path: "src/my-python-function" |
| 124 | + code_type: "zip" |
| 125 | + func_vpc_vpc_id: ${{ vars.HW_VPC_ID }} |
| 126 | + func_vpc_subnet_id: ${{ vars.HW_SUBNET_ID }} |
| 127 | + xrole: ${{ vars.HW_XROLE }} |
| 128 | +``` |
| 129 | +
|
| 130 | +### Example 2: Deploy Function Using a Custom Docker Image with VPC, Python Runtime, and a Cron Trigger |
| 131 | +
|
| 132 | +```yaml |
| 133 | +name: Deploy FunctionGraph |
| 134 | + |
| 135 | +on: |
| 136 | + push: |
| 137 | + branches: [ main ] |
| 138 | + |
| 139 | +jobs: |
| 140 | + deploy: |
| 141 | + runs-on: ubuntu-latest |
| 142 | + env: |
| 143 | + FGE_API_KEY: ${{ secrets.FGE_API_KEY }} |
| 144 | + FG_OTHER_VAR: "example-value" |
| 145 | + |
| 146 | + steps: |
| 147 | + - name: Checkout Repository |
| 148 | + uses: actions/checkout@v4 |
| 149 | + |
| 150 | + - name: Deploy Function (Custom Docker Image, VPC, Python) with Cron Trigger |
| 151 | + uses: Buronn/huaweicloud-functiongraph-action@v0.1.0 |
| 152 | + with: |
| 153 | + access_key_id: ${{ secrets.HW_ACCESS_KEY }} |
| 154 | + secret_access_key: ${{ secrets.HW_SECRET_KEY }} |
| 155 | + region: ${{ vars.HW_REGION }} |
| 156 | + func_name: "custom-image-function-vpc" |
| 157 | + package: "default" |
| 158 | + runtime: "Custom Image" |
| 159 | + timeout: 30 |
| 160 | + handler: "-" |
| 161 | + memory_size: 256 |
| 162 | + xrole: ${{ vars.HW_XROLE }} |
| 163 | + |
| 164 | + code_path: "src/custom-image-function" |
| 165 | + code_type: "Custom-Image-Swr" |
| 166 | + |
| 167 | + dockerfile_path: "Dockerfile" |
| 168 | + custom_image_enabled: "true" |
| 169 | + custom_image_image_name: "custom-function-image" |
| 170 | + custom_image_image_tag: "latest" |
| 171 | + custom_image_organization: "my-dev-team" |
| 172 | + |
| 173 | + func_vpc_vpc_id: ${{ vars.HW_VPC_ID }} |
| 174 | + func_vpc_subnet_id: ${{ vars.HW_SUBNET_ID }} |
| 175 | + |
| 176 | + trigger_enabled: "true" |
| 177 | + trigger_configs: '[{"trigger_type_code": "TIMER", "schedule_type": "Cron", "schedule": "0 */5 * * * *", "name": "EveryFiveMinutes"}]' |
| 178 | +``` |
| 179 | +
|
| 180 | +## Contributing |
| 181 | +
|
| 182 | +Contributions are welcome! If you'd like to contribute enhancements or bug fixes, please follow the repository guidelines and open a pull request. |
| 183 | +
|
| 184 | +## Issues |
| 185 | +
|
| 186 | +If you encounter any issues or have suggestions for improvements, please open an issue in the repository. |
| 187 | +
|
| 188 | +## License |
| 189 | +
|
| 190 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments