Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage docker cache #7

Closed
2m opened this issue Mar 17, 2020 · 11 comments
Closed

Leverage docker cache #7

2m opened this issue Mar 17, 2020 · 11 comments

Comments

@2m
Copy link

2m commented Mar 17, 2020

Would it possible to add support for using docker cache?

Especially for PR validation, it would be great if it would be possible to specify a docker image that would be used for resolving layer cache. That image name would be passed to a docker build option:

--cache-from strings      Images to consider as cache sources

Also the image should be pulled from the registry first.

@volkyeth
Copy link

volkyeth commented Apr 7, 2020

Is there any workaround using just this action, or maybe using https://github.com/actions/cache?

@rickclare
Copy link

When (and if) the following PR#17 from docker/github-actions is merged, will this help with this request?

docker/github-actions#17

@appleboy
Copy link

@2m @rickclare Already merged. You should close this issue.

@zappy-shu
Copy link
Contributor

Note that though the backend image has been released I am still waiting on approval of the updated docs to release the action with the new input. Pushing to get this done ASAP.

Thank you for your contribution @appleboy

@brahmlower
Copy link

brahmlower commented Apr 22, 2020

Until the action is updated, the cache-from arg can be used via the INPUT_CACHE_FROMS env var that was added. The cache-from documentation indicates the cached image is only used if was built using the build arg BUILDKIT_INLINE_CACHE=1. A rough example of what I've tried is:

- name: build and push docker image
  uses: docker/build-push-action@v1
  env:
    INPUT_CACHE_FROMS: myregistry/myimage
  with:
    ...
    build_args: BUILDKIT_INLINE_CACHE=1

I'm pretty sure that should work, however I haven't had much luck with it. I'm using a multi-stage build, which the cache-from docs say requires cache manifests generated by buildctl rather than the resulting image, so I'm pretty sure my example above would work non-mulit-stage build.

I figured this was worth mentioning in case others who find this issue are relatively new to the cache-from feature like myself 😄

@zappy-shu
Copy link
Contributor

Merged and released. You can either use docker/build-push-action@v1 or use docker/build-push-action@v1.1.0 to use the new cache_froms input.

@robpc
Copy link

robpc commented May 8, 2020

Can we have an example of how to use this option? Looking at the go code, it just adds the option to the build command, but that will do nothing when there is no local cache (ie a CB scenario like this). In my experience you need to pull the image first, so was hoping that this change did that as well. I did some testing with this action and was unable to get it to work which was consistent with that conclusion.

- name: Docker Build
  uses: docker/build-push-action@v1
  with:
    registry: quay.io
    repository: ${{ env.quayio_repo }}
    username: ${{ env.quayio_user }}
    password: ${{ secrets.QUAY_AUTH }}
    tags: >-
      ${{ env.docker_tag }},
      ${{ env.docker_cache_tag }}
    cache_froms: ${{ env.quayio_repo }}:${{ env.docker_cache_tag }}

Edit: Tried several variations including cache_froms: quay.io/${{ env.quayio_repo }}:${{ env.docker_cache_tag }} with no success

Edit2: PR for utility in docker image docker/github-actions#17

@princemaple
Copy link

@robpc looks like you have to pull the cache_from image first.

@robpc
Copy link

robpc commented May 20, 2020

@princemaple That was my conclusion, but my question is how to do that with this action.

@princemaple
Copy link

@robpc I used another one to login, run pull, then used this one to do the build. Did the job. Not sure if there is a better way though.

@robpc
Copy link

robpc commented May 26, 2020

If you use another action to authenticate and pull then I am not sure why you wouldn't use that one to build and push as well. Since this comment hasn't gotten attention from the maintainers (understandable since the issue is closed), I will create a new issue requesting an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants