Skip to content

feat: add --config flag support for oras attach#2000

Open
ogulcanaydogan wants to merge 4 commits intooras-project:mainfrom
ogulcanaydogan:feat/1146-attach-config-support
Open

feat: add --config flag support for oras attach#2000
ogulcanaydogan wants to merge 4 commits intooras-project:mainfrom
ogulcanaydogan:feat/1146-attach-config-support

Conversation

@ogulcanaydogan
Copy link
Copy Markdown

Summary

Add --config <file>[:<type>] flag support to oras attach, matching the existing behavior in oras push. This allows users to customize the config descriptor (media type and content) when attaching artifacts to a subject.

Use case: OCI does not mandate config content for artifacts, so users may need to define custom config data with specific media types when attaching artifacts.

Changes

  • cmd/oras/root/attach.go:
    • Add manifestConfigRef field to attachOptions struct
    • Register --config flag with path format <file>[:<type>]
    • Parse config file reference using fileref.Parse() and add to file store
    • Set ConfigDescriptor and ConfigAnnotations in PackManifestOptions
    • Add mutual exclusivity check between --config and --platform flags
    • Add usage example in command help text

Usage

# Attach with custom config file and media type
oras attach --artifact-type doc/example \
  --config config.json:application/vnd.me.config \
  localhost:5000/hello:v1 hi.txt

Test plan

  • go build ./cmd/oras/ — builds successfully
  • go vet ./cmd/oras/... — no issues
  • go test ./... — full test suite passes (all packages OK)

Fixes #1146

Copy link
Copy Markdown
Member

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

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

This could use some tests. It may be easier to add to test/e2e/suite/command/attach.go rather than unit tests

Comment thread cmd/oras/root/attach.go Outdated
Comment thread cmd/oras/root/attach.go
Add support for customizing the config descriptor when using oras attach,
matching the existing --config flag behavior in oras push. This allows users
to specify a config file with an optional media type using the format
--config <file>[:<type>].

- Add manifestConfigRef field and --config flag to attach command
- Parse config file reference and set ConfigDescriptor in pack options
- Add config and platform mutual exclusivity validation
- Add config annotations support for attach
- Add usage example in command help text

Fixes oras-project#1146

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Add e2e tests covering:
- attach with custom config file (default media type)
- attach with custom config file and custom media type
- --config and --platform mutual exclusivity failure

Also fix ConfigAnnotations being set unconditionally on PackManifestOptions:
move it inside the manifestConfigRef check so it only applies when a
config file is actually provided.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
@ogulcanaydogan ogulcanaydogan force-pushed the feat/1146-attach-config-support branch from c88cae7 to 4c75f97 Compare April 9, 2026 20:40
@ogulcanaydogan
Copy link
Copy Markdown
Author

Rebased onto latest main (as of today). All previous review comments have been addressed:

  • Added 3 e2e tests in test/e2e/suite/command/attach.go
  • ConfigAnnotations is only set when manifestConfigRef != ""
  • Flag description is consistent with oras push

@TerryHowe ready for re-review when you have a chance, thank you!

Copy link
Copy Markdown
Member

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

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

/lgtm

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.14%. Comparing base (2763bbb) to head (4c75f97).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/attach.go 71.42% 2 Missing and 2 partials ⚠️

❌ Your patch check has failed because the patch coverage (71.42%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2000      +/-   ##
==========================================
- Coverage   87.18%   87.14%   -0.04%     
==========================================
  Files         143      143              
  Lines        5539     5553      +14     
==========================================
+ Hits         4829     4839      +10     
- Misses        423      425       +2     
- Partials      287      289       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Cover --config and --platform mutual exclusion and flag registration
to improve patch coverage for the new flag.
Add e2e tests that exercise the error paths introduced by the --config
flag: empty file path (fileref.Parse error) and non-existent config
file (addFile error).
@TerryHowe
Copy link
Copy Markdown
Member

looks like the last commit is missing signoff

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.

Support to customize the config data

2 participants