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

Temp Git context folder does not get completely cleaned up after build #30973

Open
nazure opened this issue Feb 13, 2017 · 3 comments
Open

Temp Git context folder does not get completely cleaned up after build #30973

nazure opened this issue Feb 13, 2017 · 3 comments
Labels
area/builder kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed.

Comments

@nazure
Copy link

nazure commented Feb 13, 2017

Description

Temp folder is not completely cleaned up when invoking a Docker build using a git URL with a folder fragment.
Issue is reproducible using the CLI as well as server-side builds via the API.
Issue does not occur when not specifying a folder fragment.

Steps to reproduce the issue:

  1. Prepare a git repository with multiple folders and put a single Dockerfile in one of them.
  2. Run "docker build -t test:test https://git_URL#master:folder_containing_Dockerfile"
    (alternatively invoke build via API)

Describe the results you received:
/tmp now contains a 'docker-build-gitXXXXXX' folder which still contains all other folders in the git repository except the folder containing the Dockerfile.
For server-side builds via API, /var/lib/docker/tmp shows the same thing.

Describe the results you expected:
Temporary folders created for the git context should be deleted completely after the build.

Additional information you deem important (e.g. issue happens only occasionally):
Issue appears to be related to pkg/gitutils/gitutils.go:checkoutGit in the section which deals with folder fragments.
root gets reassigned to newCtx which now has the git folder path appended to it.
This probably why only the folder containing the Dockerfile gets deleted in builder/git.go:MakeGitContext (os.removeAll) while leaving the rest of the folders intact.

Output of docker version:
Client:
Version: 1.10.3
API version: 1.22
Package version: docker-common-1.10.3-59.el7.x86_64
Go version: go1.6.2
Git commit: 429be27-unsupported
Built: Fri Nov 18 17:03:44 2016
OS/Arch: linux/amd64

Server:
Version: 1.10.3
API version: 1.22
Package version: docker-common-1.10.3-59.el7.x86_64
Go version: go1.6.2
Git commit: 429be27-unsupported
Built: Fri Nov 18 17:03:44 2016
OS/Arch: linux/amd64

Output of docker info:
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 4
Server Version: 1.10.3
Storage Driver: devicemapper
Pool Name: docker-253:0-201443561-pool
Pool Blocksize: 65.54 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 12.95 GB
Data Space Total: 107.4 GB
Data Space Available: 33.07 GB
Metadata Space Used: 9.118 MB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.138 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
WARNING: Usage of loopback devices is strongly discouraged for production use. Either use --storage-opt dm.thinpooldev or use --storage-opt dm.no_warn_on_loop_devices=true to suppress this warning.
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.135-RHEL7 (2016-11-16)
Execution Driver: native-0.2
Logging Driver: json-file
Plugins:
Volume: local
Network: bridge null host
Authorization: rhel-push-plugin
Kernel Version: 3.10.0-514.6.1.el7.x86_64
Operating System: Linux
OSType: linux
Architecture: x86_64
Number of Docker Hooks: 2
CPUs: 2
Total Memory: 3.686 GiB
Name: xxxxxxxx
ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Registries: docker.io (secure)

Additional environment details (AWS, VirtualBox, physical, etc.):
Centos 7 (selinux enabled)

@cpuguy83 cpuguy83 added area/builder kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. labels Feb 13, 2017
@nazure nazure changed the title Temp Git context folder does not completely cleaned up after build Temp Git context folder does not get completely cleaned up after build Feb 13, 2017
@vdemeester vdemeester self-assigned this Feb 13, 2017
@joequery
Copy link

I was able to reproduce the issue with version 1.13.1.

I created a repo matching the issue description at https://github.com/joequery/tmptest, so for convenience to replicate you can run

$ docker build -t test:test "https://github.com/joequery/tmptest.git#master:testdir"

@vdemeester vdemeester removed their assignment Mar 13, 2017
@tianon
Copy link
Member

tianon commented Sep 16, 2022

This is still an issue with the classic builder in 20.10.xx 😬

(and BuildKit doesn't support subdirectories yet, so I can't "just switch" 🙈 I've yet to determine where buildkit stores the temporary clone, but it does appear to be cleaned up correctly over there)

Edit: for whatever it's worth, here's what I'm doing now instead:

# https://github.com/moby/moby/issues/30973 🤦
# docker build --pull --tag foo/bar 'https://github.com/foo/bar.git#:baz'
tempDir="$(mktemp -d -t docker-build-30973-XXXXXXXXXX)"
trap 'rm -rf "$tempDir"' EXIT
git clone --depth 1 https://github.com/foo/bar.git "$tempDir"
docker build --pull --tag foo/bar "$tempDir/baz"

tianon added a commit to docker-library/oi-janky-groovy that referenced this issue Sep 16, 2022
@thaJeztah
Copy link
Member

@tianon fragments may be supported in the upcoming release (or when using a container builder) see moby/buildkit#2116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/builder kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed.
Projects
None yet
Development

No branches or pull requests

7 participants