Skip to content

oci: set default PATH when missing or empty - #1113

Open
gcomneno wants to merge 1 commit into
canonical:mainfrom
gcomneno:contrib/issue-729-default-path
Open

oci: set default PATH when missing or empty#1113
gcomneno wants to merge 1 commit into
canonical:mainfrom
gcomneno:contrib/issue-729-default-path

Conversation

@gcomneno

@gcomneno gcomneno commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR generalizes the empty-PATH protection for OCI images (issue #729).

Previously this behavior applied only when base == "bare". The final image
environment is now inspected for every base, after project-defined environment
variables have been applied.

Behavior

  • If PATH is missing or its final value is empty (PATH=), set it to
    Pebble.DEFAULT_ENV_PATH.
  • If the final PATH value is non-empty, preserve it.
  • When multiple PATH entries exist, the last assignment wins.

The implementation reads the final image environment through skopeo inspect
and writes the default only when necessary.

Packaging order

set_default_path() runs after set_environment(), preventing a project-level
PATH: "" from overwriting the safe default after validation.

Tests

Unit coverage includes:

  • PATH present: inspect only, no config write;
  • PATH missing: inspect and configure the default;
  • PATH empty: inspect and configure the default;
  • duplicate PATH entries with last-assignment semantics;
  • package orchestration applying project environment before final PATH
    validation.

Validation performed:

  • focused OCI and package-service suite: 56 passed;
  • unit suite: 644 passed, 1 environment-dependent APT test deselected;
  • the deselected APT test fails identically on current upstream/main because
    the local environment lacks the APT package backend;
  • Ruff check and format check passed for all four changed files;
  • git diff --check passed.

Refs #729

@gcomneno
gcomneno requested a review from tigarmo as a code owner February 26, 2026 11:40
@gcomneno
gcomneno force-pushed the contrib/issue-729-default-path branch 2 times, most recently from caa0fa1 to 0dd0914 Compare May 24, 2026 15:57
@gcomneno

Copy link
Copy Markdown
Contributor Author

Hi! Just gently following up on this one.

I rebased the branch onto current upstream/main and re-ran the focused checks locally:

  • uv run --group dev python -m pytest -q tests/unit/test_oci.py -rs
  • uv run --group lint --group types ruff check rockcraft/oci.py tests/unit/test_oci.py
  • uv run --group lint --group types ruff format --check rockcraft/oci.py tests/unit/test_oci.py

The focused test run passes with 51 passed, and Ruff is clean.

Happy to adjust anything else if useful.

@gcomneno

Copy link
Copy Markdown
Contributor Author

Friendly ping on this PR. It has been idle for a while, and it should still be ready from my side.

Please let me know if you would like me to rebase, refresh the checks, or adjust anything else.

Thanks!

Read PATH via skopeo inspect and set Pebble.DEFAULT_ENV_PATH only when PATH is missing/empty. Add unit tests for PATH present/missing/empty.
@gcomneno
gcomneno force-pushed the contrib/issue-729-default-path branch from 0dd0914 to 0a6eae1 Compare July 31, 2026 11:33
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.

1 participant