Skip to content

chore(build): validate Code Engine registry secret and clarify env lo… - #6769

Open
prakhar-singh1928 wants to merge 5 commits into
mainfrom
chore/6488-ibmcloud-ce-deploy-fixes
Open

chore(build): validate Code Engine registry secret and clarify env lo…#6769
prakhar-singh1928 wants to merge 5 commits into
mainfrom
chore/6488-ibmcloud-ce-deploy-fixes

Conversation

@prakhar-singh1928

Copy link
Copy Markdown
Collaborator

Pull Request

🔗 Related Issue

Closes #6488


📝 Summary

Improves the IBM Cloud Code Engine deployment workflow and documentation by addressing two gaps:

  1. Pre-flight Registry Secret Validation: Added a check in Makefile (ibmcloud-deploy target) that verifies the $IBMCLOUD_REGISTRY_SECRET exists via ibmcloud ce secret get before attempting deployment. If missing, it exits early with actionable instructions and the exact command to create the pull secret.
  2. Documentation Updates:
    • Updated Workflow A ("Typical first deploy") in docs/docs/howto/ibm-cloud-code-engine.md to explicitly include the registry pull secret creation step and added an informational note.
    • Added a tip in Workflow B instructing users to export .env.ce variables (export $(grep -v '^#' .env.ce | grep -v '^$' | xargs)) prior to running manual CLI commands, avoiding empty variable expansion errors.

📏 Reviewability

  • This PR has one clear purpose
  • The linked issue is not labeled triage
  • Unrelated bugs or improvements are tracked in separate issues/PRs
  • Tests are included with the code they validate
  • If AI-assisted, I understand and can explain the generated changes

🏷️ Type of Change

  • Bug fix
  • Feature / Enhancement
  • Documentation
  • Refactor
  • Chore (deps, CI, tooling)
  • Other (describe below)

🧪 Verification

List exact commands, screenshots, videos, logs, reproduction steps, or manual validation. If evidence is not feasible, explain why.

Check Command Status
Lint suite make ruff interrogate pylint Passed
Makefile dry-run make -n ibmcloud-deploy Passed
Secret validation check Validated pre-flight check fails gracefully with hint Passed

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • Tests added/updated for changes
  • Documentation updated (if applicable)
  • No secrets or credentials committed

📓 Notes (optional)

  • Verified Makefile dry run correctly interpolates subshell commands $$(echo $(IBMCLOUD_IMAGE_NAME) | cut -d/ -f1) and escapes \$$IBMCLOUD_API_KEY.

@msureshkumar88 msureshkumar88 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing both deployment workflow gaps. Requesting changes for one behavior issue:

Makefile:L6259: 🔴 bug: every ibmcloud ce secret get failure is suppressed and reported as a missing registry secret, so expired authentication, authorization, plugin, project/region, and connectivity failures receive false creation guidance. Preserve a sanitized diagnostic and show the creation command only when absence is confirmed.

…ading

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
@prakhar-singh1928
prakhar-singh1928 force-pushed the chore/6488-ibmcloud-ce-deploy-fixes branch from d292e8e to e9fdb7b Compare September 11, 2026 10:51
Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>

@msureshkumar88 msureshkumar88 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes because the preflight currently misdiagnoses a missing IBM CLI, and the first-deploy documentation remains inconsistent for SSO users.

  • Makefile:L6263: 🔴 bug: broad not found matching classifies ibmcloud: command not found (exit 127) as a missing registry secret. Guard command -v ibmcloud/exit 127 first, then match only the CLI’s secret-not-found response.

  • docs/docs/howto/ibm-cloud-code-engine.md:L170: 🔴 bug: .env.ce.example allows an empty API key for SSO, but this new command requires an IAM API key as the ICR registry-secret password. Document the separate registry credential requirement and give SSO users a valid path.

  • docs/docs/howto/ibm-cloud-code-engine.md:L113: 🟡 risk: “first-time creation is automated” contradicts the new required manual creation step. Correct this surrounding documentation.

  • Makefile:L6260: 🟡 risk: the new success, missing-secret, missing-CLI, and generic-failure branches have no automated coverage. Add mocked IBM CLI/Bats tests; the PR currently changes no relevant test files.

