Skip to content

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

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

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

Conversation

@ogulcanaydogan
Copy link

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

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>
@ogulcanaydogan ogulcanaydogan force-pushed the feat/1146-attach-config-support branch from 7ea49c2 to 7e50d81 Compare March 9, 2026 08:54
Copy link
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


packOpts := oras.PackManifestOptions{
Subject: &subject,
ConfigAnnotations: opts.Annotations[option.AnnotationConfig],
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this annotation should only be set if opts.manifestConfigRef != ""

}

cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type")
cmd.Flags().StringVarP(&opts.manifestConfigRef, "config", "", "", "`path` of image config file")
Copy link
Member

Choose a reason for hiding this comment

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

Is push like this where it doesn't talk about file[:<type>]?

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