Skip to content

Commit d98c44d

Browse files
santihongSquatsTonight
authored andcommitted
Init project
1 parent e2651e8 commit d98c44d

File tree

14 files changed

+5347
-1
lines changed

14 files changed

+5347
-1
lines changed

.github/workflows/check.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Check
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
check-node:
11+
name: Build nodejs demo function
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Initializing Serverless-Devs
18+
uses: git-qfzhang/Serverless-Devs-Initialization-Action@main
19+
with:
20+
provider: alibaba
21+
access_key_id: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
22+
access_key_secret: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
23+
account_id: ${{ secrets.ALIYUN_ACCOUNT_ID }}
24+
25+
- name: Building
26+
uses: ./
27+
with:
28+
working_directory: ./test
29+
projects: ServerlessDevsNode10
30+
31+
- name: Checking
32+
run: |
33+
sudo apt-get install tree
34+
sudo tree ./test/fc-nodejs10/node_modules -L 1
35+
36+
check-all:
37+
name: Build nodejs and java demo function
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v2
42+
43+
- name: Initializing Serverless-Devs
44+
uses: git-qfzhang/Serverless-Devs-Initialization-Action@main
45+
with:
46+
provider: alibaba
47+
access_key_id: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
48+
access_key_secret: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
49+
account_id: ${{ secrets.ALIYUN_ACCOUNT_ID }}
50+
51+
- name: Building
52+
uses: ./
53+
with:
54+
working_directory: ./test
55+
projects: 'ServerlessDevsNode10 ServerlessDevsJava8'
56+
57+
- name: Checking
58+
run: |
59+
sudo apt-get install tree
60+
sudo tree ./test/fc-nodejs10/node_modules -L 1
61+
sudo tree ./test/.fc/build -L 1

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
.s

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) 2020 git-qfzhang
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: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,107 @@
1-
# serverless-devs-fc-action
1+
![GitHub Actions status](https://github.com/git-qfzhang/Serverless-Devs-Initialization-Actinos/workflows/Check/badge.svg)
2+
[![License](https://img.shields.io/github/license/git-qfzhang/Serverless-Devs-Initialization-Actinos.svg)](https://github.com/git-qfzhang/Serverless-Devs-Initialization-Actinos/blob/master/LICENSE)
3+
4+
# Alibaba Function Computer Build Action For Github Actions
5+
6+
Github action for building artifacts for compiled language runtime or installing dependencies for interpreted language runtime.
7+
8+
<!-- toc -->
9+
10+
- [Usage](#usage)
11+
- [Input variables](#credentials)
12+
- [License Summary](#license-summary)
13+
14+
<!-- tocstop -->
15+
16+
## Usage
17+
18+
Currently, [Alibaba Fcuntion Computer](https://help.aliyun.com/document_detail/74712.html?spm=a2c4g.11174283.6.563.20685212c2S6QB) supports the following programming languages:
19+
20+
| Language | Type |
21+
| ---- | ---- |
22+
| Nodejs | Interpreted |
23+
| Python | Interpreted |
24+
| PHP | Interpreted |
25+
| Java | Compiled |
26+
| C# | Compiled |
27+
28+
If you want to build the target [projects]((https://github.com/Serverless-Devs/docs/blob/master/docs/en/tool/yaml_format.md)), you should input these projects seperated by space to `projects` varibale as follows:
29+
30+
```yaml
31+
name: Check
32+
33+
on:
34+
push:
35+
branches: [main]
36+
pull_request:
37+
branches: [main]
38+
39+
jobs:
40+
build:
41+
name: Build target projects
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
47+
- name: Initializing Serverless-Devs
48+
uses: git-qfzhang/Serverless-Devs-Initialization-Action@main
49+
with:
50+
provider: alibaba
51+
access_key_id: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
52+
access_key_secret: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
53+
account_id: ${{ secrets.ALIYUN_ACCOUNT_ID }}
54+
55+
- name: Building
56+
uses: git-qfzhang/alibaba-fc-build-action@main
57+
with:
58+
working_directory: ./test
59+
projects: 'ServerlessDevsNode10 ServerlessDevsJava8'
60+
```
61+
62+
You should ignore `projects` variable or input `*` to `projects` varibale when building all projects:
63+
64+
```yaml
65+
name: Check
66+
67+
on:
68+
push:
69+
branches: [main]
70+
pull_request:
71+
branches: [main]
72+
73+
jobs:
74+
build:
75+
name: Build all projects
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout
79+
uses: actions/checkout@v2
80+
81+
- name: Initializing Serverless-Devs
82+
uses: git-qfzhang/Serverless-Devs-Initialization-Action@main
83+
with:
84+
provider: alibaba
85+
access_key_id: ${{ secrets.ALIYUN_ACCESS_KEY_ID }}
86+
access_key_secret: ${{ secrets.ALIYUN_ACCESS_KEY_SECRET }}
87+
account_id: ${{ secrets.ALIYUN_ACCOUNT_ID }}
88+
89+
- name: Building
90+
uses: git-qfzhang/alibaba-fc-build-action@main
91+
with:
92+
working_directory: ./test
93+
```
94+
95+
`git-qfzhang/Serverless-Devs-Initialization-Action` is the precondition of the building action, more information can refer to [here](https://github.com/git-qfzhang/Serverless-Devs-Initialization-Action/blob/main/README.md).
96+
97+
## Input variables
98+
99+
See [action.yml](action.yml) for the full documentation for this action's inputs.
100+
101+
* working_directory - the directory containing template.yml/template.yaml which could refer to [here](https://github.com/Serverless-Devs-Awesome/fc-alibaba-component/).
102+
103+
* projects - target projects which are delimited by space. The default * represents all projects.
104+
105+
## License Summary
106+
107+
This code is made available under the MIT license.

action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will build functions of Aliyun Function Compute locally.
2+
#
3+
# This workflow assumes you have already created the project using fc-alibaba-component of Serverless-Devs.
4+
5+
name: 'Build Aliyun FC Function Locally Using Serverless-Devs'
6+
description: 'Build Aliyun FC Function'
7+
8+
inputs:
9+
working_directory:
10+
description: 'Directory containing template.yml'
11+
required: false
12+
default: './'
13+
projects:
14+
description: 'Target projects which are delimited by space. The default * represents all projects'
15+
required: false
16+
default: '*'
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: chmod +x
22+
run: sudo chmod +x ${{ github.action_path }}/dev/build.sh
23+
shell: bash
24+
25+
- name: build/install
26+
run: ${{ github.action_path }}/dev/build.sh
27+
shell: bash
28+
env:
29+
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
30+
INPUT_PROJECTS: ${{ inputs.projects }}

dev/build.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/bash
2+
set -e
3+
4+
COMPILED_LANGUAGE_LIST=('java' 'dotnetcore')
5+
INTERPRETED_LANGUAGE_LIST=('nodejs' 'python' 'php')
6+
7+
function parse_yaml {
8+
local prefix=$2
9+
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
10+
sed -ne "s|^\($s\):|\1|" \
11+
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
12+
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
13+
awk -F$fs '{
14+
indent = length($1)/2;
15+
vname[indent] = $2;
16+
for (i in vname) {if (i > indent) {delete vname[i]}}
17+
if (length($3) > 0) {
18+
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
19+
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
20+
}
21+
}'
22+
}
23+
24+
# Parse template.yml file
25+
template_file_path=""
26+
if test -f "$INPUT_WORKING_DIRECTORY"/template.yml; then
27+
template_file_path="$INPUT_WORKING_DIRECTORY"/template.yml
28+
elif test -f "$INPUT_WORKING_DIRECTORY"/template.yaml; then
29+
template_file_path="$INPUT_WORKING_DIRECTORY"/template.yaml
30+
else
31+
echo "template.yml/template.yaml file dose not exists in $INPUT_WORKING_DIRECTORY."
32+
exit 1
33+
fi
34+
35+
parsed_yml=$(parse_yaml "$template_file_path")
36+
37+
# Generate target projects
38+
declare -a projects_list
39+
if [ "$INPUT_PROJECTS" == "*" ]; then
40+
projects_list=( $( echo "$parsed_yml" | grep "Component" | sed 's/_Component=".*"//g' ) )
41+
else
42+
projects_list=( $INPUT_PROJECTS )
43+
fi
44+
45+
# build/install for every project
46+
for project in "${projects_list[@]}"
47+
do
48+
runtime=$( echo "$parsed_yml" | grep "$project" | grep "Runtime" | sed 's/'$project'_.*_Runtime=//g; s/\"//g' )
49+
runtime_prefix=$( echo "$runtime" | sed 's/[0-9]\+\(.[0-9]\+\)*//g' )
50+
echo "runtime_prefix: $runtime_prefix"
51+
code_uri=$( echo "$parsed_yml" | grep "$project" | grep "CodeUri" | sed 's/'$project'_.*CodeUri=//g; s/\"//g' )
52+
53+
if [[ $COMPILED_LANGUAGE_LIST =~ (^|[[:space:]])$runtime_prefix($|[[:space:]]) ]]; then
54+
echo "Building artifacts for project $project with compiled runtime: $runtime..."
55+
( cd "$INPUT_WORKING_DIRECTORY" && sudo s "$project" build docker )
56+
elif [[ $INTERPRETED_LANGUAGE_LIST =~ (^|[[:space:]])$runtime_prefix($|[[:space:]]) ]]; then
57+
echo "Installing dependencies for project $project with interpreted runtime: $runtime..."
58+
( cd "$INPUT_WORKING_DIRECTORY" && sudo s "$project" install docker )
59+
else
60+
echo "Unsupported runtime: $runtime"
61+
exit 1
62+
fi
63+
done

test/fc-java8/.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.idea/
3+
*.iml
4+
lib/
5+
target/
6+
.settings/
7+
.project
8+
.classpath
9+
bin/

test/fc-java8/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>example</groupId>
5+
<artifactId>fc-java8</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>fc-java8</name>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>junit</groupId>
13+
<artifactId>junit</artifactId>
14+
<version>3.8.1</version>
15+
<scope>test</scope>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.aliyun.fc.runtime</groupId>
19+
<artifactId>fc-java-core</artifactId>
20+
<version>1.3.0</version>
21+
</dependency>
22+
</dependencies>
23+
24+
<properties>
25+
<maven.compiler.target>1.8</maven.compiler.target>
26+
<maven.compiler.source>1.8</maven.compiler.source>
27+
<maven.test.skip>true</maven.test.skip>
28+
</properties>
29+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package example;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.OutputStream;
6+
7+
import com.aliyun.fc.runtime.Context;
8+
import com.aliyun.fc.runtime.StreamRequestHandler;
9+
import com.aliyun.fc.runtime.FunctionInitializer;
10+
11+
/**
12+
* Hello world!
13+
*
14+
*/
15+
public class App implements StreamRequestHandler, FunctionInitializer {
16+
17+
public void initialize(Context context) throws IOException {
18+
//TODO
19+
}
20+
21+
@Override
22+
public void handleRequest(
23+
InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
24+
outputStream.write(new String("hello world\n").getBytes());
25+
}
26+
}

test/fc-nodejs10/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const moment = require('moment-timezone');
2+
3+
module.exports.handler = function(req, resp, context) {
4+
let tz = "Asia/Shanghai";
5+
6+
console.log(`clientIP: ${req.clientIP}`);
7+
console.log(`requestURI: ${req.url}`);
8+
9+
resp.setHeader('content-type', 'application/json');
10+
11+
if(req.queries && req.queries.tz) {
12+
tz = req.queries.tz;
13+
14+
if(!moment.tz.names().includes(tz)) {
15+
console.error(`Unknown timezone ${tz}`);
16+
17+
resp.send(JSON.stringify({
18+
statusCode: 400,
19+
message: `Unknown timezone ${tz}.`,
20+
timezones: moment.tz.names()
21+
}, null, ' '));
22+
return;
23+
}
24+
25+
console.log(`timezone: ${tz}`);
26+
}
27+
28+
resp.send(JSON.stringify({
29+
statusCode: 200,
30+
message: `The time in ${tz} is: ${moment.tz(tz).format()}`
31+
}, null, ' '));
32+
}

0 commit comments

Comments
 (0)