Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tencent provider create-template #6898

Merged
merged 7 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/plugins/create/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 49 additions & 0 deletions lib/plugins/create/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
10 changes: 10 additions & 0 deletions lib/plugins/create/templates/tencent-go/Makefile
Original file line number Diff line number Diff line change
@@ -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 .
18 changes: 18 additions & 0 deletions lib/plugins/create/templates/tencent-go/gitignore
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions lib/plugins/create/templates/tencent-go/index.go
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 14 additions & 0 deletions lib/plugins/create/templates/tencent-go/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
87 changes: 87 additions & 0 deletions lib/plugins/create/templates/tencent-go/serverless.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/plugins/create/templates/tencent-nodejs/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
6 changes: 6 additions & 0 deletions lib/plugins/create/templates/tencent-nodejs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

exports.main_handler = (event, context, callback) => {
console.log('%j', event);
callback(null, 'Hello World');
};
14 changes: 14 additions & 0 deletions lib/plugins/create/templates/tencent-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
89 changes: 89 additions & 0 deletions lib/plugins/create/templates/tencent-nodejs/serverless.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/plugins/create/templates/tencent-php/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
9 changes: 9 additions & 0 deletions lib/plugins/create/templates/tencent-php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php


function main_handler($event, $context) {
var_dump($event);
return "hello world";
}

?>
14 changes: 14 additions & 0 deletions lib/plugins/create/templates/tencent-php/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}