Skip to content

[BUG] --no-cache is not respected for git sources #2924

Closed
@willarmiros

Description

@willarmiros

Description

I have a service in a docker compose that builds using a Dockerfile in a remote git repo, defined like so:

services:
  my-service:
      container_name: my-service
      build:
        context: [email protected]:protectai/my-repo.git#main
        dockerfile: Dockerfile
        ssh:
          - default

When re-building a service with the --no-cache flag, I would expect caching to be skipped for ALL parts of the build, including making a fresh call to retrieve the source code from git. However this is not the case, as I can see in the first line of the output:

=> CACHED [internal] load git source [email protected]:protectai/my-repo.git#main                                                       8.9s

I also confirmed that the contents of the container/service are an outdated version of content in that repo. When I change the git ref to be a commit hash or some branch other than main, it then actually re-pulls from the git source as I expect. For example:

=> [internal] load git source [email protected]:protectai/my-repo.git#75e9ec67c74dcddd8cd22c3f3c6ecb947ba55f2a                          2.3s

After changing the ref to the latest commit in the repo, I confirmed the service was actually updated with the latest source code. My ask is for the --no-cache flag to do this for me without needing to make manual changes.

Steps To Reproduce

  1. Create a private Github repo, in this case it will be github.com:protectai/my-repo.git, and enable access via SSH.

  2. Create an SSH key with access to it that you can use locally, and add the SSH key to your local env so that it gets picked up by Docker's --ssh default

  3. Run docker buildx build --ssh default --progress=plain --no-cache [email protected]:protectai/my-repo.git#main

  4. Make any update to the repo, and commit the change to main branch

  5. Re-run docker buildx build --ssh default --progress=plain --no-cache [email protected]:protectai/my-repo.git#main

  6. Run docker buildx du --filter type=source.git.checkout --verbose to confirm that only the original commit SHA has been pulled

Compose Version

Docker Compose version v2.17.3

Docker Environment

Client:
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.4
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.17.3
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.19
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.4
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  v0.10.0
    Path:     /Users/williamarmiros/.docker/cli-plugins/docker-scout

Server:
 Containers: 7
  Running: 5
  Paused: 0
  Stopped: 2
 Images: 37
 Server Version: 23.0.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
 runc version: v1.1.5-0-gf19387a
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 5
 Total Memory: 7.667GiB
 Name: docker-desktop
 ID: 1d550563-0ff9-47f6-a6eb-4014a3cd7bc2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions