Skip to content

fix: update to deployment to serial flow #14

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

Merged
merged 2 commits into from
Dec 15, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Release

on:
push:
branches: [master]

jobs:
release:
name: Release
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
persist-credentials: false

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x
registry-url: https://registry.npmjs.org

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
restore-keys: npm-v14-${{ runner.os }}-refs/heads/master-

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Releasing
run: |
npm run release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_AUTHOR_NAME: slsplus
GIT_AUTHOR_EMAIL: slsplus.sz@gmail.com
GIT_COMMITTER_NAME: slsplus
GIT_COMMITTER_EMAIL: slsplus.sz@gmail.com
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test

on:
pull_request:
branches: [master]

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# Ensure connection with 'master' branch
fetch-depth: 2

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x
registry-url: https://registry.npmjs.org

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v14-${{ runner.os }}-${{ github.ref }}-
npm-v14-${{ runner.os }}-refs/heads/master-

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Running tests
run: npm run test
env:
SERVERLESS_PLATFORM_VENDOR: tencent
GLOBAL_ACCELERATOR_NA: true
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}
45 changes: 45 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validate

on:
pull_request:
branches: [master]

jobs:
lintAndFormatting:
name: Lint & Formatting
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# Ensure connection with 'master' branch
fetch-depth: 2

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x
registry-url: https://registry.npmjs.org

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: |
npm-v14-${{ runner.os }}-${{ github.ref }}-
npm-v14-${{ runner.os }}-refs/heads/master-

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save

- name: Validate Formatting
run: npm run prettier:fix
- name: Validate Lint rules
run: npm run lint:fix
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

17 changes: 7 additions & 10 deletions tests/integration.test.js → __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const { generateId, getServerlessSdk } = require('./utils')
const { generateId, getServerlessSdk } = require('./lib/utils')

// set enough timeout for deployment to finish
jest.setTimeout(300000)

// the yaml file we're testing against
const instanceYaml = {
org: 'orgDemo',
app: 'appDemo',
component: 'flask',
component: 'flask@dev',
name: `flask-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {
Expand All @@ -17,16 +13,17 @@ const instanceYaml = {
}
}

// get credentials from process.env but need to init empty credentials object
const credentials = {
tencent: {}
tencent: {
SecretId: process.env.TENCENT_SECRET_ID,
SecretKey: process.env.TENCENT_SECRET_KEY,
}
}

// get serverless construct sdk
const sdk = getServerlessSdk(instanceYaml.org)

it('should successfully deploy flask app', async () => {
const instance = await sdk.deploy(instanceYaml, { tencent: {} })
const instance = await sdk.deploy(instanceYaml, credentials)
expect(instance).toBeDefined()
expect(instance.instanceName).toEqual(instanceYaml.name)
// get src from template by default
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { join } = require('path')
require('dotenv').config({ path: join(__dirname, '.env.test') })

const config = {
verbose: true,
silent: false,
testTimeout: 600000,
testEnvironment: 'node',
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$',
testPathIgnorePatterns: ['/node_modules/', '/__tests__/lib/'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
}

module.exports = config
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"access": "public"
},
"scripts": {
"int-test": "jest ./tests/integration.test.js --testEnvironment node",
"test": "npm run lint && npm run prettier && npm run int-test",
"test": "jest",
"commitlint": "commitlint -f HEAD@{15}",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
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: flask
version: 0.0.8
version: 0.0.9
author: 'Tencent Cloud, Inc'
org: 'Tencent Cloud, Inc'
description: Deploy a serverless Flask application onto Tencent SCF and API Gateway.
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.16.4",
"tencent-component-toolkit": "^1.19.8",
"type": "^2.1.0"
}
}
27 changes: 18 additions & 9 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,33 @@ class ServerlessComponent extends Component {
outputs.templateUrl = CONFIGS.templateUrl
}

const deployTasks = [this.deployFunction(credentials, functionConf, regionList, outputs)]
let apigwOutputs
const functionOutputs = await this.deployFunction(
credentials,
functionConf,
regionList,
outputs
)
// support apigatewayConf.isDisabled
if (apigatewayConf.isDisabled !== true) {
deployTasks.push(this.deployApigateway(credentials, apigatewayConf, regionList, outputs))
apigwOutputs = await this.deployApigateway(credentials, apigatewayConf, regionList, outputs)
} else {
this.state.apigwDisabled = true
}
const [functionOutputs, apigwOutputs = {}] = await Promise.all(deployTasks)

// optimize outputs for one region
if (regionList.length === 1) {
const [oneRegion] = regionList
outputs.region = oneRegion
outputs['apigw'] = apigwOutputs[oneRegion]
outputs['scf'] = functionOutputs[oneRegion]
if (apigwOutputs) {
outputs['apigw'] = apigwOutputs[oneRegion]
}
} else {
outputs['apigw'] = apigwOutputs
outputs['scf'] = functionOutputs
if (apigwOutputs) {
outputs['apigw'] = apigwOutputs
}
}

this.state.region = regionList[0]
Expand All @@ -238,10 +247,6 @@ class ServerlessComponent extends Component {
const scf = new Scf(credentials, curRegion)
const apigw = new Apigw(credentials, curRegion)
const handler = async () => {
await scf.remove({
functionName: curState.functionName,
namespace: curState.namespace
})
// if disable apigw, no need to remove
if (state.apigwDisabled !== true) {
await apigw.remove({
Expand All @@ -252,6 +257,10 @@ class ServerlessComponent extends Component {
customDomains: curState.customDomains
})
}
await scf.remove({
functionName: curState.functionName,
namespace: curState.namespace
})
}
removeHandlers.push(handler())
}
Expand Down