Skip to content

Commit 4b3c40c

Browse files
authored
fix: update deploy and remove flow (#14)
* fix: update to deployment to serial flow * fix: update remove flow
1 parent 49bc914 commit 4b3c40c

11 files changed

+182
-46
lines changed

.github/workflows/release.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
env:
12+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
with:
17+
persist-credentials: false
18+
19+
- name: Install Node.js and npm
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 14.x
23+
registry-url: https://registry.npmjs.org
24+
25+
- name: Retrieve dependencies from cache
26+
id: cacheNpm
27+
uses: actions/cache@v2
28+
with:
29+
path: |
30+
~/.npm
31+
node_modules
32+
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
33+
restore-keys: npm-v14-${{ runner.os }}-refs/heads/master-
34+
35+
- name: Install dependencies
36+
if: steps.cacheNpm.outputs.cache-hit != 'true'
37+
run: |
38+
npm update --no-save
39+
npm update --save-dev --no-save
40+
- name: Releasing
41+
run: |
42+
npm run release
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
45+
GIT_AUTHOR_NAME: slsplus
46+
GIT_AUTHOR_EMAIL: [email protected]
47+
GIT_COMMITTER_NAME: slsplus
48+
GIT_COMMITTER_EMAIL: [email protected]

.github/workflows/test.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
- name: Running tests
42+
run: npm run test
43+
env:
44+
SERVERLESS_PLATFORM_VENDOR: tencent
45+
GLOBAL_ACCELERATOR_NA: true
46+
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
47+
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

.github/workflows/validate.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Validate
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
lintAndFormatting:
9+
name: Lint & Formatting
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
42+
- name: Validate Formatting
43+
run: npm run prettier:fix
44+
- name: Validate Lint rules
45+
run: npm run lint:fix

.travis.yml

-23
This file was deleted.

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
const { generateId, getServerlessSdk } = require('./utils')
1+
const { generateId, getServerlessSdk } = require('./lib/utils')
22

3-
// set enough timeout for deployment to finish
4-
jest.setTimeout(300000)
5-
6-
// the yaml file we're testing against
73
const instanceYaml = {
84
org: 'orgDemo',
95
app: 'appDemo',
10-
component: 'flask',
6+
component: 'flask@dev',
117
name: `flask-integration-tests-${generateId()}`,
128
stage: 'dev',
139
inputs: {
@@ -17,16 +13,17 @@ const instanceYaml = {
1713
}
1814
}
1915

20-
// get credentials from process.env but need to init empty credentials object
2116
const credentials = {
22-
tencent: {}
17+
tencent: {
18+
SecretId: process.env.TENCENT_SECRET_ID,
19+
SecretKey: process.env.TENCENT_SECRET_KEY,
20+
}
2321
}
2422

25-
// get serverless construct sdk
2623
const sdk = getServerlessSdk(instanceYaml.org)
2724

2825
it('should successfully deploy flask app', async () => {
29-
const instance = await sdk.deploy(instanceYaml, { tencent: {} })
26+
const instance = await sdk.deploy(instanceYaml, credentials)
3027
expect(instance).toBeDefined()
3128
expect(instance.instanceName).toEqual(instanceYaml.name)
3229
// get src from template by default
File renamed without changes.

jest.config.js

+14
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"access": "public"
66
},
77
"scripts": {
8-
"int-test": "jest ./tests/integration.test.js --testEnvironment node",
9-
"test": "npm run lint && npm run prettier && npm run int-test",
8+
"test": "jest",
109
"commitlint": "commitlint -f HEAD@{15}",
1110
"lint": "eslint --ext .js,.ts,.tsx .",
1211
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",

serverless.component.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: flask
2-
version: 0.0.8
2+
version: 0.0.9
33
author: 'Tencent Cloud, Inc'
44
org: 'Tencent Cloud, Inc'
55
description: Deploy a serverless Flask application onto Tencent SCF and API Gateway.

src/package.json

+1-1
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.4",
4+
"tencent-component-toolkit": "^1.19.8",
55
"type": "^2.1.0"
66
}
77
}

src/serverless.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,33 @@ class ServerlessComponent extends Component {
196196
outputs.templateUrl = CONFIGS.templateUrl
197197
}
198198

199-
const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
199+
let apigwOutputs
200+
const functionOutputs = await this.deployFunction(
201+
credentials,
202+
functionConf,
203+
regionList,
204+
outputs
205+
)
200206
// support apigatewayConf.isDisabled
201207
if (apigatewayConf.isDisabled !== true) {
202-
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
208+
apigwOutputs = await this.deployApigateway(credentials, apigatewayConf, regionList, outputs)
203209
} else {
204210
this.state.apigwDisabled = true
205211
}
206-
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)
207212

208213
// optimize outputs for one region
209214
if (regionList.length === 1) {
210215
const [oneRegion] = regionList
211216
outputs.region = oneRegion
212-
outputs['apigw'] = apigwOutputs[oneRegion]
213217
outputs['scf'] = functionOutputs[oneRegion]
218+
if (apigwOutputs) {
219+
outputs['apigw'] = apigwOutputs[oneRegion]
220+
}
214221
} else {
215-
outputs['apigw'] = apigwOutputs
216222
outputs['scf'] = functionOutputs
223+
if (apigwOutputs) {
224+
outputs['apigw'] = apigwOutputs
225+
}
217226
}
218227

219228
this.state.region = regionList[0]
@@ -238,10 +247,6 @@ class ServerlessComponent extends Component {
238247
const scf = new Scf(credentials, curRegion)
239248
const apigw = new Apigw(credentials, curRegion)
240249
const handler = async () => {
241-
await scf.remove({
242-
functionName: curState.functionName,
243-
namespace: curState.namespace
244-
})
245250
// if disable apigw, no need to remove
246251
if (state.apigwDisabled !== true) {
247252
await apigw.remove({
@@ -252,6 +257,10 @@ class ServerlessComponent extends Component {
252257
customDomains: curState.customDomains
253258
})
254259
}
260+
await scf.remove({
261+
functionName: curState.functionName,
262+
namespace: curState.namespace
263+
})
255264
}
256265
removeHandlers.push(handler())
257266
}

0 commit comments

Comments
 (0)