cache icon indicating copy to clipboard operation
cache copied to clipboard

Adjust storage warning

Open Napster134 opened this issue 1 year ago • 1 comments

Description

There's an issue with the total expected cache size warning/error when using buildjet cache which is a fork from this repo. To avoid there being any discrepancies between the actual allowed cache size and the size mentioned within the error message, I moved the limit into it's own variable and added the limit variable into the error message.

This is the message that I see when using buildjets cache:

Screenshot 2024-02-13 at 8 54 45 AM
Warning: Failed to save: Cache size of ~6148 MB (6446280578 B) is over the 10GB limit, not saving cache.
Cache saved with key: docker-image-cache4-Linux

The actual limit is 4.99 GB. The message states 10GB is the limit.

However, if I switch the caching action to use: runs-on: ubuntu-latest along with uses: actions/cache@v4 then it works as expected. Example:

Screenshot 2024-02-13 at 8 45 41 AM

Working:

    ---
    name: Test 
    
    on: [ pull_request ]
    
    permissions:
      id-token: write
      contents: read
    
    jobs:
      test:
        env:
          CI: true
    
        runs-on: ubuntu-latest
    
        steps:
          - name: Free Disk Space (Ubuntu)
            uses: jlumbroso/[email protected]
    
          - run: mkdir -p ~/docker-image-cache
    
          - id: docker-image-cache
            uses: actions/cache@v4
            with:
                path: ~/docker-image-cache
                key: docker-image-cache4-${{ runner.os }}          
    
          - name: Git checkout my app repos
            uses: myorg/repoName/.github/actions/checkout@v3
    
          - name: Load cache for docker images
            if: steps.docker-image-cache.outputs.cache-hit == 'true'
            run: |
                docker load -i ~/docker-image-cache/myOrgImage1.tar
                docker load -i ~/docker-image-cache/myOrgImage2.tar
                docker load -i ~/docker-image-cache/myOrgImage3.tar
                docker load -i ~/docker-image-cache/myOrgImage4.tar
                docker load -i ~/docker-image-cache/myOrgImage5.tar
    
          - name: Pull the docker images 
            run:  |  
                 cd testApp
                 make pull-images
    
          - name: Create cache for docker images
            if: steps.docker-image-cache.outputs.cache-hit != 'true'
            run: |
                docker image list --format "{{ .Repository }}:{{ .Tag }}"
                docker save -o ~/docker-image-cache/myOrgImage1.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage1")
                docker save -o ~/docker-image-cache/myOrgImage2.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage2")
                docker save -o ~/docker-image-cache/myOrgImage3.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage3")
                docker save -o ~/docker-image-cache/myOrgImage4.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage4")
                docker save -o ~/docker-image-cache/myOrgImage5.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage5")

Not working:

      ---
      name: Test
      
      on: [ pull_request ]
      
      permissions:
        id-token: write
        contents: read
      
      jobs:
        test:
          env:
            CI: true
      
          runs-on: buildjet-4vcpu-ubuntu-2204
      
          steps:
            - name: Free Disk Space (Ubuntu)
              uses: jlumbroso/[email protected]
      
            - run: mkdir -p ~/docker-image-cache
      
            - id: docker-image-cache
              uses: buildjet/cache@v4
              with:
                  path: ~/docker-image-cache
                  key: docker-image-cache4-${{ runner.os }}          
      
            - name: Git checkout my app repos
              uses: myorg/repoName/.github/actions/checkout@v3
      
            - name: Load cache for docker images
              if: steps.docker-image-cache.outputs.cache-hit == 'true'
              run: |
                  docker load -i ~/docker-image-cache/myOrgImage1.tar
                  docker load -i ~/docker-image-cache/myOrgImage2.tar
                  docker load -i ~/docker-image-cache/myOrgImage3.tar
                  docker load -i ~/docker-image-cache/myOrgImage4.tar
                  docker load -i ~/docker-image-cache/myOrgImage5.tar
      
          - name: Pull the docker images 
            run:  |  
                 cd testApp
                 make pull-images
      
            - name: Create cache for docker images
              if: steps.docker-image-cache.outputs.cache-hit != 'true'
              run: |
                  docker image list --format "{{ .Repository }}:{{ .Tag }}"
                  docker save -o ~/docker-image-cache/myOrgImage1.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage1")
                  docker save -o ~/docker-image-cache/myOrgImage2.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage2")
                  docker save -o ~/docker-image-cache/myOrgImage3.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage3")
                  docker save -o ~/docker-image-cache/myOrgImage4.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage4")
                  docker save -o ~/docker-image-cache/myOrgImage5.tar $(docker image list --format "{{ .Repository }}:{{ .Tag }}" | grep "myOrgImage5")

Motivation and Context

Should fix: https://github.com/BuildJet/cache/issues/2

How Has This Been Tested?

Tested this in my orgs pipeline yet as a fork from the buildjet cache modified with this change.

Screenshots (if appropriate):

Shown above in description.

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation (add or update README or docs)

Checklist:

  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [x] All new and existing tests passed.

Napster134 avatar Feb 23 '24 22:02 Napster134