-
Notifications
You must be signed in to change notification settings - Fork 1
Add image tag command #65
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
Draft
chruffins
wants to merge
11
commits into
main
Choose a base branch
from
hypeship/image-tag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
95079f4
Add image tag command
chruffins 8229612
Harden image tag command
chruffins 6367458
Prefer cached images for single-target pushes
chruffins 49dd24c
Assert escaped image tag paths
chruffins af1991b
Fall back to Docker for image tags
chruffins c3fe38e
Align image tag CLI with local tag API
chruffins be0c5be
Test image tag readiness errors
chruffins 59b2acd
Simplify image tag command
chruffins efa1374
Preserve Docker push precedence
chruffins adea978
Fix cached-push fallback and simplify tag command
chruffins b6bbb8f
Clarify cached-image readiness errors and note SDK follow-up
chruffins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ func init() { | |
| &execCmd, | ||
| &cpCmd, | ||
| &pullCmd, | ||
| &tagCmd, | ||
| &pushCmd, | ||
| &runCmd, | ||
| &psCmd, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/url" | ||
| "os" | ||
|
|
||
| "github.com/google/go-containerregistry/pkg/name" | ||
| "github.com/kernel/hypeman-go" | ||
| "github.com/kernel/hypeman-go/option" | ||
| "github.com/tidwall/gjson" | ||
| "github.com/urfave/cli/v3" | ||
| ) | ||
|
|
||
| var tagCmd = cli.Command{ | ||
| Name: "tag", | ||
| Usage: "Create a local image tag", | ||
| ArgsUsage: "<source> <target>", | ||
| Description: "Create a local image tag in Hypeman without pulling or converting the image.", | ||
| Action: handleTag, | ||
| } | ||
|
|
||
| func handleTag(ctx context.Context, cmd *cli.Command) error { | ||
| args := cmd.Args().Slice() | ||
| if len(args) != 2 { | ||
| return fmt.Errorf("source and target image references required\nUsage: hypeman tag <source> <target>") | ||
| } | ||
| source, target := args[0], args[1] | ||
| for _, ref := range []struct{ label, value string }{{"source", source}, {"target", target}} { | ||
| if _, err := name.ParseReference(ref.value); err != nil { | ||
| return fmt.Errorf("invalid %s %q: %w", ref.label, ref.value, err) | ||
| } | ||
| } | ||
|
|
||
| client := hypeman.NewClient(getDefaultRequestOptions(cmd)...) | ||
|
|
||
| var opts []option.RequestOption | ||
| if cmd.Root().Bool("debug") { | ||
| opts = append(opts, debugMiddlewareOption) | ||
| } | ||
|
|
||
| var res []byte | ||
| opts = append(opts, option.WithResponseBodyInto(&res)) | ||
| // TODO: switch to a typed Images.Tag once the tag API from kernel/hypeman#453 | ||
| // is generated into hypeman-go. | ||
| body := struct { | ||
| Target string `json:"target"` | ||
| }{Target: target} | ||
| if err := client.Post(ctx, "/images/"+url.PathEscape(source)+"/tag", body, nil, opts...); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| format := cmd.Root().String("format") | ||
| transform := cmd.Root().String("transform") | ||
| if format != "auto" { | ||
| return ShowJSON(os.Stdout, "tag", gjson.ParseBytes(res), format, transform) | ||
| } | ||
|
|
||
| imageName := gjson.GetBytes(res, "name").String() | ||
| if imageName == "" { | ||
| imageName = target | ||
| } | ||
| fmt.Println(imageName) | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Cached push skips newer Docker image
High Severity
A successful
Images.Getnow short-circuits staging, so one-arghypeman push TARGETnever reloads Docker when that tag already exists in Hypeman. Rebuilds that retag the same name and push again keep shipping the previous cached digest, including when the cached record isfailedandwaitForImageReadyerrors out. The still-documenteddocker tagthenhypeman push TARGETloop is the common path this breaks.Reviewed by Cursor Bugbot for commit 5010e06. Configure here.