Skip to content

Commit

Permalink
feat: init version (#1)
Browse files Browse the repository at this point in the history
* init

* init

* remove initTimeout
  • Loading branch information
Jominja authored Aug 5, 2021
1 parent 4292f69 commit 3ff0216
Show file tree
Hide file tree
Showing 2,966 changed files with 141,062 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
*.sublime-project
*.sublime-workspace
*.log
.serverless
v8-compile-cache-*
jest/*
coverage
.serverless_plugins
testProjects/*/package-lock.json
testProjects/*/yarn.lock
.serverlessUnzipped
node_modules
.vscode/
.eslintcache
dist
.idea
build/
.env*
env.js
package-lock.json
test
yarn.lock
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## [0.2.1](https://github.com/serverless-components/tencent-wordpress/compare/v0.2.0...v0.2.1) (2021-04-28)


### Bug Fixes

* config apigw id bug ([754c5fc](https://github.com/serverless-components/tencent-wordpress/commit/754c5fc1026443e1397366d42714b4eeb98af523))

# [0.2.0](https://github.com/serverless-components/tencent-wordpress/compare/v0.1.1...v0.2.0) (2021-04-27)


### Features

* support tag config ([c9765be](https://github.com/serverless-components/tencent-wordpress/commit/c9765be56162410a77d4f76df42f2f16b162bbc1))

## [0.1.1](https://github.com/serverless-components/tencent-wordpress/compare/v0.1.0...v0.1.1) (2021-04-15)


### Bug Fixes

* optimize default subnet create ([f031eba](https://github.com/serverless-components/tencent-wordpress/commit/f031eba0205bdcd606672ba173051acb8ca256a1))

# [0.1.0](https://github.com/serverless-components/tencent-wordpress/compare/v0.0.6...v0.1.0) (2021-04-14)


### Bug Fixes

* add can not get CIDR error ([5d555d3](https://github.com/serverless-components/tencent-wordpress/commit/5d555d36f4977346a1435ac14a26a956aa462287))
* increase upload size to 4M ([44060f6](https://github.com/serverless-components/tencent-wordpress/commit/44060f632a8082c0ee8c547e56f9d493989fcd9f))
* support auto provide cidr for subnet ([2d9661a](https://github.com/serverless-components/tencent-wordpress/commit/2d9661ad5303f24bd7e00be8b03f8b9e52d37f00))


### Features

* support using default vpc ([a474359](https://github.com/serverless-components/tencent-wordpress/commit/a474359fdf307cb77d17e20ca456de87f877da61))

## [0.0.6](https://github.com/serverless-components/tencent-wordpress/compare/v0.0.5...v0.0.6) (2021-03-25)


### Bug Fixes

* update db config to lowest config ([fb2a5a5](https://github.com/serverless-components/tencent-wordpress/commit/fb2a5a5994b1a614bc23d23c44e96a99260252b7))

## [0.0.5](https://github.com/serverless-components/tencent-wordpress/compare/v0.0.4...v0.0.5) (2021-02-25)


### Bug Fixes

* config cache bug ([324ed8b](https://github.com/serverless-components/tencent-wordpress/commit/324ed8bcadccd86b6ff5d8313ac218fe0f1be2d8))

## [0.0.4](https://github.com/serverless-components/tencent-wordpress/compare/v0.0.3...v0.0.4) (2021-02-19)


### Bug Fixes

* ignore remove error ([#1](https://github.com/serverless-components/tencent-wordpress/issues/1)) ([c6daf72](https://github.com/serverless-components/tencent-wordpress/commit/c6daf72b7eb750d4f07c51d9151990b0c3865b98))
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Serverless Components
Copyright (c) 2020 Tencent Cloud, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
123 changes: 123 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
**腾讯云 Discuz!Q 组件** ⎯⎯⎯ 通过使用 [Tencent Serverless Framework](https://github.com/serverless/components/tree/cloud),基于云上 Serverless 服务(如网关、云函数、CFS 等),实现“0”配置,便捷开发,极速部署你的 Discuz!Q 应用,Discuz!Q 组件支持丰富的配置扩展,提供了目前最易用、低成本并且弹性伸缩的 Discuz!Q 项目开发/托管能力。
<br/>

快速开始:

1. [**安装**](#1-安装)
2. [**创建**](#2-创建)
3. [**部署**](#3-部署)
4. [**配置**](#4-配置)
5. [**查看状态**](#6-查看状态)
6. [**移除**](#7-移除)

更多资源:

- [**架构说明**](#架构说明)
- [**账号配置**](#账号配置)

### 1. 安装

通过 npm 安装最新版本的 Serverless Framework

```bash
$ npm install -g serverless
```

### 2. 部署

`serverless.yml` 文件所在的项目根目录,运行以下指令进行部署:

```bash
$ serverless deploy
```

部署时需要进行身份验证,如您的账号未 [登陆](https://cloud.tencent.com/login)[注册](https://cloud.tencent.com/register) 腾讯云,您可以直接通过 `微信` 扫描命令行中的二维码进行授权登陆和注册。

> 注意: 如果希望查看更多部署过程的信息,可以通过`serverless deploy --debug` 命令查看部署过程中的实时日志信息。
部署成功后控制台输出参数介绍请参考 [output 文档](https://github.com/serverless-components/tencent-wordpress/blob/master/docs/output.md)

### 3. 配置

Discuz!Q 组件支持 0 配置部署,也就是可以直接通过配置文件中的默认值进行部署。但你依然可以修改更多可选配置来进一步开发该 Discuz!Q 项目。

以下是 Discuz!Q 组件的 `serverless.yml`配置示例:

```yml
# serverless.yml

app: appDemo
stage: dev
component: discuz-q
name: discuzqDemo

inputs:
region: ap-shanghai
src:
exclude:
- .env
```
点此查看[全量配置及配置说明](https://github.com/serverless-components/tencent-discuzq/tree/master/docs/configure.md)
当你根据该配置文件更新配置字段后,再次运行 `serverless deploy` 或者 `serverless` 就可以更新配置到云端。

### 5. 查看状态

在`serverless.yml`文件所在的目录下,通过如下命令查看部署状态:

```
$ serverless info
```
### 6. 移除
在`serverless.yml`文件所在的目录下,通过以下命令移除部署的 Discuz!Q 服务。移除后该组件会对应删除云上部署时所创建的所有相关资源。
```
$ serverless remove
```
和部署类似,支持通过 `serverless remove --debug` 命令查看移除过程中的实时日志信息。
### 7. 安装
在部署完成 Discuz!Q 后,您需要进行初始化安装和配置数据库,安装步骤请参考[官方文档](https://discuz.com/docs/)。
建议使用与 Discuz!Q 实例同地域的数据库。
## 架构说明
Discuz!Q 组件将在腾讯云账户中使用到如下 Serverless 服务:
- [x] **API 网关** - API 网关将会接收外部请求并且转发到 SCF 云函数中。
- [x] **SCF 云函数** - 云函数将承载 Wordpress.js 应用。
- [x] **CAM 访问控制** - 该组件会创建默认 CAM 角色用于授权访问关联资源。
- [x] **COS 对象存储** - 为确保上传速度和质量,云函数压缩并上传代码时,会默认将代码包存储在特定命名的 COS 桶中。
- [x] **VPC 私有网络** - 腾讯云私有网络。
- [x] **CFS 文件存储** - 腾讯云文件存储。
- [x] **SSL 证书服务** - 如果你在 yaml 文件中配置了 `apigatewayConf.customDomains` 字段,需要做自定义域名绑定并开启 HTTPS 时,也会用到证书管理服务和域名服务。Serverless Framework 会根据已经备案的域名自动申请并配置 SSL 证书。
## 账号配置
当前默认支持 CLI 扫描二维码登录,如您希望配置持久的环境变量/秘钥信息,也可以本地创建 `.env` 文件
```console
$ touch .env # 腾讯云的配置信息
```

`.env` 文件中配置腾讯云的 SecretId 和 SecretKey 信息并保存

如果没有腾讯云账号,可以在此[注册新账号](https://cloud.tencent.com/register)

如果已有腾讯云账号,可以在[API 密钥管理](https://console.cloud.tencent.com/cam/capi)中获取 `SecretId``SecretKey`.

```
# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
```

## License

MIT License

Copyright (c) 2020 Tencent Cloud, Inc.
77 changes: 77 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const { generateId, getServerlessSdk } = require('./lib/utils')

const instanceYaml = {
org: 'orgDemo',
app: 'appDemo',
component: 'discuz-q@dev',
name: `discuzq-integration-tests-${generateId()}`,
stage: 'dev',
inputs: {}
}

const credentials = {
tencent: {
SecretId: process.env.TENCENT_SECRET_ID,
SecretKey: process.env.TENCENT_SECRET_KEY,
}
}

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

it('Using template should deploy success', async () => {
const instance = await sdk.deploy(instanceYaml, credentials)

expect(instance).toBeDefined()

const { outputs } = instance
expect(instance.instanceName).toEqual(instanceYaml.name)

// vpc
expect(outputs.vpc).toBeDefined()
expect(outputs.vpc.region).toBe('ap-shanghai')
expect(outputs.vpc.zone).toBe('ap-shanghai-2')
expect(outputs.vpc.vpcId).toContain('vpc-')
expect(outputs.vpc.subnetId).toContain('subnet-')

// cfs
expect(outputs.cfs).toBeDefined()
expect(outputs.cfs.cfsId).toContain('cfs-')

// layer
expect(outputs.layer).toBeDefined()
expect(outputs.layer.name).toContain('dzq-layer')
expect(outputs.layer.version).toBeGreaterThanOrEqual(1)
expect(outputs.layer.runtimes).toEqual([
'Php7'
])


// apigw
expect(outputs.apigw).toBeDefined()
expect(outputs.apigw.id).toContain('service-')
expect(outputs.apigw.environment).toEqual('release')

// wpInitFaas
expect(outputs.wpInitFaas).toBeDefined()
expect(outputs.wpInitFaas.name).toContain('dzq-init')
expect(outputs.wpInitFaas.runtime).toEqual('Nodejs12.16')

// wpServerFaas
expect(outputs.wpServerFaas).toBeDefined()
expect(outputs.wpServerFaas.name).toContain('dzq-server')
expect(outputs.wpServerFaas.runtime).toEqual('Php7')
expect(outputs.wpServerFaas.layers).toEqual([
{
name: outputs.layer.name,
version: outputs.layer.version
}
])
})

it('should remove success', async () => {
await sdk.remove(instanceYaml, credentials)
result = await sdk.getInstance(instanceYaml.org, instanceYaml.stage, instanceYaml.app, instanceYaml.name)

expect(result.instance.instanceStatus).toEqual('inactive')
})
24 changes: 24 additions & 0 deletions __tests__/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { ServerlessSDK } = require('@serverless/platform-client-china')

/*
* Generate random id
*/
const generateId = () =>
Math.random()
.toString(36)
.substring(6)

/*
* Initializes and returns an instance of the serverless sdk
* @param ${string} orgName - the serverless org name.
*/
const getServerlessSdk = (orgName) => {
const sdk = new ServerlessSDK({
context: {
orgName
}
})
return sdk
}

module.exports = { generateId, getServerlessSdk }
9 changes: 9 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Configuration = {
/*
* Resolve and load @commitlint/config-conventional from node_modules.
* Referenced packages must be installed
*/
extends: ['@commitlint/config-conventional']
}

module.exports = Configuration
Binary file added docs/architecture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3ff0216

Please sign in to comment.