[英]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.