【问题标题】:I have an API which updates yaml file. I need to periodically update a yaml file which is deployed in a pipeline我有一个更新 yaml 文件的 API。我需要定期更新部署在管道中的 yaml 文件
【发布时间】:2022-02-04 21:41:01
【问题描述】:

我有一个更新 yml 文件的 API。我需要定期更新部署在管道中的 yaml 文件。 每 7 天后需要运行以下一组 shell 命令。

  1. Git 拉包。
  2. 运行调用 API 并更新包的脚本。
  3. Git 将此包推送回管道。

为此,我需要找到一项服务来安排作业(cron 作业)。我正在为此考虑 AWS Lambdas 或 DJS。 请提出任何更好的替代方案以及如何在其中使用 git。

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: git amazon-web-services aws-lambda cron pipeline


【解决方案1】:

如果您在 GitHub 上托管 yaml 文件,我建议查看 GitHub Workflows。您可以将 GitHub 操作设置为(在响应事件之后)按计划运行(请参阅here)。然后,工作流可以访问该存储库(您的包),可以进行 API 调用并推回更改。像这样的:

注意:我没有测试这个工作流程

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 作业。你可以让那个 cron-job 触发一个脚本来处理所有的步骤。如果要更新 git 存储库,则可以在服务器上使用 git,并将特定存储库用作 git 子模块。然后,脚本可以将对子模块的更改推送到其各自的存储库。

与大多数事情一样,如果它是私有的,您将需要处理身份验证等等。

【讨论】:

    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 2011-12-13
    • 2018-11-27
    • 2019-01-09
    • 2020-12-07
    • 2020-10-04
    • 2023-02-11
    • 1970-01-01
    相关资源
    最近更新 更多