docker/build-push-action

Example for Cache-Froms option

Closed this issue · 2 comments

robpc commented

Can an example of how to use the cache-froms option in a github workflow be added to the documentation? I was unable to figure out a way to use it that actually took advantage of the option. Looking at the go utility 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 and the original issue asks for that as well. I did some testing and was unable to get it to work. It was indistinguishable from not using it.

- 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 }}

My original comment from the original issue.

Unless this feature works with service it makes very little sense to use it to us if we require cache-from. I think we have the correct understanding how it should be used, but it looks very ugly.

    steps:
      - uses: actions/checkout@v2
      - name: Login to docker.pkg.github.com
        run: docker login -u $GITHUB_ACTOR -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
      - name: Pull cache from docker.pkg.github.com
        run: docker pull docker.pkg.github.com/$GITHUB_REPOSITORY/build-cache || true
      - uses: docker/build-push-action@v1
        with:
          username: hholst80
          password: ${{ secrets.DOCKER_PASSWORD }}
          repository: hholst80/test
          tags: latest
          cache_froms: docker.pkg.github.com/$GITHUB_REPOSITORY/build-cache
      - name: Tag new cache image
        run: docker tag hholst80/test:latest docker.pkg.github.com/$GITHUB_REPOSITORY/build-cache
      - name: Push cache to docker.pkg.github.com
        run: docker push docker.pkg.github.com/$GITHUB_REPOSITORY/build-cache

Version 2 has been merged to the main branch and is therefore available via uses: docker/build-push-action@v2 (mutable tag).

As a reminder, this new version changes drastically and works with 3 new actions (login, setup-buildx and setup-qemu) that we have created. Many usage examples have been added to handle most use cases.

About this current issue, take a look at the Leverage GitHub cache section in the README and also buildx README about cache.

Don't hesitate if you have any questions.