Skip to content

Commit 97e70ae

Browse files
authored
fix: update deploy and remove flow (#42)
* fix: update to deployment to serial flow * fix: update remove flow * chore: update version in yaml * test: update
1 parent 851588a commit 97e70ae

File tree

12 files changed

+43
-51
lines changed

12 files changed

+43
-51
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ jobs:
4343
env:
4444
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
4545
GIT_AUTHOR_NAME: slsplus
46-
GIT_AUTHOR_EMAIL: yuga.sun.bj@gmail.com
46+
GIT_AUTHOR_EMAIL: slsplus.sz@gmail.com
4747
GIT_COMMITTER_NAME: slsplus
48-
GIT_COMMITTER_EMAIL: yuga.sun.bj@gmail.com
48+
GIT_COMMITTER_EMAIL: slsplus.sz@gmail.com

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: |
3939
npm update --no-save
4040
npm update --save-dev --no-save
41-
- name: Running integration tests
41+
- name: Running tests
4242
run: npm run test
4343
env:
4444
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}

tests/integration.test.js renamed to __tests__/index.test.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
require('dotenv').config()
2-
const { generateId, getServerlessSdk } = require('./utils')
1+
const { generateId, getServerlessSdk } = require('./lib/utils')
32
const execSync = require('child_process').execSync
43
const path = require('path')
54
const axios = require('axios')
65

7-
// set enough timeout for deployment to finish
8-
jest.setTimeout(300000)
9-
10-
// the yaml file we're testing against
116
const instanceYaml = {
127
org: 'orgDemo',
138
app: 'appDemo',
14-
component: 'koa',
9+
component: 'koa@dev',
1510
name: `koa-integration-tests-${generateId()}`,
1611
stage: 'dev',
1712
inputs: {
@@ -21,7 +16,6 @@ const instanceYaml = {
2116
}
2217
}
2318

24-
// get credentials from process.env
2519
const credentials = {
2620
tencent: {
2721
SecretId: process.env.TENCENT_SECRET_ID,
@@ -46,15 +40,14 @@ it('should successfully deploy koa app', async () => {
4640
})
4741

4842
it('should successfully update source code', async () => {
49-
// change source to own source './src' and need to install packages before deploy
50-
const srcPath = path.join(__dirname, 'src')
43+
const srcPath = path.join(__dirname, '..', 'example')
5144
execSync('npm install', { cwd: srcPath })
5245
instanceYaml.inputs.src = srcPath
5346

5447
const instance = await sdk.deploy(instanceYaml, credentials)
5548
const response = await axios.get(instance.outputs.apigw.url)
5649

57-
expect(response.data).toEqual('Hello World')
50+
expect(response.data).toContain('Serverless Framework')
5851
expect(instance.outputs.templateUrl).not.toBeDefined()
5952
})
6053

File renamed without changes.

docs/configure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ inputs:
8686
| functionName | 否 | | 云函数名称 |
8787
| serviceName | 否 | | API 网关服务名称, 默认创建一个新的服务名称 |
8888
| serviceId | 否 | | API 网关服务 ID,如果存在将使用这个 API 网关服务 |
89-
| entryFile | | `sls.js` | 自定义 server 的入口文件名 |
89+
| entryFile | | `sls.js` | 自定义 server 的入口文件名 |
9090
| src | 否 | `process.cwd()` | 默认为当前目录, 如果是对象, 配置参数参考 [执行目录](#执行目录) |
9191
| layers | 否 | | 云函数绑定的 layer, 配置参数参考 [层配置](#层配置) |
9292
| [functionConf](#函数配置) | 否 | | 函数配置 |

jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const { join } = require('path')
2+
require('dotenv').config({ path: join(__dirname, '.env.test') })
3+
4+
const config = {
5+
verbose: true,
6+
silent: false,
7+
testTimeout: 600000,
8+
testEnvironment: 'node',
9+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$',
10+
testPathIgnorePatterns: ['/node_modules/', '/__tests__/lib/'],
11+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
12+
}
13+
14+
module.exports = config

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"access": "public"
66
},
77
"scripts": {
8-
"test": "jest ./tests/integration.test.js --testEnvironment node",
8+
"test": "jest",
99
"commitlint": "commitlint -f HEAD@{15}",
1010
"lint": "eslint --ext .js,.ts,.tsx .",
1111
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: koa
2-
version: 0.2.0
2+
version: 0.2.1
33
author: 'Tencent Cloud, Inc.'
44
org: 'Tencent Cloud, Inc.'
55
description: Deploy a serverless Koa.js application onto Tencent SCF and API Gateway.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"download": "^8.0.0",
4-
"tencent-component-toolkit": "^1.16.8",
4+
"tencent-component-toolkit": "^1.19.8",
55
"type": "^2.1.0"
66
}
77
}

src/serverless.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,33 @@ class ServerlessComponent extends Component {
184184
outputs.templateUrl = CONFIGS.templateUrl
185185
}
186186

187-
const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
187+
let apigwOutputs
188+
const functionOutputs = await this.deployFunction(
189+
credentials,
190+
functionConf,
191+
regionList,
192+
outputs
193+
)
188194
// support apigatewayConf.isDisabled
189195
if (apigatewayConf.isDisabled !== true) {
190-
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
196+
apigwOutputs = await this.deployApigateway(credentials, apigatewayConf, regionList, outputs)
191197
} else {
192198
this.state.apigwDisabled = true
193199
}
194-
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)
195200

196201
// optimize outputs for one region
197202
if (regionList.length === 1) {
198203
const [oneRegion] = regionList
199204
outputs.region = oneRegion
200-
outputs['apigw'] = apigwOutputs[oneRegion]
201205
outputs['scf'] = functionOutputs[oneRegion]
206+
if (apigwOutputs) {
207+
outputs['apigw'] = apigwOutputs[oneRegion]
208+
}
202209
} else {
203-
outputs['apigw'] = apigwOutputs
204210
outputs['scf'] = functionOutputs
211+
if (apigwOutputs) {
212+
outputs['apigw'] = apigwOutputs
213+
}
205214
}
206215

207216
this.state.region = regionList[0]
@@ -226,10 +235,6 @@ class ServerlessComponent extends Component {
226235
const scf = new Scf(credentials, curRegion)
227236
const apigw = new Apigw(credentials, curRegion)
228237
const handler = async () => {
229-
await scf.remove({
230-
functionName: curState.functionName,
231-
namespace: curState.namespace
232-
})
233238
// if disable apigw, no need to remove
234239
if (state.apigwDisabled !== true) {
235240
await apigw.remove({
@@ -240,6 +245,10 @@ class ServerlessComponent extends Component {
240245
customDomains: curState.customDomains
241246
})
242247
}
248+
await scf.remove({
249+
functionName: curState.functionName,
250+
namespace: curState.namespace
251+
})
243252
}
244253
removeHandlers.push(handler())
245254
}

0 commit comments

Comments
 (0)