我有一个 API 更新 yaml 文件。我需要定期更新部署在管道中的 yaml 文件
I have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipeline
我有一个 API 可以更新 yml 文件。我需要定期更新部署在管道中的 yaml 文件。
以下一组 shell 命令需要每 7 天 运行。
- Git拉包
- 运行 调用 API 并更新包的脚本。
- Git 将此包推回管道。
为此,我需要找到一个服务来安排作业(cron 作业)。为此,我正在考虑使用 AWS Lambdas 或 DJS。
请提出任何更好的选择,以及我如何在其中使用 git。
如果您在 GitHub 上托管 yaml
文件,我建议您查看 GitHub Workflows. You can set GitHub actions to (next to respond to events) run on a schedule (see here)。然后,工作流可以访问该存储库(您的包),可以进行 API 调用并推回更改。像这样:
NOTE: I did not test this workflow
name: Trigger API update
on:
schedule:
- cron: "0 6 * * *" # run everyday at six
jobs:
ping_api_and_update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Webhook
uses: distributhor/workflow-webhook@v2
env:
webhook_url: ${{ secrets.API_URL }}
webhook_secret: ${{ secrets.API_SECRET }}
- name: do something with output
run: |
command based on API result
maybe another command
edit the yaml file in this repo
shell: bash
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
id: commit
with:
commit_message: Auto-update YAML
commit_author: CI/CD <actions@github.com>
或者,大多数(例如 linux)服务器可以处理 cron-jobs。您可以让 cron-job 触发脚本来处理所有步骤。如果你想更新一个 git 存储库,你可以在你的服务器上使用 git,并将特定的存储库作为一个 git 子模块。然后脚本可以将对子模块的更改推送到其各自的存储库。
与大多数事情一样,如果它是私有的,您将需要处理身份验证等等。
我有一个 API 可以更新 yml 文件。我需要定期更新部署在管道中的 yaml 文件。 以下一组 shell 命令需要每 7 天 运行。
- Git拉包
- 运行 调用 API 并更新包的脚本。
- Git 将此包推回管道。
为此,我需要找到一个服务来安排作业(cron 作业)。为此,我正在考虑使用 AWS Lambdas 或 DJS。 请提出任何更好的选择,以及我如何在其中使用 git。
如果您在 GitHub 上托管 yaml
文件,我建议您查看 GitHub Workflows. You can set GitHub actions to (next to respond to events) run on a schedule (see here)。然后,工作流可以访问该存储库(您的包),可以进行 API 调用并推回更改。像这样:
NOTE: I did not test this workflow
name: Trigger API update
on:
schedule:
- cron: "0 6 * * *" # run everyday at six
jobs:
ping_api_and_update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Webhook
uses: distributhor/workflow-webhook@v2
env:
webhook_url: ${{ secrets.API_URL }}
webhook_secret: ${{ secrets.API_SECRET }}
- name: do something with output
run: |
command based on API result
maybe another command
edit the yaml file in this repo
shell: bash
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
id: commit
with:
commit_message: Auto-update YAML
commit_author: CI/CD <actions@github.com>
或者,大多数(例如 linux)服务器可以处理 cron-jobs。您可以让 cron-job 触发脚本来处理所有步骤。如果你想更新一个 git 存储库,你可以在你的服务器上使用 git,并将特定的存储库作为一个 git 子模块。然后脚本可以将对子模块的更改推送到其各自的存储库。
与大多数事情一样,如果它是私有的,您将需要处理身份验证等等。