Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use docker build in next step of github actions after build step

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

like image 869
katakuri Avatar asked Oct 29 '25 19:10

katakuri


1 Answers

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
like image 189
Fcmam5 Avatar answered Oct 31 '25 10:10

Fcmam5