【问题标题】:Is there a way to put a lock on Concourse git-resource?有没有办法锁定 Concourse git-resource?
【发布时间】:2019-05-19 17:33:04
【问题描述】:

我在 Concourse 中设置了管道,其中包含一些构建 Docker 映像的工作。 构建后,我将图像标签推送到 git 存储库。 问题是当构建同时结束时,一个作业推送到 git,而另一个只是拉动,当第二个作业尝试推送到 git 时,它会出错。

error: failed to push some refs to 'git@github.com:*****/*****'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

那么有什么办法可以防止并发推送呢?

到目前为止,我已经尝试将serialserial_groups 应用于工作。 它有帮助,但是所有的工作都排队了,因为我们有很多构建。

如果其他作业锁定了它,我希望作业在对 git 执行操作之前同时运行并暂停。

resources:
- name: backend-helm-repo
  type: git
  source:
    branch: master
    paths:
    - helm
    uri: git@github.com:******/******
-...

jobs:

-...

- name: some-hidden-api-build
  serial: true
  serial_groups:
  - build-alone
  plan:
  - get: some-hidden-api-repo
    trigger: true
  - get: golang
  - task: build-image
    file: somefile.yaml
  - put: some-hidden-api-image
  - get: backend-helm-repo
  - task: update-helm-tag
    config:
      platform: linux
      image_resource:
        type: registry-image
        source:
          repository: mikefarah/yq
          tag: latest
      run:
        path: /bin/sh
        args:
        - -xce
        - "file manipulations && git commit"
      inputs:
      - name: some-hidden-api-repo
      - name: backend-helm-repo
      outputs:
      - name: backend-helm-tag-bump
  - put: backend-helm-repo
    params:
      repository: backend-helm-tag-bump
  - put: some-hidden-api-status
    params:
      commit: some-hidden-api-repo
      state: success


- name: some-other-build
  serial: true
  serial_groups:
  - build-alone
  plan:
  - get: some-other-repo
    trigger: true
  - get: golang
  - task: build-image
    file: somefile.yaml
  - put: some-other-image
  - get: backend-helm-repo
  - task: update-helm-tag
    config:
      platform: linux
      image_resource:
        type: registry-image
        source:
          repository: mikefarah/yq
          tag: latest
      run:
        path: /bin/sh
        args:
        - -xce
        - "file manipulations && git commit"
      inputs:
      - name: some-other-repo
      - name: backend-helm-repo
      outputs:
      - name: backend-helm-tag-bump
  - put: backend-helm-repo
    params:
      repository: backend-helm-tag-bump
  - put: some-other-status
    params:
      commit: some-other-repo
      state: success

-...

因此,如果作业同时完成映像构建并并行执行 git commit,则第一个推送比第二个更快,第二个会中断。

有人可以帮忙吗?

【问题讨论】:

  • 如果 pool-resource 是您正在寻找的并且足够了,那么请接受我的回答。如果没有,请随时询问详细信息。

标签: concourse concourse-git-resource


【解决方案1】:

请注意,您的描述过于模糊,无法给出详细答案。

如果其他作业锁定了 git,我希望作业在推送到 git 之前同时停止。

这还不够,如果他们在推送之前停止,他们已经在引用一个 git 提交,当另一个作业释放锁时,它会变得陈旧:-)

在克隆 git repo 之前,作业必须停止,等待锁,所以一开始就这样做。

所有这一切都是我的猜测,因为同样不清楚你想做什么,对于这些发布尽可能小的管道图像和尽可能小的配置代码的问题是有帮助。

您可以将https://github.com/concourse/pool-resource 视为锁定机制。

【讨论】:

  • 我想我可以在 git clone 之前暂停一下,因为我是在构建镜像之后在这个 repo 上运行 get 的。我添加了管道描述,但我认为 pool-resource 是我正在寻找的,谢谢!
猜你喜欢
  • 1970-01-01
  • 2011-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-16
  • 1970-01-01
  • 2018-03-13
  • 1970-01-01
相关资源
最近更新 更多