…ential docs

- Preflight checks CLI availability before querying the secret, so
  infrastructure failures (missing CLI, expired auth, wrong region) are
  reported with actionable guidance rather than misattributed to an absent
  registry secret
- Tighten secret-absence detection to match only the CE CLI's own error
  format instead of any substring containing 'not found'
- Fix misleading .env.ce comment: registry secret creation is a manual
  one-time step, not automated
- Document the registry credential requirement for SSO users: IBMCLOUD_API_KEY
  may be blank for interactive logins, but a long-lived IAM API key is required
  as the ICR pull credential regardless of deploy-time auth method; includes
  a service ID key setup example
- Add bats tests covering all four preflight branches: missing CLI, missing
  secret, generic CLI failure, and happy path

Closes #6488

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
The ibmcloud-deploy target is a Makefile recipe, not a standalone shell
script. Driving make with a stubbed binary does not fit the existing bats
pattern in tests/bash/ (which tests executable scripts such as
run-gunicorn.sh). Remove the file until a proper testing approach is agreed.

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
@prakhar-singh1928

Copy link
Copy Markdown
Collaborator Author

Thanks for the detailed review @msureshkumar88 — all findings addressed in the latest push.

🔴 Makefile — CLI availability check
Added a command -v ibmcloud guard before the secret query, so a missing CLI gets its own error message and never reaches the secret-verification path.

🔴 Makefile — not found pattern too broad
Tightened to an anchored regex targeting the CE CLI's own error format ([FAILED] ... not found, secret ... not found), so shell messages like command not found can't match.

🔴 docs L170 — SSO users without a valid path
The first-deploy sequence and the !!! info block now document the SSO case explicitly: IBMCLOUD_API_KEY may be blank for interactive logins, but the registry pull secret always needs a long-lived IAM API key because Code Engine uses it at image-pull time. A service ID API key setup example is included.

🟡 docs L113 — "first-time creation is automated"
Corrected — the comment now states the registry secret is a manual one-time step.

🟡 Makefile — test coverage
Not addressing in this PR. The preflight logic is embedded in a Makefile recipe — the only way to test it with bats would be to drive make with a stubbed binary, which is fragile and outside what tests/bash/ is designed for. Adding coverage here would mean extracting the preflight into a standalone shell script, which is a structural change beyond the scope of this fix. The three blocking issues are resolved; the deployment path now fails fast with accurate, actionable errors.

@msureshkumar88 msureshkumar88 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the CLI guard and the documentation gaps. Two changes are still needed before approval:

  • Makefile:L6268: 🔴 bug: ^\[FAILED\].*not found classifies any Code Engine [FAILED] … not found response as a missing registry secret—for example, a missing project. Match only the CLI response that identifies the requested secret; retain the generic diagnostic for all other failures.

  • Makefile:L6260: 🟡 risk: the four new preflight branches have no automated coverage. Add a Bats test that runs make ibmcloud-deploy with a stubbed ibmcloud in a throwaway clone/worktree. tests/bash/configure_secrets_merge_driver.bats already establishes this Makefile-test pattern.

- Tighten registry secret absence detection to match only the CE CLI's
  own response format ('Secret <name> not found') rather than any
  'not found' substring, so unrelated failures such as a missing project
  are correctly routed to the generic diagnostic branch
- Add bats tests covering all five preflight branches: missing CLI,
  absent registry secret, generic CLI failure, missing CE project
  (must not misclassify), and happy path — tests drive the live working
  tree via make -C REPO_ROOT with a stubbed ibmcloud on PATH

Signed-off-by: prakhar-singh1928 <prakhar.singh1928@ibm.com>
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.

IBM Cloud Code Engine deployment gaps in docs/docs/howto/ibm-cloud-code-engine.md

2 participants