-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add platform option to push command #1500
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1500 +/- ##
==========================================
- Coverage 86.10% 86.08% -0.02%
==========================================
Files 118 118
Lines 4224 4248 +24
==========================================
+ Hits 3637 3657 +20
- Misses 350 352 +2
- Partials 237 239 +2 ☔ View full report in Codecov by Sentry. |
641cbba
to
7e915b1
Compare
cmd/oras/root/push.go
Outdated
@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations: | |||
Example - Push repository with manifest annotation file: | |||
oras push --annotation-file annotation.json localhost:5000/hello:v1 | |||
|
|||
Example - Push repository with platform: | |||
oras push --platform linux/arm/v5 localhost:5000/hello:v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @FeynmanZhou for the flag naming. attach
already using it so better call the new one --config-platform
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good point that --platform
means differently in oras push
and oras attach
. We need a better flag name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--config-platform
does not sound like a good name. Would it be better to name it --artifact-platform
? That will be consistent with --artifact-type
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does mean pull will use --platform
and push --artifact-platform
though which does seem a bit inconsistent to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to choose a good flag name.
Some historical view on this: --platform
was firstly introduced to oras manifest fetch
to select an image with specific platform from a multi-arch image. Then the same UX was applied to oras discover
and oras attach
for selecting a platform-specific subject artifact.
cmd/oras/root/push.go
Outdated
desc := ocispec.Descriptor{ | ||
MediaType: oras.MediaTypeUnknownConfig, | ||
Digest: digest.FromBytes(blob), | ||
Size: int64(len(blob)), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This part can be replaced by func NewDescriptorFromBytes(mediaType string, content []byte) ocispec.Descriptor
of oras-go. Reference: NewDescriptorFromBytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cmd/oras/root/push.go
Outdated
@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations: | |||
Example - Push repository with manifest annotation file: | |||
oras push --annotation-file annotation.json localhost:5000/hello:v1 | |||
|
|||
Example - Push repository with platform: | |||
oras push --platform linux/arm/v5 localhost:5000/hello:v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good point that --platform
means differently in oras push
and oras attach
. We need a better flag name.
cmd/oras/root/push.go
Outdated
@@ -97,6 +101,9 @@ Example - Push repository with manifest annotations: | |||
Example - Push repository with manifest annotation file: | |||
oras push --annotation-file annotation.json localhost:5000/hello:v1 | |||
|
|||
Example - Push repository with platform: | |||
oras push --platform linux/arm/v5 localhost:5000/hello:v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--config-platform
does not sound like a good name. Would it be better to name it --artifact-platform
? That will be consistent with --artifact-type
.
cmd/oras/root/push.go
Outdated
if opts.Platform.Platform != nil && opts.artifactType != "" { | ||
return errors.New("--artifact-type and --platform cannot both be provided for 1.0 OCI image") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can be used together, can't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed they can be used together. We can populate the artifactType
as mediaType
into the config descriptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmd/oras/root/push.go
Outdated
return err | ||
} | ||
desc := ocispec.Descriptor{ | ||
MediaType: oras.MediaTypeUnknownConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value depends on the image-spec version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the image-spec
version is v1.0
. The media type can also be the value of --artifact-type
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
3038b7b
to
fafd301
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit, but I am not a maintainer.
cmd/oras/root/push.go
Outdated
if opts.Flag == option.ImageSpecV1_0 { | ||
if opts.artifactType != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: how about
if opts.Flag == option.ImageSpecV1_0 { | |
if opts.artifactType != "" { | |
if opts.Flag == option.ImageSpecV1_0 && opts.artifactType != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fafd301
to
a8a6a36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmd/oras/root/push.go
Outdated
configAndPlatform := []string{"config", "artifact-platform"} | ||
if err := oerrors.CheckMutuallyExclusiveFlags(cmd.Flags(), configAndPlatform...); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in PreRunE
before option.Parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -116,7 +122,7 @@ Example - Push file "hi.txt" into an OCI image layout folder 'layout-dir' with t | |||
return err | |||
} | |||
|
|||
if opts.manifestConfigRef != "" && opts.artifactType == "" { | |||
if (opts.manifestConfigRef != "" || opts.Platform.Platform != nil) && opts.artifactType == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block handles oras push --config xxx ...
without using --artifact-type xxx
:
- For v1.1 artifacts, this usage invalid.
- Otherwise give best-effort try to pack v1.0 artifacts.
Since --artifact-platform
cannot be used with --config
, there is no need to change this code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only need to make sure: --artifact-platform
is not used for v1.0 artifact in the below opts.PackVersion
switching block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the change I think you requested. I do need to think about this some more though.
bb6cfaa
to
8d4062e
Compare
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
8d4062e
to
35fe5b7
Compare
What this PR does / why we need it:
Add the platform option to the push command for example:
Create the manifest for example:
The results
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Closes #1066
Partial #1053
Please check the following list: