-
Notifications
You must be signed in to change notification settings - Fork 582
Description
Description
The Go feature's install.sh script leaves approximately 994 MB of Go build artifacts in /tmp/gotools after compiling Go tools. The script sets GOPATH=/tmp/gotools and GOCACHE=/tmp/gotools/cache as temporary build locations, moves the compiled binaries out of /tmp/gotools/bin/, but fails to clean up the module cache and build cache directories.
Root Cause
In src/go/install.sh, the cleanup logic is:
The rm -rf /tmp/gotools is inside the if [ -d /tmp/gotools/bin ] conditional. If this block executes successfully, the rm should remove the directory — but in practice, /tmp/gotools/cache (612 MB) and /tmp/gotools/pkg (383 MB) remain in the final image layer.
It appears the rm -rf /tmp/gotools either fails silently or the cache directories are recreated after this point (possibly by the subsequent golangci-lint installation which also uses Go tooling).
Impact
994 MB of unnecessary data baked into every image using this feature
/tmp/gotools/cache: 612 MB (Go build cache)
/tmp/gotools/pkg: 383 MB (Go module cache)
Steps to Reproduce
- Create a devcontainer with the Go feature:
- Build the devcontainer image
- Inspect the image: docker run --rm
du -sh /tmp/gotools/*
Expected Behavior
/tmp/gotools should be completely removed after tool installation.
Suggested Fix
Add a cleanup after the golangci-lint install block (after the fi closing the INSTALL_GO_TOOLS conditional):
Environment
Feature: ghcr.io/devcontainers/features/go:1 (v1.3.2)
Base image: mcr.microsoft.com/devcontainers/base:ubuntu
Go version: latest (1.24.x)
Architecture: x86_64 / amd64