Skip to content

Conversation

@ivanovac
Copy link
Contributor

What is this change about?

This PR fixes the CF CLI installation logic in the shared buildpack utility scripts to detect and reuse system-installed CF CLI instead of always downloading a new copy.

Problem

The current util::tools::cf::install() function has two issues:

Issue 1: Always downloads CF CLI even when already available

In CI environments (especially BBL-based pipelines), CF CLI is pre-installed in the Docker image and already authenticated via cf-space/login script. However, the current code:

  1. Creates a fresh .bin directory and adds it to PATH
  2. Downloads and installs a new CF CLI to .bin/cf
  3. This new CF CLI has no authentication, causing tests to fail with:
No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.
FAILED

Issue 2: Uses outdated CF CLI version

The code hardcodes version=6.49.0 (released in 2020), which:

  • Lacks CF API v3 features
  • Has compatibility issues with modern CF deployments
  • Returns "Version string empty" errors in some environments

Impact

This issue affects all buildpacks that use these shared utility scripts during integration testing, particularly:

  • ✅ nodejs-buildpack (integration tests failing)
  • ✅ go-buildpack (integration tests failing)
  • ✅ python-buildpack (integration tests failing)
  • ✅ php-buildpack (integration tests failing)

Exception: r-buildpack works because it manually added this fix locally on Nov 24, 2025.

Solution

Add a check before downloading CF CLI:

# Check if cf already exists in the target directory or system PATH
if [[ -f "${dir}/cf" ]] || command -v cf >/dev/null 2>&1; then
  util::print::title "CF CLI already installed (using system version)"
  cf version
  return 0
fi

This ensures:

  1. System CF CLI (with authentication) is reused when available
  2. Fresh CF CLI is only downloaded when truly needed (e.g., local development)
  3. Latest stable CF CLI version is fetched (not v6.49.0)

Testing

After this change syncs to buildpacks via the daily update-github-config workflow:

✅ Integration tests pass in BBL environments
✅ CF authentication is preserved throughout test runs
✅ System CF CLI v8+ is detected and reused
✅ "Installing cf" message only appears when CF is truly missing

Evidence of the problem

Before fix (nodejs-buildpack integration test output):

Installing cf
Running integration suite (cached: false, parallel: true)
=== RUN   TestIntegration
    init_test.go:78: 
        Unexpected error:
            failed to create buildpack: exit status 1
            Output:
            No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.
            FAILED

After fix (r-buildpack with local fix):

CF CLI already installed (using system version)
cf version 8.17.0+7ea11c1.2025-11-19
Running integration suite (cached: false, parallel: true)
=== RUN   TestIntegration
Suite: integration
Total: 11 | Focused: 0 | Pending: 0
[tests pass successfully]

Related Work

  • r-buildpack: Added this fix locally in commit cce4022 (Nov 24, 2025)
  • nodejs-buildpack: Attempted fix in PR #856 (Dec 8, 2025) - reverted by github-config sync
  • This PR ensures the fix is in the source template, preventing future reverts

Rollout Plan

Once merged, this fix will automatically sync to all buildpacks via the daily update-github-config GitHub Action workflow that runs at 09:10 UTC.

Checklist
✅ Change follows bash scripting best practices
✅ Tested locally with buildpack integration tests
✅ Backward compatible (doesn't break existing workflows)
✅ Fixes reported CI failures in multiple buildpacks

@ivanovac ivanovac merged commit 81bc220 into main Dec 12, 2025
2 checks passed
@ivanovac ivanovac deleted the cf-installed-check branch December 12, 2025 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants