Merge pull request #6898 from serverless-tencent/add-tencent

Add tencent provider create-template
This commit is contained in:
Mariusz Nowak 2019-10-29 10:41:47 -05:00 committed by GitHub
commit 593ef909b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 558 additions and 0 deletions

View File

@ -61,6 +61,10 @@ const validTemplates = [
'spotinst-java8',
'twilio-nodejs',
'aliyun-nodejs',
'tencent-go',
'tencent-nodejs',
'tencent-python',
'tencent-php',
'plugin',
// this template is used to streamline the onboarding process

View File

@ -800,6 +800,55 @@ describe('Create', () => {
});
});
it('should generate scaffolding for "tencent-go" template', () => {
process.chdir(tmpDir);
create.options.template = 'tencent-go';
return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('index.go');
expect(dirContent).to.include('Makefile');
expect(dirContent).to.include('.gitignore');
});
});
it('should generate scaffolding for "tencent-php" template', () => {
process.chdir(tmpDir);
create.options.template = 'tencent-php';
return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('index.php');
expect(dirContent).to.include('.gitignore');
});
});
it('should generate scaffolding for "tencent-python" template', () => {
process.chdir(tmpDir);
create.options.template = 'tencent-python';
return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('index.py');
expect(dirContent).to.include('.gitignore');
});
});
it('should generate scaffolding for "tencent-nodejs" template', () => {
process.chdir(tmpDir);
create.options.template = 'tencent-nodejs';
return create.create().then(() => {
const dirContent = fs.readdirSync(tmpDir);
expect(dirContent).to.include('serverless.yml');
expect(dirContent).to.include('index.js');
expect(dirContent).to.include('.gitignore');
});
});
it('should generate scaffolding for "plugin" template', () => {
process.chdir(tmpDir);
create.options.template = 'plugin';

View File

@ -0,0 +1,10 @@
.PHONY: all deps clean build
all: deps clean build
deps:
go get github.com/tencentyun/scf-go-lib/cloudfunction
clean:
rm -rf ./index
build:
GOOS=linux GOARCH=amd64 go build -o ./index .

View File

@ -0,0 +1,18 @@
# Serverless directories
.serverless
# golang output binary directory
bin
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

View File

@ -0,0 +1,22 @@
package main
import (
"context"
"fmt"
"github.com/tencentyun/scf-go-lib/cloudfunction"
)
type DefineEvent struct {
Key1 string `json:"key1"`
Key2 string `json:"key2"`
}
func hello(ctx context.Context, event DefineEvent) (string, error) {
fmt.Println("key1:", event.Key1)
fmt.Println("key2:", event.Key2)
return fmt.Sprintf("Hello World"), nil
}
func main() {
cloudfunction.Start(hello)
}

View File

@ -0,0 +1,14 @@
{
"name": "tencent-golang",
"version": "1.0.0",
"description": "Tencent Serverless Cloud Function example using Golang",
"main": "index.go",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "cloud.tencent.com",
"license": "MIT",
"devDependencies": {
"serverless-tencent-scf": "^0.1.7"
}
}

View File

@ -0,0 +1,87 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: my-service # service name
provider: # provider information
name: tencent
runtime: Go1
credentials: ~/credentials
# you can overwrite defaults here
# stage: dev
# cosBucket: DEFAULT
# role: QCS_SCFExcuteRole
# memorySize: 256
# timeout: 10
# region: ap-shanghai
# environment:
# variables:
# ENV_FIRST: env1
# ENV_SECOND: env2
plugins:
- serverless-tencent-scf
# you can add packaging information here
#package:
# exclude:
# - ./**
# include:
# - ./bin/**
functions:
function_one:
handler: main
# description: Tencent Serverless Cloud Function
# runtime: Go1
# memorySize: 256
# timeout: 10
# environment:
# variables:
# ENV_FIRST: env1
# ENV_Third: env2
# events:
# - timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
# - cos:
# name: cli-appid.cos.ap-beijing.myqcloud.com
# parameters:
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
# filter:
# prefix: filterdir/
# suffix: .jpg
# events: cos:ObjectCreated:*
# enable: true
# - apigw:
# name: hello_world_apigw
# parameters:
# stageName: release
# serviceId:
# httpMethod: ANY
# - cmq:
# name: cmq_trigger
# parameters:
# name: test-topic-queue
# enable: true
# - ckafka:
# name: ckafka_trigger
# parameters:
# name: ckafka-2o10hua5
# topic: test
# maxMsgNum: 999
# offset: latest
# enable: true

View File

@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages
# Serverless directories
.serverless

View File

@ -0,0 +1,6 @@
'use strict';
exports.main_handler = (event, context, callback) => {
console.log('%j', event);
callback(null, 'Hello World');
};

View File

@ -0,0 +1,14 @@
{
"name": "tencent-nodejs",
"version": "1.0.0",
"description": "Tencent Serverless Cloud Function example using Nodejs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "cloud.tencent.com",
"license": "MIT",
"devDependencies": {
"serverless-tencent-scf": "^0.1.7"
}
}

View File

@ -0,0 +1,89 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: my-service # service name
provider: # provider information
name: tencent
runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
credentials: ~/credentials
# you can overwrite defaults here
# stage: dev
# cosBucket: DEFAULT
# role: QCS_SCFExcuteRole
# memorySize: 256
# timeout: 10
# region: ap-shanghai
# environment:
# variables:
# ENV_FIRST: env1
# ENV_SECOND: env2
plugins:
- serverless-tencent-scf
# you can add packaging information here
#package:
# include:
# - include-me.js
# - include-me-dir/**
# exclude:
# - exclude-me.js
# - exclude-me-dir/**
functions:
function_one:
handler: index.main_handler
# description: Tencent Serverless Cloud Function
# runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
# memorySize: 256
# timeout: 10
# environment:
# variables:
# ENV_FIRST: env1
# ENV_Third: env2
# events:
# - timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
# - cos:
# name: cli-appid.cos.ap-beijing.myqcloud.com
# parameters:
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
# filter:
# prefix: filterdir/
# suffix: .jpg
# events: cos:ObjectCreated:*
# enable: true
# - apigw:
# name: hello_world_apigw
# parameters:
# stageName: release
# serviceId:
# httpMethod: ANY
# - cmq:
# name: cmq_trigger
# parameters:
# name: test-topic-queue
# enable: true
# - ckafka:
# name: ckafka_trigger
# parameters:
# name: ckafka-2o10hua5
# topic: test
# maxMsgNum: 999
# offset: latest
# enable: true

View File

@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages
# Serverless directories
.serverless

View File

@ -0,0 +1,9 @@
<?php
function main_handler($event, $context) {
var_dump($event);
return "hello world";
}
?>

View File

@ -0,0 +1,14 @@
{
"name": "tencent-php",
"version": "1.0.0",
"description": "Tencent Serverless Cloud Function example using Php",
"main": "index.php",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "cloud.tencent.com",
"license": "MIT",
"devDependencies": {
"serverless-tencent-scf": "^0.1.7"
}
}

View File

@ -0,0 +1,80 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: my-service # service name
provider: # provider information
name: tencent
runtime: Php7 # Php7 or Php5
credentials: ~/credentials
# you can overwrite defaults here
# stage: dev
# cosBucket: DEFAULT
# role: QCS_SCFExcuteRole
# memorySize: 256
# timeout: 10
# region: ap-shanghai
# environment:
# variables:
# ENV_FIRST: env1
# ENV_SECOND: env2
plugins:
- serverless-tencent-scf
functions:
function_one_one_one:
handler: index.main_handler
# description: Tencent Serverless Cloud Function
# runtime: Php7 # Php7 or Php5
# memorySize: 256
# timeout: 10
# environment:
# variables:
# ENV_FIRST: env1
# ENV_Third: env2
# events:
# - timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
# - cos:
# name: cli-appid.cos.ap-beijing.myqcloud.com
# parameters:
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
# filter:
# prefix: filterdir/
# suffix: .jpg
# events: cos:ObjectCreated:*
# enable: true
# - apigw:
# name: hello_world_apigw
# parameters:
# stageName: release
# serviceId:
# httpMethod: ANY
# - cmq:
# name: cmq_trigger
# parameters:
# name: test-topic-queue
# enable: true
# - ckafka:
# name: ckafka_trigger
# parameters:
# name: ckafka-2o10hua5
# topic: test
# maxMsgNum: 999
# offset: latest
# enable: true

View File

@ -0,0 +1,20 @@
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Serverless directories
.serverless

View File

@ -0,0 +1,7 @@
# -*- coding: utf8 -*-
def main_handler(event, context):
print(str(event))
return "hello world"

View File

@ -0,0 +1,14 @@
{
"name": "tencent-python",
"version": "1.0.0",
"description": "Tencent Serverless Cloud Function example using Python",
"main": "index.py",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "cloud.tencent.com",
"license": "MIT",
"devDependencies": {
"serverless-tencent-scf": "^0.1.7"
}
}

View File

@ -0,0 +1,89 @@
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: my-service # service name
provider: # provider information
name: tencent
runtime: Python3.6 # Python3.6 or Python2.7
credentials: ~/credentials
# you can overwrite defaults here
# stage: dev
# cosBucket: DEFAULT
# role: QCS_SCFExcuteRole
# memorySize: 256
# timeout: 10
# region: ap-shanghai
# environment:
# variables:
# ENV_FIRST: env1
# ENV_SECOND: env2
plugins:
- serverless-tencent-scf
# you can add packaging information here
#package:
# include:
# - include-me.py
# - include-me-dir/**
# exclude:
# - exclude-me.py
# - exclude-me-dir/**
functions:
function_one:
handler: index.main_handler
# description: Tencent Serverless Cloud Function
# runtime: Python3.6 # Python3.6 or Python2.7
# memorySize: 256
# timeout: 10
# environment:
# variables:
# ENV_FIRST: env1
# ENV_Third: env2
# events:
# - timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
# - cos:
# name: cli-appid.cos.ap-beijing.myqcloud.com
# parameters:
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
# filter:
# prefix: filterdir/
# suffix: .jpg
# events: cos:ObjectCreated:*
# enable: true
# - apigw:
# name: hello_world_apigw
# parameters:
# stageName: release
# serviceId:
# httpMethod: ANY
# - cmq:
# name: cmq_trigger
# parameters:
# name: test-topic-queue
# enable: true
# - ckafka:
# name: ckafka_trigger
# parameters:
# name: ckafka-2o10hua5
# topic: test
# maxMsgNum: 999
# offset: latest
# enable: true