Skip to content

Commit

Permalink
feat: update deployCdn supporting onlyRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed May 25, 2020
1 parent ecb3e44 commit 991dc40
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 91 deletions.
8 changes: 8 additions & 0 deletions doc/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ inputs:
| ---------- | -------- | ------- | --------------------------------------------------------------------------------- |
| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, |
| autoRefesh | 否 | `false` | 是否自动刷新预热 CDN |
| onlyRefesh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 |
| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) |
| host | 是 | | 需要接入的 CDN 域名。 |
| host | 是 | | 需要接入的 CDN 域名。 |
| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https |
Expand All @@ -140,4 +142,10 @@ inputs:

> 注意:`async` 参数对于配置多个 CDN 域名需求,或者在 CI 流程中时,建议配置成 `true`,不然会导致 serverless cli 执行超时,或者 CI 流程超时。

#### refreshCdn

| 参数名称 | 是否必选 | 默认 | 描述 |
| -------- | -------- | ---- | ------------------- |
| urls | 否 | [] | 需要刷新的 CDN 路径 |

更多配置,请移至官方云 API 文档:https://cloud.tencent.com/document/product/228/41123
80 changes: 0 additions & 80 deletions doc/serverless.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@serverless/website",
"version": "0.0.5",
"version": "0.0.6",
"main": "./serverless.js",
"publishConfig": {
"access": "public"
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: website
version: 0.0.5
version: 0.0.6
author: Tencent Cloud, Inc.
org: Tencent Cloud, Inc.
description: Deploys Tencent Website.
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"fs-extra": "^8.1.0",
"request": "^2.88.2",
"string-random": "^0.1.3",
"tencent-component-toolkit": "^1.5.4",
"tencent-component-toolkit": "^1.7.2",
"type": "^2.0.0"
}
}
27 changes: 19 additions & 8 deletions src/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,23 @@ class ServerlessComponent extends Component {
originPullProtocol: originPullProtocol
}

if (cdnInputs.autoRefesh) {
if (cdnInputs.autoRefresh) {
cdnInputs.refreshCdn = {
urls: [`http://${cdnInputs.domain}`, `https://${cdnInputs.domain}`]
}
}
tencentCdnOutput = await cdn.deploy(cdnInputs)
protocol = tencentCdnOutput.https ? 'https' : 'http'
cdnResult.push(
protocol + '://' + tencentCdnOutput.domain + ' (CNAME: ' + tencentCdnOutput.cname + ')'
)
const result = {
domain: `${protocol}://${tencentCdnOutput.domain}`,
cname: tencentCdnOutput.cname
}
if (cdnInputs.onlyRefresh !== true) {
if (cdnInputs.refreshCdn && cdnInputs.refreshCdn.urls) {
result.refreshUrls = cdnInputs.refreshCdn.urls
}
cdnResult.push(result)
}
outputs.push(tencentCdnOutput)
}
return {
Expand Down Expand Up @@ -158,7 +165,7 @@ class ServerlessComponent extends Component {
originPullProtocol: websiteInputs.protocol
})

output.hosts = deployCdnRes.cdnResult
output.cdnDomains = deployCdnRes.cdnResult
this.state.cdn = deployCdnRes.outputs
}

Expand All @@ -176,15 +183,19 @@ class ServerlessComponent extends Component {

// 默认值
const { region } = this.state
const stateCdn = this.state.cdn

// 创建cos对象
const cos = new Cos(credentials, region)
await cos.remove(this.state.website)

if (this.state.cdn) {
if (stateCdn) {
const cdn = new Cdn(credentials, region)
for (let i = 0; i < this.state.cdn.length; i++) {
await cdn.remove(this.state.cdn[i])
for (let i = 0; i < stateCdn.length; i++) {
const curCdnConf = stateCdn[i]
if (curCdnConf.created === true) {
await cdn.remove(curCdnConf)
}
}
}

Expand Down

0 comments on commit 991dc40

Please sign in to comment.