-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from devsapp/develop
some bugfix and implement the start-fc-cdn app
- Loading branch information
Showing
10 changed files
with
277 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
async function preInit(inputObj) { | ||
|
||
} | ||
|
||
async function postInit(inputObj) { | ||
|
||
} | ||
|
||
module.exports = { | ||
postInit, | ||
preInit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
Type: Application | ||
Name: start-fc-cdn | ||
Provider: | ||
- 阿里云 | ||
Version: 0.0.1 | ||
Description: FC 回源到CDN | ||
HomePage: https://github.com/devsapp/start-cdn/start-fc-cdn/ | ||
Tags: #标签详情 | ||
- 部署函数 | ||
- Web应用 | ||
- CDN | ||
Category: 新手入门 | ||
Service: # 使用的服务 | ||
函数计算: | ||
Authorities: | ||
- AliyunFCFullAccess | ||
Runtime: Node.js14 | ||
CDN: | ||
Authorities: #权限描述 | ||
- AliyunCDNFullAccess | ||
Parameters: | ||
type: object | ||
additionalProperties: false # 不允许增加其他属性 | ||
required: # 必填项 | ||
- region | ||
- serviceName | ||
- functionName | ||
- acrRegistry | ||
properties: | ||
region: | ||
title: 地域 | ||
type: string | ||
default: cn-hangzhou | ||
description: 创建应用所在的地区 | ||
enum: | ||
- cn-beijing | ||
- cn-hangzhou | ||
- cn-shanghai | ||
- cn-qingdao | ||
- cn-zhangjiakou | ||
- cn-huhehaote | ||
- cn-shenzhen | ||
- cn-chengdu | ||
- cn-hongkong | ||
- ap-southeast-1 | ||
- ap-southeast-2 | ||
- ap-southeast-3 | ||
- ap-southeast-5 | ||
- ap-northeast-1 | ||
- eu-central-1 | ||
- eu-west-1 | ||
- us-west-1 | ||
- us-east-1 | ||
- ap-south-1 | ||
serviceName: | ||
title: 服务名 | ||
type: string | ||
default: start-fc-cdn-service | ||
description: 服务名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间 | ||
functionName: | ||
title: 函数名 | ||
type: string | ||
default: start-fc-cdn-fc | ||
description: 函数名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-64 之间 | ||
domainName: | ||
title: 加速域名 | ||
description: cdn加速域名,必填项 | ||
type: string | ||
refreshAfterDeploy: | ||
title: 部署后自动刷新cdn | ||
description: 部署完成后字段cdn的缓存,让cdn的缓存失效,下次访问直接访问源站 | ||
type: boolean | ||
default: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# start-fc-cdn帮助文档 | ||
快速部署一个静态网站到阿里云FC并使用阿里云CDN服务为其进行CDN加速。 | ||
<a name="tu2Bs"></a> | ||
## 前期准备 | ||
使用该项目,推荐您拥有以下的产品权限 / 策略: | ||
|
||
| **服务/业务** | **函数计算** | | ||
| --- | --- | | ||
| 权限/策略 | AliyunFCFullAccess | | ||
| 权限/策略 | AliyunCDNFullAccess | | ||
|
||
<a name="cDPBk"></a> | ||
## 部署&体验 | ||
|
||
- 🔥 通过 [Serverless 应用中心](https://fcnext.console.aliyun.com/applications/create?template=start-fc-cdn) , [![](https://cdn.nlark.com/yuque/0/2022/svg/2754189/1659421080072-872339bd-efe6-40c2-980a-2b774a7aea31.svg#clientId=u4260fcfa-1d28-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u951fe235&margin=%5Bobject%20Object%5D&originHeight=28&originWidth=95&originalType=url&ratio=1&rotation=0&showTitle=false&status=done&style=none&taskId=u90c7646a-d32f-4a27-bacf-aba2236f868&title=)](https://fcnext.console.aliyun.com/applications/create?start-oss-cdn) 该应用。 | ||
- 通过 [Serverless Devs Cli](https://www.serverless-devs.com/serverless-devs/install) 进行部署: | ||
- [安装 Serverless Devs Cli 开发者工具](https://www.serverless-devs.com/serverless-devs/install) ,并进行[授权信息配置](https://www.serverless-devs.com/fc/config) ; | ||
- 初始化项目:s init start-fc-cdn -d start-fc-cdn | ||
- 进入项目,并进行项目部署:cd start-fc-cdn && s deploy -y | ||
<a name="TXTmL"></a> | ||
- 项目目录结构 | ||
``` | ||
- dist # 存放静态文件路径 | ||
- index.htm | ||
- s.yaml | ||
``` | ||
## 删除 | ||
在项目目录下执行`s remove` | ||
> Tips:该操作不仅会删除FC服务,还会删除cdn加速域名 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Application development instructions | ||
|
||
<p align="center"><b> <a href="./readme.md"> 中文 </a> | English </b></p> | ||
|
||
> The development of Serverless Devs applications must strictly conform to the [application model specification](../../spec/en/0.0.2/serverless_package_model/3.package_model.md#Application-model-specification) in [Serverless Package Model](../../spec/en/0.0.2/serverless_package_model/readme.md). In the [application model specification](../../spec/en/0.0.2/serverless_package_model/3.package_model.md#Application-model-specification), the instructions on [application model metadata](../../spec/en/0.0.2/serverless_package_model/3.package_model.md#Application-model-metadata) are described. | ||
The component development cases of Serverless Devs are integrated into the Serverless Devs CLI tool. You can use the CLI tool to initialize an application project that is not developed. Developers only need to run the s init command, and the following command output is returned: | ||
|
||
```shell script | ||
|
||
🚀 Serverless Awesome: https://github.com/Serverless-Devs/package-awesome | ||
|
||
? Hello Serverless for Cloud Vendors (Use arrow keys or type to search) | ||
❯ Alibaba Cloud Serverless | ||
AWS Cloud Serverless | ||
Tencent Cloud Serverless | ||
Baidu Cloud Serverless | ||
Dev Template for Serverless Devs | ||
``` | ||
|
||
Select the last line `Dev Template for Serverless Devs` and press the Enter key. The following command output is returned: | ||
|
||
|
||
```shell script | ||
$ s init | ||
|
||
🚀 Serverless Awesome: https://github.com/Serverless-Devs/package-awesome | ||
|
||
? Hello Serverless for Cloud Vendors Dev Template for Serverless Devs | ||
? Please select an Serverless-Devs Application (Use arrow keys or type to search) | ||
❯ Application Scaffolding | ||
Component Scaffolding | ||
``` | ||
Select the `Application Scaffolding` and press the Enter key. The project of a Serverless Devs application is initialized. You can view the file tree by using the following command: | ||
```shell script | ||
$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' | ||
. | ||
|____readme.md | ||
|____version.md | ||
|____publish.yaml | ||
|____src | ||
| |____s.yaml | ||
| |____index.js | ||
``` | ||
The following table describes the directories in the file tree: | ||
| Directory | Description | | ||
| ------------ | ------------------------------------------------------------ | | ||
| readme.md | Description of the component, or help documentations. | | ||
| version.md | The description of the project version, such as the updates of the current version. | | ||
| publish.yaml | The file that is a required for the project. The file is identifiable for developers of Serverless Devs Package. | | ||
| src | The directory where the application is located, which needs to include s.yaml and related application code. | | ||
Developers can develop applications by using the code stored in the src directory and write the `publish.yaml` file for the project. After the preceding operations are complete, you can commit the project to different sources. For example, if you want to commit the project to GitHub Registry, you can create a repository named `Public` in GitHub, store the compiled code into the repository, and then publish a version. In this case, the application is available on Serverless Devs clients. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* /* | ||
* To enable the initializer feature (https://help.aliyun.com/document_detail/156876.html) | ||
* please implement the initializer function as below: | ||
* exports.initializer = (context, callback) => { | ||
* console.log('initializing'); | ||
* callback(null, ''); | ||
* }; | ||
* | ||
* @format | ||
*/ | ||
|
||
exports.handler = (event, context, callback) => { | ||
console.log('hello world'); | ||
callback(null, 'hello world'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范 | ||
name: start-fc-cdn # 项目名称 | ||
access: "{{ access }}" # 秘钥别名 | ||
vars: # 全局变量 | ||
region: "{{ region }}" | ||
serviceName: "{{ serviceName }}" | ||
functionName: "{{ functionName }}" | ||
domainName: "{{ domainName }}" | ||
refreshAfterDeploy: "{{ refreshAfterDeploy }}" | ||
|
||
services: | ||
website: | ||
component: fc | ||
actions: # 自定义执行逻辑 | ||
pre-deploy: # 在deploy之前运行 | ||
- plugin: website-fc | ||
props: # 组件的属性值 | ||
region: ${vars.region} | ||
service: | ||
name: ${vars.serviceName} | ||
internetAccess: true | ||
description: 'fc static website' | ||
function: | ||
name: ${vars.functionName} | ||
description: 'fc static website' | ||
runtime: nodejs14 # 任何一个 runtime 都可以 | ||
codeUri: ./dist | ||
memorySize: 128 | ||
timeout: 60 | ||
triggers: | ||
- name: httpTrigger | ||
type: http | ||
config: | ||
authType: anonymous | ||
methods: | ||
- GET | ||
customDomains: | ||
- domainName: auto | ||
protocol: HTTP | ||
routeConfigs: | ||
- path: /* | ||
methods: | ||
- GET | ||
cdn-service: # cdn 相关配置 | ||
component: devsapp/cdn # 组件名称 | ||
props: # 组件的属性值 | ||
cdnType: web | ||
domainName: ${vars.domainName} | ||
sources: | ||
- type: fc_domain | ||
content: ${website.output.url.custom_domain[0].domain} | ||
refreshConfig: | ||
objectPaths: | ||
- http://${vars.domainName}/ | ||
objectType: Directory | ||
refreshAfterDeploy: ${vars.refreshAfterDeploy} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- 初始化项目 | ||
- 测试项目模板 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,27 @@ | ||
# 应用开发说明 | ||
# start-oss-cdn帮助文档 | ||
快速部署一个静态网站到阿里云OSS并使用阿里云CDN服务为其进行CDN加速。 | ||
<a name="tu2Bs"></a> | ||
## 前期准备 | ||
使用该项目,推荐您拥有以下的产品权限 / 策略: | ||
|
||
| **服务/业务** | **函数计算** | | ||
| --- | --- | | ||
| 权限/策略 | AliyunOSSFullAccess | | ||
| 权限/策略 | AliyunCDNFullAccess | | ||
|
||
<a name="cDPBk"></a> | ||
## 部署&体验 | ||
|
||
- 🔥 通过 [Serverless 应用中心](https://fcnext.console.aliyun.com/applications/create?template=start-oss-cdn) , [![](https://cdn.nlark.com/yuque/0/2022/svg/2754189/1659421080072-872339bd-efe6-40c2-980a-2b774a7aea31.svg#clientId=u4260fcfa-1d28-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u951fe235&margin=%5Bobject%20Object%5D&originHeight=28&originWidth=95&originalType=url&ratio=1&rotation=0&showTitle=false&status=done&style=none&taskId=u90c7646a-d32f-4a27-bacf-aba2236f868&title=)](https://fcnext.console.aliyun.com/applications/create?start-oss-cdn) 该应用。 | ||
- 通过 [Serverless Devs Cli](https://www.serverless-devs.com/serverless-devs/install) 进行部署: | ||
- [安装 Serverless Devs Cli 开发者工具](https://www.serverless-devs.com/serverless-devs/install) ,并进行[授权信息配置](https://www.serverless-devs.com/fc/config) ; | ||
- 初始化项目:s init start-oss-cdn -d start-oss-cdn | ||
- 进入项目,并进行项目部署:cd start-oss-cdn && s deploy -y | ||
<a name="TXTmL"></a> | ||
## 删除 | ||
在项目目录下执行`s remove` | ||
> Tips:该操作只会删除cdn域名,并不会删除OSS的bucket。 | ||
<p align="center"><b> 中文 | <a href="./readme_en.md"> English </a> </b></p> | ||
|
||
|
||
> Serverless Devs 应用开发需要严格遵守 [Serverless Package Model](../../spec/zh/0.0.2/serverless_package_model/readme.md) 中的 [应用模型规范](../../spec/zh/0.0.2/serverless_package_model/3.package_model.md#应用模型规范)。在[应用模型规范](../../spec/zh/0.0.2/serverless_package_model/3.package_model.md#应用模型规范)中有关于[应用模型元数据](../../spec/zh/0.0.2/serverless_package_model/3.package_model.md#应用模型元数据)的说明。 | ||
Serverless Devs的组件开发案例已经被集成到Serverless Devs命令行工具中,通过对Serverless Devs的命令行工具,可以进行空白应用项目的初始化,开发者只需要执行`s init`即可看到: | ||
|
||
```shell script | ||
|
||
🚀 Serverless Awesome: https://github.com/Serverless-Devs/package-awesome | ||
|
||
? Hello Serverless for Cloud Vendors (Use arrow keys or type to search) | ||
❯ Alibaba Cloud Serverless | ||
AWS Cloud Serverless | ||
Tencent Cloud Serverless | ||
Baidu Cloud Serverless | ||
Dev Template for Serverless Devs | ||
``` | ||
|
||
此时,选择最后的`Dev Template for Serverless Devs`,并按回车: | ||
|
||
```shell script | ||
$ s init | ||
|
||
🚀 Serverless Awesome: https://github.com/Serverless-Devs/package-awesome | ||
|
||
? Hello Serverless for Cloud Vendors Dev Template for Serverless Devs | ||
? Please select an Serverless-Devs Application (Use arrow keys or type to search) | ||
❯ Application Scaffolding | ||
Component Scaffolding | ||
``` | ||
此时,选择`Application Scaffolding`,并按回车,即可完成一个完整的Serverless Devs的Application项目的初始化,可以通过命令查看文件树: | ||
```shell script | ||
$ find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' | ||
. | ||
|____readme.md | ||
|____version.md | ||
|____publish.yaml | ||
|____src | ||
| |____s.yaml | ||
| |____index.js | ||
``` | ||
这其中: | ||
| 目录 | 含义 | | ||
| --- | --- | | ||
| readme.md | 对该组件的描述,或帮助文档信息 | | ||
| version.md | 版本的描述,例如当前版本的更新内容等 | | ||
| publish.yaml | 项目所必须的文件,Serverless Devs Package的开发识别文档 | | ||
| src | 应用所在目录,需要包括`s.yaml`和相关的应用代码等 | | ||
此时,开发者可以在src下完成应用的开发,并对项目进行`publish.yaml`文件的编写。完成之后,即可将项目发不到不同的源,以Github Registry为例,可以在Github创建一个`Public`的仓库,并将编译后的代码放到仓库,并发布一个版本。此时,就可以通过客户端获取到该应用。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters