-
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
base: main
Are you sure you want to change the base?
Changes from all commits
c538308
d647ee7
5010e06
6d6d616
61d1aca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ func init() { | |
| &execCmd, | ||
| &cpCmd, | ||
| &pullCmd, | ||
| &tagCmd, | ||
| &pushCmd, | ||
| &runCmd, | ||
| &psCmd, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/url" | ||
| "os" | ||
|
|
||
| "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. If the source is not already | ||
| cached in Hypeman, fall back to the matching image in the local Docker daemon.`, | ||
| 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] | ||
| 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)) | ||
| body := struct { | ||
| Target string `json:"target"` | ||
| }{Target: target} | ||
| path := "/images/" + url.PathEscape(source) + "/tag" | ||
| if err := client.Post(ctx, path, body, nil, opts...); err != nil { | ||
| if !isNotFoundError(err) { | ||
| return err | ||
| } | ||
| staged, stageErr := stageDockerImage(ctx, cmd, &client, source, target) | ||
| if stageErr != nil { | ||
| return fmt.Errorf("image %q was not found in Hypeman or Docker: %w", source, stageErr) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tag errors claim image not foundLow Severity Every Additional Locations (1)Reviewed by Cursor Bugbot for commit 61d1aca. Configure here. |
||
| res = []byte(staged.RawJSON()) | ||
| } | ||
|
|
||
| format := cmd.Root().String("format") | ||
| transform := cmd.Root().String("transform") | ||
| result := gjson.ParseBytes(res) | ||
| if format != "auto" { | ||
| return ShowJSON(os.Stdout, "tag", result, format, transform) | ||
| } | ||
|
|
||
| imageName := result.Get("name").String() | ||
| if imageName == "" { | ||
| imageName = target | ||
| } | ||
| fmt.Println(imageName) | ||
| return nil | ||
| } | ||


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.