Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Scf', () => {
}
]

const codeSrc = path.join(__dirname, '../example/event-scf/src')
const codeSrc = path.join(__dirname, '../example/event/src')
const inputs = {
name: `scf-integration-tests-${generateId()}`,
src: {
Expand Down
30 changes: 18 additions & 12 deletions docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ inputs:
key2: value2 # tags 的key value
ignoreTriggers: false # 是否忽略触发器部署
image: # 镜像配置
registryName: serverless # 容器镜像服务名称,企业版必须
namespace: scf_images # 命名空间
repositoryName: nodejs_server # 镜像名称
tagName: latest # 镜像版本
registryId: tcr-xxx # 容器镜像服务名称,企业版必须
imageType: personal # 镜像类型:personal - 个人,enterprise - 企业版,public - 镜像模板
imageUri: ccr.ccs.tencentyun.com/sls-scf/nodejs_test:latest@sha256:xxx
command: node index.js # 容器启动命名
args: test # 容器启动参数
events: # 触发器
Expand Down Expand Up @@ -500,14 +499,21 @@ value:

镜像相关配置:

| 参数名称 | 必选 | 类型 | 默认值 | 描述 |
| -------------- | ---- | ------ | -------- | :----------------------------------------------------- |
| registryName | 否 | string | | [容器镜像服务][tcr]名称,使用企业版镜像时必须 |
| namespace | 是 | string | | 命名空间 |
| repositoryName | 是 | string | | 镜像名称 |
| tagName | 否 | string | `latest` | 镜像版本 |
| command | 否 | string | | 容器启动命令,默认使用镜像中的 `Entrypoint` 或者 `CMD` |
| args | 否 | string | | 容器启动参数,默认使用惊醒中的 `CMD` |
| 参数名称 | 必选 | 类型 | 默认值 | 描述 |
| ---------- | ---- | ------ | ---------- | :----------------------------------------------------- |
| imageUrl | 是 | string | | 镜像版本 URL |
| registryId | 否 | string | | [容器镜像服务][tcr] 实例 ID,使用企业版镜像时必须 |
| imageType | 否 | string | `personal` | 镜像类型,支持:personal、enterprise、public |
| command | 否 | string | | 容器启动命令,默认使用镜像中的 `Entrypoint` 或者 `CMD` |
| args | 否 | string | | 容器启动参数,默认使用惊醒中的 `CMD` |

注意:

`imageUrl` 拼接格式为 `<仓库地址>:<镜像版本>@<镜像ID(sha256)>`,如下:

```text
ccr.ccs.tencentyun.com/sls-scf/nodejs_test:latest@sha256:xxx
```

<!-- Refer links -->

Expand Down
131 changes: 0 additions & 131 deletions example/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ tag_name="latest"

# 镜像登录密码
password="xxx"

# 镜像版本 URL
image_uri=ccr.ccs.tencentyun.com/sls-scf/nodejs_test:latest@sha256:xxx

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

在部署前,需要先构建镜像,并推送到云端镜像仓库。

首先,复制 `account.example.conf` 为 `account.conf`,并修改其中配置为开发者账号:
## 构建镜像

首先,复制 `.env.example` 为 `.env`,并修改其中配置为开发者账号:

```bash
# 主账号 UIN
UIN=123455555

# 实例 ID,企业版需要
registry_id="tcr-xxx"
# 实例名称,企业版需要
registry_name="serverless"

Expand Down Expand Up @@ -35,6 +39,10 @@ $ ./build.sh
$ ./build.sh enterprise
```

## 部署函数

镜像发布后,将需要的 `image_uri` 添加到 `.env` 文件中

然后执行 Serverless 部署:

```
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ inputs:
name: event-function-image
region: ap-chengdu
image:
registryName: ${env:registry_name}
namespace: ${env:namespace}
repositoryName: ${env:image_name}
tagName: ${env:tag_name}
imageType: enterprise
registryId: ${env:registry_id} # 请修改为指定容器镜像服务实例 ID
imageUrl: ${env:image_url} # 请修改为指定镜像版本 URL
events:
- apigw:
parameters:
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions example/image-scf/.env.example → example/image/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ tag_name="latest"

# 镜像登录密码
password="xxx"

# 镜像版本 URL
image_uri=ccr.ccs.tencentyun.com/sls-scf/nodejs_test:latest@sha256:xxx
File renamed without changes.
17 changes: 15 additions & 2 deletions example/image-scf/README.md → example/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

在部署前,需要先构建镜像,并推送到云端镜像仓库。

首先,复制 `account.example.conf` 为 `account.conf`,并修改其中配置为开发者账号:
## 构建镜像

首先,复制 `.env.example` 为 `.env`,并修改其中配置为开发者账号:

```bash
# 主账号 UIN
UIN=123455555

# 实例 ID,企业版需要
registry_id="tcr-xxx"
# 实例名称,企业版需要
registry_name="serverless"

# 命名空间
namespace="sls-scf"
# 镜像名称
image_name="nodejs_test"
image_name="nodejs_test_event"
# 镜像版本
tag_name="latest"

# 镜像登录密码
password="xxx"
Expand All @@ -30,6 +39,10 @@ $ ./build.sh
$ ./build.sh enterprise
```

## 部署函数

镜像发布后,将需要的 `image_uri` 添加到 `.env` 文件中

然后执行 Serverless 部署:

```
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ inputs:
# 指定 SCF 类型为 Web 类型
type: web
image:
# registryName: ${env:registry_name} # 企业版必须
namespace: ${env:namespace}
repositoryName: ${env:image_name}
tagName: ${env:tag_name}
imageType: personal
imageUrl: ${env:image_url} # 请修改为指定镜像版本 URL
events:
- apigw:
parameters:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ inputs:
endpoints:
- path: /
method: ANY
function:
# 指定 API 类型为 Web 类型
type: web
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: scf
version: 0.7.1
version: 0.7.2
author: Tencent Cloud, Inc.
org: Tencent Cloud, Inc.
description: Deploy a serverless cloud function on Tencent Cloud.
Expand Down
28 changes: 8 additions & 20 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const download = require('download')
const { Cos, Tcr } = require('tencent-component-toolkit')
const { Cos } = require('tencent-component-toolkit')
const { ApiTypeError } = require('tencent-component-toolkit/lib/utils/error')
const CONFIGS = require('./config')

Expand Down Expand Up @@ -165,32 +165,20 @@ const formatInputs = async (instance, credentials, appId, inputs) => {
let imageCode
if (inputs.image) {
const imageConfig = inputs.image
const region = inputs.region || CONFIGS.region
const tcr = new Tcr(credentials, region)
// 企业版需要配置 registryName (实例名称)
if (imageConfig.registryName) {
const imageInfo = await tcr.getImageInfoByName({
registryName: imageConfig.registryName,
namespace: imageConfig.namespace,
repositoryName: imageConfig.repositoryName,
tagName: imageConfig.tagName || 'latest'
})
if (imageConfig.registryId) {
imageCode = {
imageType: imageInfo.imageType,
imageUri: imageInfo.imageUri,
registryId: imageInfo.registryId,
imageType: 'enterprise',
// yaml 配置使用 imageUrl 方便理解
imageUri: imageConfig.imageUrl,
registryId: imageConfig.registryId,
command: imageConfig.command,
args: imageConfig.args
}
} else {
const imageInfo = await tcr.getPersonalImageInfo({
namespace: imageConfig.namespace,
repositoryName: imageConfig.repositoryName,
tagName: imageConfig.tagName || 'latest'
})
imageCode = {
imageType: imageInfo.imageType,
imageUri: imageInfo.imageUri,
imageType: imageConfig.imageType || 'personal',
imageUri: imageConfig.imageUrl,
command: imageConfig.command,
args: imageConfig.args
}
Expand Down