英文:
How to use docker build in next step of github actions after build step
问题
以下是我使用的GHA工作流程YAML文件示例。当前,我正在构建并推送Docker镜像到存储库。在接下来的步骤中,我会在Docker镜像上运行pytest。但在下一步中,它必须拉取上一步构建的镜像才能运行pytest。是否有办法可以在不从存储库拉取Docker镜像的情况下运行pytest以节省时间。
- name: Build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: my_registry:${{ github.run_number }}
cache-from: |
type=registry,ref=my_registry:cache
cache-to: |
type=registry,ref=my_registry:cache,mode=max
- name: Pytest
run: docker run my_registry:${{ github.run_number }} pytest
(Note: The code section is not translated as per your request.)
英文:
following is the example GHA workflow yaml file I'm using. Currently I'm building an pushing docker image to artifact registry. And in the next step I run pytest on the docker image. But for next step it has to pull image which was build in the last step to run pytest. Is there any way I can run pytest without pulling the docker image from registry to save time.
- name: Build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: my_registry:${{ github.run_number }}
cache-from: |
type=registry,ref=my_registry:cache
cache-to: |
type=registry,ref=my_registry:cache,mode=max
- name: Pytest
run: docker run my_registry:${{ github.run_number }} pytest
答案1
得分: 2
请看操作示例,了解如何在作业之间共享Docker镜像。
该操作提供了一个outputs
参数:
输出目标列表(格式:
type=local,dest=path
)。注:目前不支持多个
outputs
。
您可以使用它将您的镜像输出到一个tar文件,然后在下一步中加载它。
示例:
- name: 构建
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: my_registry:${{ github.run_number }}
cache-from: |
type=registry,ref=my_registry:cache
cache-to: |
type=registry,ref=my_registry:cache,mode=max
outputs: type=docker,dest=./myimage.tar
- name: Pytest
run: |
docker load --input ./myimage.tar
docker run my_registry:${{ github.run_number }} pytest
英文:
Have a look at the actions's example on how to share a docker image between jobs.
The action offers an outputs
¹ argument:
> List of output destinations (format: type=local,dest=path
).
>
> ¹ multiple outputs
are not yet supported
You can use it to output your image to a tar file which you can load in the next step.
Example:
- name: Build
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: my_registry:${{ github.run_number }}
cache-from: |
type=registry,ref=my_registry:cache
cache-to: |
type=registry,ref=my_registry:cache,mode=max
outputs: type=docker,dest=./myimage.tar
- name: Pytest
run: |
docker load --input ./myimage.tar
docker run my_registry:${{ github.run_number }} pytest
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论