Skip to content

Commit 6fa3940

Browse files
committed
Align image tag CLI with local tag API
1 parent 61d1aca commit 6fa3940

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

pkg/cmd/imagecmd_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ func TestTagCommandFallsBackToDockerWhenHypemanMisses(t *testing.T) {
104104
"hypeman", "--base-url", server.URL,
105105
"tag", "not a valid image", "myapp:latest",
106106
})
107-
require.ErrorContains(t, err, "was not found in Hypeman or Docker")
107+
require.ErrorContains(t, err, "was not found in Hypeman; stage it from Docker")
108108
}

pkg/cmd/push.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ Examples:
4848
hypeman tag alpine:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
4949
hypeman push 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
5050
51-
# Push a local Docker tag to ECR
51+
# Stage a local Docker tag, then push it to ECR
5252
docker tag alpine:latest 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
53+
hypeman push local 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
5354
hypeman push 123456789.dkr.ecr.us-east-1.amazonaws.com/myapp:v1
5455
5556
# Push a cached Hypeman image directly to a different remote target

pkg/cmd/pushcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func handleRemotePushTarget(ctx context.Context, cmd *cli.Command, target string
107107

108108
// If Hypeman does not have the image, preserve the Docker-daemon fallback.
109109
if _, err := stageDockerImage(ctx, cmd, &client, target, target); err != nil {
110-
return fmt.Errorf("load local Docker image %q: %w; tag it first or use hypeman push <image> <target> for a cached Hypeman image", target, err)
110+
return fmt.Errorf("image %q was not found in Hypeman; stage it from Docker: %w", target, err)
111111
}
112112

113113
return runRemotePush(ctx, cmd, target, target)

pkg/cmd/tag.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ import (
1313
)
1414

1515
var tagCmd = cli.Command{
16-
Name: "tag",
17-
Usage: "Create a local image tag",
18-
ArgsUsage: "<source> <target>",
19-
Description: `Create a local image tag in Hypeman. If the source is not already
20-
cached in Hypeman, fall back to the matching image in the local Docker daemon.`,
21-
Action: handleTag,
16+
Name: "tag",
17+
Usage: "Create a local image tag",
18+
ArgsUsage: "<source> <target>",
19+
Description: "Create a local image tag in Hypeman without pulling or converting the image.",
20+
Action: handleTag,
21+
HideHelpCommand: true,
22+
}
23+
24+
type tagImageRequest struct {
25+
Target string `json:"target"`
2226
}
2327

2428
func handleTag(ctx context.Context, cmd *cli.Command) error {
@@ -37,17 +41,18 @@ func handleTag(ctx context.Context, cmd *cli.Command) error {
3741

3842
var res []byte
3943
opts = append(opts, option.WithResponseBodyInto(&res))
40-
body := struct {
41-
Target string `json:"target"`
42-
}{Target: target}
4344
path := "/images/" + url.PathEscape(source) + "/tag"
44-
if err := client.Post(ctx, path, body, nil, opts...); err != nil {
45+
if err := client.Post(ctx, path, tagImageRequest{Target: target}, nil, opts...); err != nil {
4546
if !isNotFoundError(err) {
4647
return err
4748
}
49+
50+
// Keep the Docker fallback for sources that have not been imported into
51+
// Hypeman yet. Once staged, the image is available under the requested
52+
// target and can be pushed through the normal cached-image flow.
4853
staged, stageErr := stageDockerImage(ctx, cmd, &client, source, target)
4954
if stageErr != nil {
50-
return fmt.Errorf("image %q was not found in Hypeman or Docker: %w", source, stageErr)
55+
return fmt.Errorf("image %q was not found in Hypeman; stage it from Docker: %w", source, stageErr)
5156
}
5257
res = []byte(staged.RawJSON())
5358
}

0 commit comments

Comments
 (0)