Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
heimanba committed Jul 28, 2022
0 parents commit 2f7e6ec
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/registry-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish package to serverless-hub

on:
release:
types: [created]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- uses: actions/setup-node@v1
with:
node-version: 12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install requests
- name: Publish package
env:
publish_token: ${{ secrets.alibaba_registry_publish_token }}
run: |
ls
python publish.py
37 changes: 37 additions & 0 deletions publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import subprocess
import time


def getContent(fileList):
for eveFile in fileList:
try:
with open(eveFile) as f:
return f.read()
except:
pass
return None


with open('update.list') as f:
publish_list = [eve_app.strip() for eve_app in f.readlines()]

for eve_app in publish_list:
times = 1
while times <= 3:
print("----------------------: ", eve_app)
publish_script = 'https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py'
command = 'cd %s && wget %s && python hub-publish.py' % (
eve_app, publish_script)
child = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, )
stdout, stderr = child.communicate()
if child.returncode == 0:
print("stdout:", stdout.decode("utf-8"))
break
else:
print("stdout:", stdout.decode("utf-8"))
print("stderr:", stderr.decode("utf-8"))
time.sleep(3)
if times == 3:
raise ChildProcessError(stderr)
times = times + 1
12 changes: 12 additions & 0 deletions start-oss-cdn/hook/index.js
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
}
36 changes: 36 additions & 0 deletions start-oss-cdn/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Type: Application
Name: start-oss-cdn
Provider:
- 阿里云
Version: 0.0.1
Description: API 网关
HomePage: https://github.com/devsapp/start-cdn
Tags:
- Web应用
- CDN
Category: Web框架
Service: # 使用的服务
Serverless 应用引擎:
Authorities: #权限描述
- AliyunCDNFullAccess
Parameters:
type: object
additionalProperties: false # 不允许增加其他属性
required: # 必填项
- region
properties:
region:
title: 地域
type: string
default: cn-hangzhou
description: 创建应用所在的地区
enum:
- cn-beijing
- cn-hangzhou
- cn-shanghai
- cn-zhangjiakou
- cn-shenzhen
- cn-guangzhou
- cn-hongkong
- ap-southeast-1
- us-west-1
60 changes: 60 additions & 0 deletions start-oss-cdn/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 应用开发说明

<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`的仓库,并将编译后的代码放到仓库,并发布一个版本。此时,就可以通过客户端获取到该应用。
58 changes: 58 additions & 0 deletions start-oss-cdn/readme_en.md
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.
16 changes: 16 additions & 0 deletions start-oss-cdn/src/index.js
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');
};
13 changes: 13 additions & 0 deletions start-oss-cdn/src/s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范
name: functionApp # 项目名称
access: aliyun-release # 秘钥别名

vars: # 全局变量
region: "{{ region }}"
appName: "{{ appName }}"

services:
function-test: # 服务名称
component: api-gateway # 组件名称
props: # 组件的属性值
region: ${vars.region}
2 changes: 2 additions & 0 deletions start-oss-cdn/version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- 初始化项目
- 测试项目模板
1 change: 1 addition & 0 deletions update.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
start-oss-cdn

0 comments on commit 2f7e6ec

Please sign in to comment.