Skip to content

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

Merged
TerryHowe merged 6 commits into
oras-project:mainfrom
ogulcanaydogan:feat/1146-attach-config-support
May 4, 2026
Merged

feat: add --config flag support for oras attach#2000
TerryHowe merged 6 commits into
oras-project:mainfrom
ogulcanaydogan:feat/1146-attach-config-support

Conversation

@ogulcanaydogan

Copy link
Copy Markdown
Contributor

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

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

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
@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
Contributor 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!

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@codecov

codecov Bot commented Apr 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.18%. Comparing base (b6b4956) to head (96c1221).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/root/attach.go 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2000      +/-   ##
==========================================
+ Coverage   87.15%   87.18%   +0.03%     
==========================================
  Files         138      138              
  Lines        5448     5462      +14     
==========================================
+ Hits         4748     4762      +14     
  Misses        419      419              
  Partials      281      281              

☔ 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.

@TerryHowe

Copy link
Copy Markdown
Member

looks like the last commit is missing signoff

@ogulcanaydogan ogulcanaydogan force-pushed the feat/1146-attach-config-support branch from 5df9bab to 2989670 Compare April 24, 2026 12:40
@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

All commits have DCO sign-off and CI is green. Ready to merge when you have a moment — thanks @TerryHowe!

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>
Cover --config and --platform mutual exclusion and flag registration
to improve patch coverage for the new flag.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
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).

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
@ogulcanaydogan ogulcanaydogan force-pushed the feat/1146-attach-config-support branch from 2989670 to 4a77777 Compare May 1, 2026 10:35
@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

Rebased onto main — all checks green, DCO clean. Ready to merge when you have a moment, @TerryHowe.

Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

CI runs need maintainer approval to execute (fork PR restriction). @TerryHowe if you can approve the workflow runs, that should unblock the merge.

@ogulcanaydogan

Copy link
Copy Markdown
Contributor Author

Friendly bump — CI is green and all feedback has been addressed.

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe TerryHowe merged commit 625105a into oras-project:main May 4, 2026
9 checks passed
@TerryHowe

Copy link
Copy Markdown
Member

Thanks!

TerryHowe added a commit to TerryHowe/oras that referenced this pull request Jun 28, 2026
Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
Co-authored-by: Terry Howe <terrylhowe@gmail.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.

Support to customize the config data

2 participants