螺旋部署
一个用于运行在AWS Lambda,Adobe I/O Runtime,Azure函数,Google Cloud函数,Cloudflare Workers,和快速计算@Edge上的服务器和边缘计算函数的多云部署工具. 写一次,到处跑.
状态
设置
-
将此包页添加为 dev 依赖 :
# Add OpenWhisk wrapper as dependency npm add helix-deploy -
在您的软件包中添加构建脚本。 json:
"scripts": { "build": "./node_modules/.bin/hedy" } -
构建 OpenWhisk 动作
$ npm run build ... Created action: dist/my-example.zip. -
部署 OpenWhisk 动作
$ wsk action update ....
部署参数可在CLI中通过 -p. 见下文.
发展中国家
- 安装依赖性一次
npm install。 。 。 . - 运行天线通过
npm run lint。 。 。 . - 运行单元测试套件
npm test。脚本运行c8 mocha -i -g Integration,因此明确标记为"整合"的测试被跳过.
国 际
命令行接口 hedy 可以通过 ./node_modules/.bin/hedy。 。 。 .
您也可以使用 npx: npx hedy 或在全球安装 npm install -g helix-deploy。 。 。 .
$ hedy --help
General Options
-v, --verbose [boolean] [default: false]
--directory Project directory [string] [default: "."]
--version Show version number [boolean]
Operation Options
--help Show help [boolean]
--build Build the deployment package [boolean] [default: true]
--deploy Automatically deploy to specified targets [boolean] [default: false]
--test Invoke action after deployment. Can be relative url or "true" [string]
--test-bundle Invoke bundle after build. Can be relative url or "true". Defaults to the same as --test [string]
--update-package Create or update package with params. [boolean] [default: false]
-l, --version-link Create symlinks (sequences) after deployment. "major" and "minor" will create respective version links [array]
--delete Delete the action from OpenWhisk. Implies no-build [boolean] [default: false]
--plugin Specify bundler or deploy plugins. [array] [default: []]
Build Options
--minify Minify the final bundle [boolean] [default: false]
-s, --static Includes a static file into the archive [array] [default: []]
--entryFile Specifies the entry file (the universal function). [default: "src/index.js"]
--externals Defines the externals for the bundler (these dependencies will not be bundled). [array] [default: []]
--edge-externals Defines the externals for the edge bundler (these dependencies will not be bundled for Cloudflare or Fastly). [array] [default: []]
--serverless-externals Defines the externals for the serverless bundler (these dependencies will not be bundled for AWS Lambda or Google Cloud Functions). [array] [default: []]
-m, --modules Include a node_module as is. [array] [default: []]
--adapterFile Specifies the adapter file (the exported module).
--esm Produce EcmaScript Module (experimental, disables edge arch) [boolean] [default: false]
--bundler
--dist-directory Specifies the dist (output) directory [default: "dist"]
Deploy Options
--target Select target(s) for test, deploy, update-package actions (wsk,aws,google,auto) [array] [default: ["auto"]]
--hints, --no-hints Show additional hints for deployment [boolean] [default: true]
Test Options
--target Select target(s) for test, deploy, update-package actions (wsk,aws,google,auto) [array] [default: ["auto"]]
--test-params Invoke openwhisk action after deployment with the given params. [array] [default: []]
--test-url Test url to use after deployment, in case --test is not an url. [string]
--test-headers Test headers to send in test requests. [array] [default: []]
Link Options
--target Select target(s) for test, deploy, update-package actions (wsk,aws,google,auto) [array] [default: ["auto"]]
--linkPackage Package name for version links [string]
Update Package Options
--package.params OpenWhisk package params. [array] [default: []]
--package.params-file OpenWhisk package params file. [array] [default: []]
Cleanup Old Deployments: automatically delete redundant versions older than specified.
Use a pattern like 7d or 1m to specify time frames.
Use a simple number like --cleanup-ci=5 to retain the last five CI builds
--cleanup-ci Automatically delete redundant CI versions
--cleanup-patch Automatically delete redundant patch versions. At least one patch version for each minor version will be kept.
--cleanup-minor Automatically delete redundant minor versions. At least one minor version for each major version will be kept.
--cleanup-major Automatically delete redundant major versions.
General Action Options
--name Action name. Can be prefixed with package.
--package.name Action package name. [string]
--node-version Specifies the node.js version to use in the serverless runtime [default: "18"]
-p, --params Include the given action param. can be json or env. [array] [default: []]
-f, --params-file Include the given action param from a file; can be json or env. [array] [default: []]
--updated-by user that updated the action or sequence. [string]
--updated-at unix timestamp when the action or sequence was updated (defaults to the current time). [number] [default: 1719567952628]
--web-secure Annotates the action with require-whisk-auth. leave empty to generate random token. [string]
-t, --timeout the timeout limit in milliseconds after which the action is terminated [default: 60000]
--pkgVersion Version use in the embedded package.json.
--memory the maximum memory LIMIT in MB for the action
--concurrency the maximum intra-container concurrent activation LIMIT for the action
OpenWhisk Action Options
--namespace OpenWhisk namespace. Needs to match the namespace provided with the openwhisk credentials.
--package.shared OpenWhisk package scope. [boolean] [default: false]
AWS Deployment Options
--aws-region the AWS region to deploy lambda functions to [string] [default: ""]
--aws-api the AWS API Gateway name. (id, "auto" or "create") [string] [default: "auto"]
--aws-role the AWS role ARN to execute lambda functions with [string] [default: ""]
--aws-cleanup-buckets
--aws-cleanup-integrations Cleans up unused integrations [boolean] [default: false]
--aws-cleanup-versions Cleans up unused versions [boolean] [default: false]
--aws-create-routes Create routes for function (usually not needed due to proxy function). [boolean] [default: false]
--aws-link-routes Create or update routes, integrations, permissions, and authorizers when linking versions. [boolean] [default: true]
--aws-create-authorizer Creates API Gateway authorizer using lambda authorization with this function and the specified name. The string can contain placeholders (note that all dots ('.') are replaced with underscores. Example: "helix-authorizer_${version}". [string]
--aws-attach-authorizer Attach specified authorizer to routes during linking. [string]
--aws-lambda-format Format to use to create lambda functions (note that all dots ('.') will be replaced with underscores. [string] [default: "${packageName}--${baseName}"]
--aws-parameter-manager Manager to use for storing package params. (either "secret" for Secrets Manager or "system" for System Manager) [array] [default: ["secret"]]
--aws-deploy-template
--aws-arch deployment architecture. either 'x86_64' or 'arm64' [string] [default: "x86_64"]
--aws-update-secrets Uploads the function specific secrets with the params. defaults to /helix-deploy/{pkg}/{name} [string]
--aws-deploy-secrets Name of a secret in the target account (in AWS Secrets Manager) holding the HLX_AWS_* environment variables to use for the deployment. [string]
--aws-deploy-bucket Name of the deploy S3 bucket to use (default is helix-deploy-bucket-{accountId}) [string] [default: ""]
--aws-identity-source Identity source to used when creating the authorizer [array] [default: ["$request.header.Authorization"]]
--aws-log-format The lambda log format. Can be either "JSON" or "Text". [string]
--aws-layers List of layers ARNs to attach to the lambda function. [array]
--aws-tracing-mode The lambda tracing mode. Can be either "Active" or "PassThrough". [string]
--aws-extra-permissions A list of additional invoke permissions to add to the lambda function in the form <SourceARN>@<Principal>. Optionally, you can use <SourceARN>@<Principal>:<Alias> if you want to scope the permission to a specific alias. [array]
--aws-tags A list of additional tags to attach to the lambda function in the form key=value. To remove a tag, use key= (i.e. without a value). [array]
--aws-handler Set custom lambda Handler. For example, set if an AWS layer provides another function entry point. [string]
--aws-ephemeral-storage Size of the Lambda /tmp ephemeral storage in MB (512-10240). [number] [default: 512]
--aws-vpc-subnet-ids List of VPC subnet IDs to attach the Lambda function to. [array]
--aws-vpc-security-group-ids List of VPC security group IDs to attach the Lambda function to. [array]
Google Deployment Options
--google-project-id the Google Cloud project to deploy to. Optional when the key file is a JSON file [string] [default: ""]
--google-key-file full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console [string] [default: ""]
--google-email the Google account email address. Required when using a .pem or .p12 credential file [string] [default: ""]
Options:
--arch Select archs(s) for bundles (node,edge). [array] [default: ["node"]]
--format Action formats [default: {"aws":"/${packageName}/${baseName}/${version}"}]
--property Additional properties that can be used in formats. [default: {}]
--package-token Protects access to the gateway-stored package parameters with this token. leave empty to generate random token. [string] [default: "2l8JumQIoX+SLQRc2eO2TUh1VO44/qh9KkL7VZO1T9k="]
--google-region the Google Cloud region to deploy in [string] [default: ""]
没有争论 hedy 将代码捆入相应的 action.zip数字 :
自动部署到开怀斯克
当得到 --deploy,则 wskbot 将尝试使用来自
~/.wskprops或者,您也可以设置 WSK_NAMESPACE, (中文(简体) ), WSK_AUTH, (中文(简体) ), WSK_APIHOST 在你身边
环境或环境 .env 文档.
$ hedy --deploy --no-hints
ok: created action: dist/my-example.zip.
ok: updated action tripod/my-example
自动 测试 已部署的行动
为了快速测试部署的行动, hedy 可以发送 GET 请求动作 url.
$ hedy --deploy --no-hints --test
ok: created action: dist/my-example.zip.
ok: updated action tripod/my-example
--: requesting: https://runtime.adobe.io/api/v1/web/tripod/default/my-example ...
ok: 200
页:1 --test 参数可以是相对的url,以防请求不应针对root url, 如:
$ hedy --deploy --no-hints --test=/ping
ok: created action: dist/my-example.zip.
ok: updated action tripod/my-example
--: requesting: https://runtime.adobe.io/api/v1/web/tripod/default/my-example/ping ...
ok: 200
包括行动参数
行动参数可通过 -p,或者作为json 在env字符串, 或json或env文件.
实例:
# specify as env string
hedy -p MY_TOKEN=1234 -p MY_PWD=foo
# specify as json string
hedy -p '{ "MY_TOKEN": 1234, "MY_PWD": "foo" }'
# specify as env file
hedy -f .env
# specify as json file
hedy -f params.json
# and a combination of the above
hedy -f .env -f params.json -p MY_TOKEN=123
# like in curl, you can include file contents with `@` (also works in .env or .json file)
hedy -p [email protected]
在 package.json
您不通过命令行传递所有参数, 也可以在 package.json
输入 hlx 对象
{
...
"scripts": {
"build": "./node_modules/.bin/hedy -v",
"deploy": "./node_modules/.bin/hedy -v --deploy --test"
},
"hlx": {
"name": "my-test-action",
"params-file": [
"secrets/secrets.env"
],
"externals": [
"fs-extra",
"js-yaml",
"dotenv",
"bunyan",
"bunyan-loggly",
"bunyan-syslog",
"bunyan-format"
],
"docker": "adobe/probot-ow-nodejs8:latest"
},
...
}
配置名称改为 hlx 版本中 12.3上一个名称 wsk 仍然被支持,但贬值。 如果两者都在场, hlx 将被使用.
修改您的动作
将动作名称与 @version 标注. 比如说
"hlx": {
"name": "[email protected]"
}
为了自动使用版本 package.json 使用:
"hlx": {
"name": "my-action@${version}"
}
说明:该版本从内部取自
pkgVersion变量,因此可以用 页:1--pkgVersion理由,如果应用不同,则采用不同方法.
参数中的环境变量内插
计外 ${version} 参数将使用存在变量的环境变量进行插值。 例如,给定一个命名的环境变量 PROBOT_DOCKER_VERSION 设置为 latest,此配置 :
{
...
"hlx": {
...
"docker": "adobe/probot-ow-nodejs8:${env.PROBOT_DOCKER_VERSION}"
},
...
}
将实现 docker 设置为 adobe/probot-ow-nodejs8:latest。 。 。 .
自动创建语义版本序列动作
通过使用 --version-link (单位:千美元)-l),而起步器可以创建动作序列 链接 到部署的版本,
使用语义版本标记: latest, (中文(简体) ), major, (中文(简体) ), minor数字 :
| 动作名称 | 指定者 | 序列名称 |
|---|---|---|
[email protected] | latest | foo@latest |
[email protected] | major | foo@v2 |
[email protected] | minor | [email protected] |
包括静态文件
添加静态文件, 即未从中引用的文件 index.js 被网包检测到,
可以通过 -s 参数。 它们总是被放入档案的根目录.
示例
# include an image
hedy -s logo.png
如果路径指向一个目录,则会递归包含.
静态文件的文件也可以在 package.json 它允许指定
目标文件名 。 例如:
...
"hlx": {
...
"static": [
"config.json",
["assets/logo.png", "static/icon.ong"],
["public/", "static/"],
]
}
...
使用插件
Helix 部署支持可以通过 --plugin 参数。 插件
可导出一个 bundler 和(或) deployer 函数。 例如,以下插件可用于
部署到边缘计算平台 : https://github.com/adobe/helix-deplog-plugin-edge 页面存档备份,存于互联网档案馆
hedy --plugin @adobe/helix-deploy-plugin-edge --deploy
使用开发服务器
测试通用函数可以用 开发服务器。 。 。 .
只要创建一个 test/dev.js 文件为 :
import { DevelopmentServer } from '@adobe/helix-universal-devserver';
import { main } from '../src/index.js';
async function run() {
const devServer = await new DevelopmentServer(main).init();
await devServer.start();
}
run().then(process.stdout).catch(process.stderr);
运行 node test/dev.js。 。 。 .
更多信息请参见 https://github.com/adobe/helix-universal-devserver 页面存档备份,存于互联网档案馆
页:1
捆绑
动作是使用 Web 包创建源代码捆绑, 然后创建 zip 归档
与捆绑,a package.json,私钥文件和 .env。 。 。 .
捐款
如果您对如何改进这些 OpenWhisk 动作工具有建议, 或是想要报告错误, 请打开一个问题 ! 我们很乐意所有的贡献.
更多,请检查 贡献指南。 。 。 .