Skip to content

Go feature leaves ~994 MB of build cache in /tmp/gotools after installing tools #1587

@dkwgit

Description

@dkwgit

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions