Skip to content

Commit c4135c4

Browse files
committed
feat: init project
1 parent 6f4c64e commit c4135c4

20 files changed

+924
-0
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
dist
3+
node_modules

.eslintrc.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['prettier'],
4+
plugins: ['import', 'prettier'],
5+
env: {
6+
es6: true,
7+
jest: true,
8+
node: true
9+
},
10+
parser: 'babel-eslint',
11+
parserOptions: {
12+
ecmaVersion: 2018,
13+
sourceType: 'module',
14+
ecmaFeatures: {
15+
jsx: true
16+
}
17+
},
18+
globals: {
19+
on: true // for the Socket file
20+
},
21+
rules: {
22+
'array-bracket-spacing': [
23+
'error',
24+
'never',
25+
{
26+
objectsInArrays: false,
27+
arraysInArrays: false
28+
}
29+
],
30+
'arrow-parens': ['error', 'always'],
31+
'arrow-spacing': ['error', { before: true, after: true }],
32+
'comma-dangle': ['error', 'never'],
33+
curly: 'error',
34+
'eol-last': 'error',
35+
'func-names': 'off',
36+
'id-length': [
37+
'error',
38+
{
39+
min: 2,
40+
max: 50,
41+
properties: 'never',
42+
exceptions: ['e', 'i', 'n', 't', 'x', 'y', 'z', '_', '$']
43+
}
44+
],
45+
'no-alert': 'error',
46+
'no-console': 'error',
47+
'no-const-assign': 'error',
48+
'no-else-return': 'error',
49+
'no-empty': 'off',
50+
'no-shadow': 'error',
51+
'no-undef': 'error',
52+
'no-unused-vars': 'error',
53+
'no-use-before-define': 'error',
54+
'no-useless-constructor': 'error',
55+
'object-curly-newline': 'off',
56+
'object-shorthand': 'off',
57+
'prefer-const': 'error',
58+
'prefer-destructuring': ['error', { object: true, array: false }],
59+
quotes: [
60+
'error',
61+
'single',
62+
{
63+
allowTemplateLiterals: true,
64+
avoidEscape: true
65+
}
66+
],
67+
semi: ['error', 'never'],
68+
'spaced-comment': 'error',
69+
strict: ['error', 'never'],
70+
'prettier/prettier': 'error'
71+
}
72+
}

.gitignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
*.sublime-project
3+
*.sublime-workspace
4+
*.log
5+
.serverless
6+
v8-compile-cache-*
7+
jest/*
8+
coverage
9+
.serverless_plugins
10+
testProjects/*/package-lock.json
11+
testProjects/*/yarn.lock
12+
.serverlessUnzipped
13+
node_modules
14+
.vscode/
15+
.eslintcache
16+
dist
17+
.idea
18+
build/
19+
.env*
20+
env.js
21+
package-lock.json
22+
yarn.lock

.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
components
2+
examples
3+
.idea
4+
.serverless
5+
coverage
6+
.env*
7+
env.js
8+
tmp
9+
test

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.DS_Store
2+
*.sublime-project
3+
*.sublime-workspace
4+
*.log
5+
.serverless
6+
v8-compile-cache-*
7+
jest/*
8+
coverage
9+
.serverless_plugins
10+
testProjects/*/package-lock.json
11+
testProjects/*/yarn.lock
12+
.serverlessUnzipped
13+
node_modules
14+
.vscode/
15+
.eslintcache
16+
dist
17+
.idea
18+
build/
19+
.env*
20+
env.js
21+
package-lock.json
22+
yarn.lock

README.en.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Tencent Flask Serverless Component
2+
3+
[简体中文](./README.md) | English
4+
5+
## Introduction
6+
7+
Flask Serverless Component for Tencent Cloud, support Restful API deploy, not supportting Flask command.
8+
9+
## Content
10+
11+
1. [Prepare](#0-prepare)
12+
1. [Install](#1-install)
13+
2. [Create](#2-create)
14+
3. [Configure](#3-configure)
15+
4. [Deploy](#4-deploy)
16+
5. [Remove](#5-Remove)
17+
18+
### 0. Prepare
19+
20+
Before using this component, you need add `Flask` and `werkzeug` for your requirements. Like below:
21+
22+
```txt
23+
Flask==1.0.2
24+
werkzeug==0.16.0
25+
```
26+
27+
### 1. Install
28+
29+
Install the Serverless Framework globally:
30+
31+
```shell
32+
$ npm install -g serverless
33+
```
34+
35+
### 2. Create
36+
37+
Just create the following simple boilerplate:
38+
39+
```shell
40+
$ touch serverless.yml
41+
$ touch .env # your Tencent api keys
42+
```
43+
44+
Add the access keys of a [Tencent CAM Role](https://console.cloud.tencent.com/cam/capi) with `AdministratorAccess` in the `.env` file, using this format:
45+
46+
```
47+
# .env
48+
TENCENT_SECRET_ID=XXX
49+
TENCENT_SECRET_KEY=XXX
50+
```
51+
52+
- If you don't have a Tencent Cloud account, you could [sign up](https://intl.cloud.tencent.com/register) first.
53+
54+
### 3. Configure
55+
56+
```yml
57+
# serverless.yml
58+
59+
MyComponent:
60+
component: "@serverless/tencent-flask"
61+
inputs:
62+
region: ap-guangzhou
63+
functionName: flask-function
64+
codeUri: ./
65+
functionConf:
66+
timeout: 10
67+
memorySize: 128
68+
environment:
69+
variables:
70+
TEST: vale
71+
vpcConfig:
72+
subnetId: ''
73+
vpcId: ''
74+
apigatewayConf:
75+
protocol: https
76+
environment: release
77+
```
78+
79+
- [More Options](./docs/configure.md)
80+
81+
### 4. Deploy
82+
83+
```shell
84+
$ sls --debug
85+
```
86+
87+
 
88+
89+
### 5. Remove
90+
91+
```shell
92+
$ sls remove --debug
93+
```
94+
95+
### More Components
96+
97+
Checkout the [Serverless Components](https://github.com/serverless/components) repo for more information.

README.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# 腾讯云 Flask Serverless Component
2+
3+
简体中文 | [English](./README.en.md)
4+
5+
## 简介
6+
7+
腾讯云 Flask Serverless Component, 支持 Restful API 服务的部署,不支持 Flask Command.
8+
9+
## 目录
10+
11+
0. [准备](#0-准备)
12+
1. [安装](#1-安装)
13+
2. [配置](#2-配置)
14+
3. [部署](#3-部署)
15+
4. [移除](#4-移除)
16+
17+
18+
### 0. 准备
19+
20+
在使用此组件之前,需要将 `Flask``werkzeug` 添加到依赖文件 `requiements.txt` 中,比如:
21+
22+
```txt
23+
Flask==1.0.2
24+
werkzeug==0.16.0
25+
```
26+
27+
### 1. 安装
28+
29+
通过 npm 全局安装 [serverless cli](https://github.com/serverless/serverless)
30+
31+
```shell
32+
$ npm install -g serverless
33+
```
34+
35+
### 2. 配置
36+
37+
本地创建 `serverless.yml` 文件,在其中进行如下配置
38+
39+
```shell
40+
$ touch serverless.yml
41+
```
42+
43+
```yml
44+
# serverless.yml
45+
46+
MyComponent:
47+
component: "@serverless/tencent-flask"
48+
inputs:
49+
region: ap-guangzhou
50+
functionName: flask-function
51+
codeUri: ./
52+
functionConf:
53+
timeout: 10
54+
memorySize: 128
55+
environment:
56+
variables:
57+
TEST: vale
58+
vpcConfig:
59+
subnetId: ''
60+
vpcId: ''
61+
apigatewayConf:
62+
protocol: https
63+
environment: release
64+
```
65+
66+
- [更多配置](./docs/configure.md)
67+
68+
### 3. 部署
69+
70+
如您的账号未 [登陆](https://cloud.tencent.com/login) 或 [注册](https://cloud.tencent.com/register) 腾讯云,您可以直接通过 `微信` 扫描命令行中的二维码进行授权登陆和注册。
71+
72+
通过 `sls` 命令进行部署,并可以添加 `--debug` 参数查看部署过程中的信息
73+
74+
```shell
75+
$ sls --debug
76+
```
77+
78+
### 4. 移除
79+
80+
通过以下命令移除部署的 API 网关
81+
82+
```shell
83+
$ sls remove --debug
84+
```
85+
86+
### 账号配置(可选)
87+
88+
当前默认支持 CLI 扫描二维码登录,如您希望配置持久的环境变量/秘钥信息,也可以本地创建 `.env` 文件
89+
90+
```shell
91+
$ touch .env # 腾讯云的配置信息
92+
```
93+
94+
在 `.env` 文件中配置腾讯云的 SecretId 和 SecretKey 信息并保存
95+
96+
如果没有腾讯云账号,可以在此 [注册新账号](https://cloud.tencent.com/register)。
97+
98+
如果已有腾讯云账号,可以在 [API 密钥管理](https://console.cloud.tencent.com/cam/capi) 中获取 `SecretId` 和`SecretKey`.
99+
100+
```text
101+
# .env
102+
TENCENT_SECRET_ID=123
103+
TENCENT_SECRET_KEY=123
104+
```
105+
106+
### 更多组件
107+
108+
可以在 [Serverless Components](https://github.com/serverless/components) repo 中查询更多组件的信息。

0 commit comments

Comments
 (0)