简体   繁体   English

您如何构建 docker 映像并将其用作 GitHub 操作中下一个作业的容器?

[英]How do you build a docker image and use it as the container for the next job in GitHub actions?

On my CI, I want to build a docker image once and then use the same image twice (or multiple times) for any following jobs, such as "test" and "lint".在我的 CI 上,我想构建一个 docker 镜像,然后对任何后续作业(例如“test”和“lint”)使用相同的镜像两次(或多次)。

  ╭─────────────╮
  │ build-image │
  ╰─────────────╯
        ⬇
 ╭──────╮ ╭──────╮
 │ test │ │ lint │
 ╰──────╯ ╰──────╯

It is possible to use a custom container using the container attribute .可以使用容器属性来使用自定义容器。 However, I'm unsure of how to make the image built in the "build-image" step accessible to that property.但是,我不确定如何使该属性可以访问在“构建图像”步骤中构建的图像。

What's the best approach to building an image and using it in the following jobs?构建图像并在以下工作中使用它的最佳方法是什么?

I was able to build the image in the first step and tag that image with the commit sha.我能够在第一步中构建图像并使用提交 sha 标记该图像。 Then, in the next step, load the container with the sha tag.然后,在下一步中,使用 sha 标签加载容器。

build-image:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
    - uses: docker/build-push-action@v1
      with:
        registry: registry
        repository: user/repo/image-name
        tags: ${{ github.sha }}
test:
  needs: [build-image]
  runs-on: ubuntu-latest
  container:
    image: registry/user/repo/image-name:${{ github.sha }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Docker 与 GitHub Actions 结合使用? - How do I use Docker with GitHub Actions? Github 操作使用 maven 构建 jar 并用于 docker 镜像构建 - Github actions build jar with maven and use for docker image building 如何使用私有 docker 镜像作为自定义 Github 操作? - How do you use a private docker image as a custom Github action? 如何在 github 操作中构建 docker-image 并将其与 k8s 一起使用? - how to build docker-image and use it with k8s in github actions? 如何将 Github 操作与具有不同架构的 Docker 容器一起使用 - How to use Github Actions with a Docker container with a different architecture 如何保存 Github Actions docker 图像的构建结果 - How can I save the build result of the Github Actions docker image 无法使用 GitHub 操作构建 Docker 映像 - Unable to Build Docker Image Using GitHub Actions 在私有 docker 容器中运行整个 GitHub 操作工作流作业 - Run entire GitHub Actions workflow job in private docker container GitHub 操作:获取所有作业命令以在 Docker 容器中运行 - GitHub Actions: Get all job commands to run in a Docker container GitHub Google Cloud Run 上的 Actions Runner 容器,可以构建 docker 映像 - GitHub Actions Runner Container on Google Cloud Run that can build docker image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM