Skip to content

Commit

Permalink
feat: add input types check
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed Aug 13, 2020
1 parent 887cf1d commit 7871c53
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 32 deletions.
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ install:
jobs:
include:
# Define the release stage that runs semantic-release
- stage: release
node_js: 10.18
# Advanced: optionally overwrite your default `script` step to skip the tests
# script: skip
deploy:
provider: script
skip_cleanup: true
script:
- npm run release
# - stage: release
# node_js: 10.18
# # Advanced: optionally overwrite your default `script` step to skip the tests
# # script: skip
# deploy:
# provider: script
# skip_cleanup: true
# script:
# - npm run release
7 changes: 1 addition & 6 deletions example/serverless.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
org: orgDemo
app: appDemo
stage: dev
component: scf
name: scfDemo
name: scfdemo

inputs:
src: ./src
Expand All @@ -11,12 +8,10 @@ inputs:
handler: index.main_handler
events:
- apigw:
name: serverless_api
parameters:
protocols:
- http
- https
description: The service of Serverless Framework
environment: release
endpoints:
- path: /
Expand Down
214 changes: 214 additions & 0 deletions serverless.component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,217 @@ readme: https://github.com/serverless-components/tencent-scf/tree/master/README.
license: MIT
main: ./src
webDeployable: true

actions:
deploy:
definition: Deploy your Express.js application to Tencent SCF
inputs:
src:
type: src
required: true
description: The folder containing the source code of your Express.js application.
name:
type: string
description: The name of Tencent SCF function.
regex: '^[a-z][a-z0-9\-]{0,61}[A-Za-z0-9]$'
handler:
type: string
default: 'index.main_handler'
description: The handler of Tencent SCF function.
runtime:
type: string
description: SCF runtime
default: Nodejs10.15
allow: # The values that are allowed for this
- Python2.7
- Python3.6
- Nodejs6.10
- Nodejs8.9
- Nodejs10.15
- Nodejs12.16
- Php5
- Php7
- Go1
- Java8
region:
type: string
default: ap-guangzhou
description: Region for SCF deployed to
allow: # The values that are allowed for this
- ap-guangzhou
- ap-shanghai
- ap-hongkong
- ap-beijing
- ap-chengdu
- ap-tokyo
- ap-mumbai
- ap-singapore
- na-siliconvalley
- na-toronto
memorySize:
type: number
description: SCF memory size
default: 128 # The default value
min: 64 # Minimum number allowed
max: 3072 # Maximum number allowed
allow: # The values that are allowed for this
- 64
- 128
- 256
- 384
- 512
- 640
- 768
- 896
- 1024
- 1152
- 1280
- 1408
- 1536
- 1664
- 1792
- 1920
- 2048
- 2176
- 2304
- 2432
- 2560
- 2688
- 2816
- 2944
- 3072
environment:
type: object
description: SCF environment
keys:
variables:
type: object
vpcConfig:
type: object
keys:
vpcId:
type: string
subnetId:
type: string
events:
type: array
items:
- type: object
keys:
timer:
type: object
keys:
parameters:
type: object
keys:
enable:
type: boolean
default: true
cronExpression:
type: string
argument:
type: string
apigw:
type: object
keys:
parameters:
type: object
keys:
protocols:
type: array
items:
- type: string
allow:
- http
- https
netTypes:
type: array
default:
- OUTER
items:
- type: string
allow:
- OUTER
- INNER
description:
type: string
environment:
type: string
allow:
- release
- test
- prepub
endpoints:
type: array
items:
- type: object
keys:
path:
type: string
method:
type: string
enableCORS:
type: boolean
serviceId:
type: string
serviceName:
type: string
regex: '^[a-zA-Z][a-zA-Z0-9(_)]{0,48}[a-zA-Z0-9]?$'
cos:
type: object
keys:
enable:
type: boolean
default: true
bucket:
type: string
filter:
prefix:
type: string
suffix:
type: string
events:
type: string
allow:
- 'cos:ObjectCreated:*'
- 'cos:ObjectCreated:Put'
- 'cos:ObjectCreated:Post'
- 'cos:ObjectCreated:Copy'
- 'cos:ObjectCreated:CompleteMultipartUpload'
- 'cos:ObjectCreated:Origin'
- 'cos:ObjectCreated:Replication'
- 'cos:ObjectRemove:*'
- 'cos:ObjectRemove:Delete'
- 'cos:ObjectRemove:DeleteMarkerCreated'
- 'cos:ObjectRestore:Post'
- 'cos:ObjectRestore:Completed'
ckafka:
type: object
keys:
enable:
type: boolean
default: true
name:
type: string
topic:
type: string
maxMsgNum:
type: number
min: 1
max: 10000
offset:
type: string
allow:
- latest
- earliest
- timestamp
cmq:
type: object
keys:
enable:
type: boolean
default: true
name:
type: string
remove:
definition: Remove your Express.js application
38 changes: 35 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
const LANGS = ['Nodejs', 'Python', 'Go', 'Php', 'Java']
const getLang = (runtime) => {
for (let i = 0; i < LANGS.length; i++) {
if (runtime.indexOf(LANGS[i]) === 0) {
return LANGS[i]
}
}
return 'Nodejs'
}

const CONFIGS = {
templateUrl: 'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/scf-demo.zip',
region: 'ap-guangzhou',
compName: 'scf',
componentFullname: 'SCF',
compFullname: 'SCF',
runtime: 'Nodejs10.15',
handler: 'index.main_handler',
description: 'Created by Serverless Component',
handler(runtime) {
let handler = 'index.main_handler'
const lang = getLang(runtime)
switch (lang) {
case 'Nodejs':
case 'Php':
case 'Python':
handler = 'index.main_handler'
break
case 'Go':
handler = 'main'
break
case 'Java':
handler = 'example.Hello::mainHandler'
break
default:
break
}
return handler
},
description(app) {
return `This is a function in ${app} application`
},
triggerTypes: ['apigw', 'cos', 'timer', 'cmq', 'ckafka'],
defaultApigw: {
name: `serverless_api`,
parameters: {
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"download": "^8.0.0",
"tencent-component-toolkit": "^1.13.2",
"tencent-component-toolkit": "^1.14.4",
"type": "^2.0.0"
}
}
8 changes: 4 additions & 4 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ServerlessComponent extends Component {
}

async deploy(inputs) {
console.log(`Deploying Tencent ${CONFIGS.componentFullname}...`)
console.log(`Deploying Tencent ${CONFIGS.compFullname}...`)

const credentials = this.getCredentials()
const appId = this.getAppId()
Expand Down Expand Up @@ -115,7 +115,7 @@ class ServerlessComponent extends Component {

await this.save()

console.log(`Deployed Tencent ${CONFIGS.componentFullname}...`)
console.log(`Deployed Tencent ${CONFIGS.compFullname}...`)

return outputs
}
Expand All @@ -126,13 +126,13 @@ class ServerlessComponent extends Component {
const { region } = this.state
const functionInfo = this.state.function

console.log(`Removing Tencent ${CONFIGS.componentFullname}...`)
console.log(`Removing Tencent ${CONFIGS.compFullname}...`)
const scf = new Scf(credentials, region)
if (functionInfo && functionInfo.FunctionName) {
await scf.remove(functionInfo)
}
this.state = {}
console.log(`Removed Tencent ${CONFIGS.componentFullname}`)
console.log(`Removed Tencent ${CONFIGS.compFullname}`)
}
}

Expand Down
Loading

0 comments on commit 7871c53

Please sign in to comment.