如何在Bitbucket管道中使用Docker撰写V2

发布于 2025-02-10 04:48:12 字数 433 浏览 1 评论 0 原文

传统上,我一直在

pip install docker-compose

管道脚本中发布指示,以便需要进行集成测试。

这很方便,因为它与Bitbucket的Docker Service提供的Docker二进制文件完美无缺,并且可以从PIP CACHE中受益,因为我已经在这些步骤中使用了Python图像。但是我宁愿使用最新的软件,因此我正在寻找安装Docker-Compose V2的机制。

理想情况下,该解决方案

  • 不应安装另一个Docker二进制文件,而是重复使用Bitbucket的Docker服务提供的解决方案
  • 不需要特定的运行时(与V1不同的是需要Python)
  • 受益于某种缓存,以避免在每个管道上下载Complose插件。

有人在解决这个问题吗?您的经验是什么?

Traditionally, I had been issuing

pip install docker-compose

instructions in my pipelines scripts for steps needing it, usually for integration tests.

This was convenient because it operates flawlessly with the docker binary provided by Bitbucket's docker service, and benefits from the pip cache since I am already using python images for those steps. But I'd rather work with up-to-date software, so I am looking for mechanisms to install docker-compose V2.

Ideally, the solution should

  • not install another docker binary, but reuse the one provided by Bitbucket's docker service
  • not require a specific runtime (unlike V1 requiring python)
  • benefit from some kind of cache to avoid downloading the compose plugin on every single pipeline.

Is anyone addressing this? What's your experience?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆里有你的影子 2025-02-17 04:48:12

使其正常工作的一种方法是从Github下载最新版本,将其放入〜/.docker/cli-Plugins中,然后缓存此文件夹。

definitions:
  caches:
    docker-cliplugins: ~/.docker/cli-plugins
  yaml-anchors:
    - &setup-docker-compose-latest-script >-
        wget --no-verbose --no-clobber https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 --output-document ~/.docker/cli-plugins/docker-compose
        || true
        ; chmod a+x ~/.docker/cli-plugins/docker-compose
        && ln --symbolic ~/.docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
pipelines:
  default:
    - step:
        services: [docker]
        caches: [docker-cliplugins]
        script:
          - *setup-docker-compose-latest-script
          - docker compose version

这需要 WGET -no-Clobber 从缓存中受益。

理想情况下,这可以用管道以可重复使用的方式完成,就像您使用“设置” github动作一样。但是,由于管道仅安装了克隆目录,而不是整个代理,因此您有此YAML锚。

One way to get it working is to download the latest release from github, place it in ~/.docker/cli-plugins and cache this folder.

definitions:
  caches:
    docker-cliplugins: ~/.docker/cli-plugins
  yaml-anchors:
    - &setup-docker-compose-latest-script >-
        wget --no-verbose --no-clobber https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 --output-document ~/.docker/cli-plugins/docker-compose
        || true
        ; chmod a+x ~/.docker/cli-plugins/docker-compose
        && ln --symbolic ~/.docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
pipelines:
  default:
    - step:
        services: [docker]
        caches: [docker-cliplugins]
        script:
          - *setup-docker-compose-latest-script
          - docker compose version

This needs wget --no-clobber to benefit from the cache.

Ideally this could be done in a reusable way with a pipe, just like you would with "setup" github actions. But because pipes are only mounted the clone directory and not the whole agent, here you have this yaml anchor.

帅气尐潴 2025-02-17 04:48:12

您可以使用atlassian/default-image:4,它已经安装了Docker组成V2:

image: atlassian/default-image:4
pipelines:
  default:
    - parallel:
        - step:
            name: Unit Tests
            services:
              - docker
            caches:
              - docker
              - pip
            script:
              - export DOCKER_BUILDKIT=0
              - source .env_example
              - docker-compose build

You can use atlassian/default-image:4, it already has docker compose V2 installed: https://hub.docker.com/r/atlassian/default-image/

image: atlassian/default-image:4
pipelines:
  default:
    - parallel:
        - step:
            name: Unit Tests
            services:
              - docker
            caches:
              - docker
              - pip
            script:
              - export DOCKER_BUILDKIT=0
              - source .env_example
              - docker-compose build

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文