Skip to content

Commit c294193

Browse files
committed
first commit
0 parents  commit c294193

File tree

7 files changed

+800
-0
lines changed

7 files changed

+800
-0
lines changed

.github/workflows/example_usage.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Deploy FunctionGraph
2+
3+
on:
4+
push:
5+
branches: [ none ]
6+
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
env:
11+
FGE_API_KEY: ${{ secrets.FGE_API_KEY }}
12+
FG_OTHER_VAR: "example-value"
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Deploy Function (ZIP Code, VPC, Python)
19+
uses: Buronn/huaweicloud-functiongraph-action@v0.1.0
20+
with:
21+
access_key_id: ${{ secrets.HW_ACCESS_KEY }}
22+
secret_access_key: ${{ secrets.HW_SECRET_KEY }}
23+
region: ${{ vars.HW_REGION }}
24+
func_name: "zip-function-vpc"
25+
package: "default"
26+
runtime: "Python3.10"
27+
timeout: 30
28+
handler: "index.handler"
29+
memory_size: 256
30+
code_path: "src/my-python-function"
31+
code_type: "zip"
32+
func_vpc_vpc_id: ${{ vars.HW_VPC_ID }}
33+
func_vpc_subnet_id: ${{ vars.HW_SUBNET_ID }}
34+
xrole: ${{ vars.HW_XROLE }}
35+
36+
- name: Deploy Function (Custom Docker Image, VPC, Python) with Cron Trigger
37+
uses: Buronn/huaweicloud-functiongraph-action@v0.1.0
38+
with:
39+
access_key_id: ${{ secrets.HW_ACCESS_KEY }}
40+
secret_access_key: ${{ secrets.HW_SECRET_KEY }}
41+
region: ${{ vars.HW_REGION }}
42+
func_name: "custom-image-function-vpc"
43+
package: "default"
44+
runtime: "Custom Image"
45+
timeout: 30
46+
handler: "-"
47+
memory_size: 256
48+
xrole: ${{ vars.HW_XROLE }}
49+
50+
code_path: "src/custom-image-function"
51+
code_type: "Custom-Image-Swr"
52+
53+
dockerfile_path: "Dockerfile"
54+
custom_image_enabled: "true"
55+
custom_image_image_name: "custom-function-image"
56+
custom_image_image_tag: "latest"
57+
custom_image_organization: "my-dev-team"
58+
59+
func_vpc_vpc_id: ${{ vars.HW_VPC_ID }}
60+
func_vpc_subnet_id: ${{ vars.HW_SUBNET_ID }}
61+
62+
trigger_enabled: "true"
63+
trigger_configs: '[{"trigger_type_code": "TIMER", "schedule_type": "Cron", "schedule": "0 */5 * * * *", "name": "EveryFiveMinutes"}]'

Dockerfile.example

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM python:3.7-slim
2+
3+
ENV HOME=/home/custom_container
4+
ENV GROUP_ID=1003
5+
ENV GROUP_NAME=custom_container
6+
ENV USER_ID=1003
7+
ENV USER_NAME=custom_container
8+
9+
RUN mkdir -m 550 ${HOME} && \
10+
groupadd -g ${GROUP_ID} ${GROUP_NAME} && \
11+
useradd -u ${USER_ID} -g ${GROUP_ID} ${USER_NAME}
12+
13+
WORKDIR ${HOME}
14+
15+
COPY --chown=${USER_ID}:${GROUP_ID} ./example-app/requirements.txt ${HOME}/requirements.txt
16+
COPY --chown=${USER_ID}:${GROUP_ID} ./example-app/ ${HOME}/
17+
18+
RUN pip install --no-cache-dir -r requirements.txt
19+
20+
RUN chown -R ${USER_ID}:${GROUP_ID} ${HOME} && \
21+
find ${HOME} -type d -exec chmod 500 {} \; && \
22+
find ${HOME} -type f -exec chmod 500 {} \;
23+
24+
USER ${USER_NAME}
25+
26+
EXPOSE 8000
27+
28+
ENTRYPOINT python3 ${HOME}/index.py

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 fburon
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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

Comments
 (0)