oci-build-task icon indicating copy to clipboard operation
oci-build-task copied to clipboard

context=cwd and caching enabled may cause ever increasing image size

Open Akhalaka opened this issue 6 years ago • 1 comments

Pipeline to demonstrate

jobs:
- name: Build Growing Image
  plan:
  # This would normally be a git resource, but done to make this self contained
  - task: write dockerfile  
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: alpine}
      outputs: [name: docker]
      run:
        path: sh
        args: [-ec, 'printf "FROM alpine\nCOPY . /data/\n" >docker/Dockerfile']
  - task: build
    privileged: true
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: vito/oci-build-task}
      inputs: [{name: docker, path: .}]
      outputs: [{name: image}]
      caches: [{path: cache}]
      run: {path: build}

After repeatedly running the job on a single worker (to make sure that I was getting the cache every time). I had context sizes of 181B, 2.79MB, 5.58MB, 11.15MB, 22.30MB, ... As you can see the context (and resultant image) is doubling in size every build. This is also starting from the tiny alpine image; Depending on your base image, you can easily get to multiple GB in a few builds.

The image size depends on the Dockerfile and .dockerignore files, but COPY . is not that uncommon in a Dockerfile. Even with a Dockerfile only copying specific items, having context include the cache is not great as this requires sending the entire contents of cache into memory which for larger images, the cache can become very large.

Since nothing is actually wrong, I would recommend either removing the section talking about path: . or make note of this behavior when CONTEXT=. and cache is enabled.

Akhalaka avatar Oct 04 '19 15:10 Akhalaka

Ended up with a 6Gb image.tar in a local job testing after several iterations before went to look what's going on. IMO docs really need a recommendation to add the cache directory to .dockerignore somewher near the cache section.

ei-grad avatar Jan 17 '23 10:01 ei-grad