Skip to content

Preserve GOPATH when invoking Go tools under sudo in workflow template #1411

@coderabbitai

Description

@coderabbitai

Problem Description

The GitHub Actions workflow template at .github/workflows/build-notebooks-TEMPLATE.yaml around lines 631-641 uses sudo --preserve-env=PATH when invoking the Go tool for check-payload scanning. However, this approach drops the GOPATH environment variable, causing the Go toolchain to fall back to /root and unnecessarily recompile binaries.

Current Implementation

sudo --preserve-env=PATH go tool github.com/openshift/check-payload scan local --path "${IMAGE_MOUNT_DIR}"

Impact Analysis

  • Performance degradation: Go toolchain recompiles binaries when GOPATH is not preserved
  • Permission pollution: Compilation artifacts created in /root directory
  • Wasted build time: Unnecessary recompilation on every workflow run
  • Resource inefficiency: Additional CPU and I/O overhead during builds

Solution Options

Option 1: Preserve GOPATH (Recommended)

sudo --preserve-env=PATH,GOPATH go tool github.com/openshift/check-payload scan local --path "${IMAGE_MOUNT_DIR}"

Option 2: Also preserve GOMODCACHE if used

sudo --preserve-env=PATH,GOPATH,GOMODCACHE go tool github.com/openshift/check-payload scan local --path "${IMAGE_MOUNT_DIR}"

Option 3: Drop sudo entirely

Since the mount is already unprivileged, consider removing sudo altogether:

go tool github.com/openshift/check-payload scan local --path "${IMAGE_MOUNT_DIR}"

Acceptance Criteria

  • GOPATH environment variable is preserved when invoking Go tools under sudo
  • No unnecessary recompilation occurs during workflow execution
  • Build time is optimized by reusing existing compiled binaries
  • No permission pollution in /root directory
  • Workflow continues to function correctly with security requirements

Implementation Notes

  • Test the change in a non-production environment first
  • Consider whether GOMODCACHE should also be preserved if module caching is used
  • Verify that the workflow still meets security requirements after the change
  • Monitor build times to confirm performance improvement

Context

This issue addresses workflow performance optimization identified during code review.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions