Skip to content

Commit

Permalink
feat: optimize deploy flow and update deps (#16)
Browse files Browse the repository at this point in the history
* feat: optimize deploy flow and update deps

* chore: update dev deps

* chore: fix test

* ci: add env
  • Loading branch information
yugasun authored Mar 19, 2021
1 parent ab7baa6 commit 8b74d8c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ jobs:
env:
SERVERLESS_PLATFORM_VENDOR: tencent
GLOBAL_ACCELERATOR_NA: true
TENCENT_APP_ID: ${{ secrets.TENCENT_APP_ID }}
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}
2 changes: 1 addition & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const credentials = {
}

// get serverless construct sdk
const sdk = getServerlessSdk(instanceYaml.org)
const sdk = getServerlessSdk(instanceYaml.org, process.env.TENCENT_APP_ID)

it('should deploy success', async () => {
const instance = await sdk.deploy(instanceYaml, credentials)
Expand Down
3 changes: 2 additions & 1 deletion __tests__/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const generateId = () =>
* Initializes and returns an instance of the serverless sdk
* @param ${string} orgName - the serverless org name.
*/
const getServerlessSdk = (orgName) => {
const getServerlessSdk = (orgName, orgUid) => {
const sdk = new ServerlessSDK({
context: {
orgUid,
orgName
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/release-notes-generator": "^9.0.1",
"@serverless/platform-client-china": "^2.0.7",
"@serverless/platform-client-china": "^2.1.9",
"@ygkit/secure": "^0.0.3",
"babel-eslint": "^10.1.0",
"dotenv": "^8.2.0",
Expand Down
2 changes: 1 addition & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: websocket
version: 0.4.1
version: 0.5.0
author: Tencent Cloud, Inc.
org: Tencent Cloud, Inc.
description: Deploys websocket service on Tencent Cloud.
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"dependencies": {
"@slsplus/migrate": "^0.0.1-beta-4",
"download": "^8.0.0",
"tencent-component-toolkit": "^1.19.8"
"tencent-component-toolkit": "^2.5.2"
}
}
40 changes: 4 additions & 36 deletions src/serverless.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { Component } = require('@serverless/core')
const { Scf, Apigw, Cns } = require('tencent-component-toolkit')
const { TypeError } = require('tencent-component-toolkit/src/utils/error')
const { Scf, Apigw } = require('tencent-component-toolkit')
const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error')
const { migrateFramework } = require('@slsplus/migrate')
const { uploadCodeToCos, getDefaultProtocol, initializeInputs, deepClone } = require('./utils')
const initConfigs = require('./config')
Expand All @@ -10,7 +10,7 @@ class ServerlessComponent extends Component {
const { tmpSecrets } = this.credentials.tencent

if (!tmpSecrets || !tmpSecrets.TmpSecretId) {
throw new TypeError(
throw new ApiTypeError(
'CREDENTIAL',
'Cannot get secretId/Key, your account could be sub-account and does not have the access to use SLS_QcsRole, please make sure the role exists first, then visit https://cloud.tencent.com/document/product/1154/43006, follow the instructions to bind the role to your account.'
)
Expand Down Expand Up @@ -81,34 +81,6 @@ class ServerlessComponent extends Component {
return faasOutputs
}

// try to add dns record
async tryToAddDnsRecord(credentials, customDomains) {
try {
const cns = new Cns(credentials)
for (let i = 0; i < customDomains.length; i++) {
const item = customDomains[i]
if (item.domainPrefix) {
await cns.deploy({
domain: item.subDomain.replace(`${item.domainPrefix}.`, ''),
records: [
{
subDomain: item.domainPrefix,
recordType: 'CNAME',
recordLine: '默认',
value: item.cname,
ttl: 600,
mx: 10,
status: 'enable'
}
]
})
}
}
} catch (e) {
console.log('METHOD_tryToAddDnsRecord', e.message)
}
}

async deployApigw(credentials, inputs) {
if (inputs.isDisabled) {
return {}
Expand Down Expand Up @@ -147,10 +119,6 @@ class ServerlessComponent extends Component {
}

if (apigwOutput.customDomains) {
// TODO: need confirm add cns authentication
if (inputs.autoAddDnsRecord === true) {
// await this.tryToAddDnsRecord(credentials, apigwOutput.customDomains)
}
outputs.customDomains = apigwOutput.customDomains
}
return outputs
Expand All @@ -171,7 +139,7 @@ class ServerlessComponent extends Component {
inputs.environment.variables.wsBackUrl = wsBackUrl

const scf = new Scf(credentials, inputs.region)
await scf.updatefunctionConfigure(inputs)
await scf.scf.updateConfigure(inputs)

console.log(`Add wsBackUrl environment variable for function ${inputs.name} successfully`)
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const fs = require('fs')
const { Cos } = require('tencent-component-toolkit')
const download = require('download')
const { TypeError } = require('tencent-component-toolkit/src/utils/error')
const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error')

/*
* Generates a random id
Expand Down Expand Up @@ -79,7 +79,7 @@ const getCodeZipPath = async (instance, inputs) => {
filename: `${filename}.zip`
})
} catch (e) {
throw new TypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.')
throw new ApiTypeError(`DOWNLOAD_TEMPLATE`, 'Download default template failed.')
}
zipPath = `${downloadPath}/${filename}.zip`
} else {
Expand Down

0 comments on commit 8b74d8c

Please sign in to comment.