Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit a3680f2

Browse files
authored
Merge pull request #355 from shin-/360-customizable_target_repo_save_push
Allow user to configure repo name with save and push commands
2 parents b53a913 + bf7312a commit a3680f2

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

cmd/docker-app/push.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
type pushOptions struct {
1212
namespace string
1313
tag string
14+
repo string
1415
}
1516

1617
func pushCmd() *cobra.Command {
@@ -25,7 +26,7 @@ func pushCmd() *cobra.Command {
2526
return err
2627
}
2728
defer app.Cleanup()
28-
dgst, err := packager.Push(app, opts.namespace, opts.tag)
29+
dgst, err := packager.Push(app, opts.namespace, opts.tag, opts.repo)
2930
if err == nil {
3031
fmt.Println(dgst)
3132
}
@@ -34,5 +35,6 @@ func pushCmd() *cobra.Command {
3435
}
3536
cmd.Flags().StringVar(&opts.namespace, "namespace", "", "Namespace to use (default: namespace in metadata)")
3637
cmd.Flags().StringVarP(&opts.tag, "tag", "t", "", "Tag to use (default: version in metadata)")
38+
cmd.Flags().StringVar(&opts.repo, "repo", "", "Name of the remote repository (default: <app-name>.dockerapp)")
3739
return cmd
3840
}

e2e/commands_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ func testImage(registry string) func(*testing.T) {
282282
dir := fs.NewDir(t, "save-prepare-build", fs.WithFile("my.dockerapp", singleFileApp))
283283
defer dir.Remove()
284284
icmd.RunCommand(dockerApp, "push", "--namespace", registry+"/myuser", dir.Join("my.dockerapp")).Assert(t, icmd.Success)
285+
286+
// push with custom repo name
287+
icmd.RunCommand(dockerApp, "push", "-t", "marshmallows", "--namespace", registry+"/rainbows", "--repo", "unicorns", "testdata/render/envvariables/my.dockerapp").Assert(t, icmd.Success)
288+
icmd.RunCommand(dockerApp, "inspect", registry+"/rainbows/unicorns:marshmallows").Assert(t, icmd.Success)
285289
}
286290
}
287291

internal/packager/extract.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,26 @@ func extractImage(appname string, ops ...func(*types.App) error) (*types.App, er
6464
if err != nil {
6565
return nil, err
6666
}
67+
literalImageName := appname
6768
imagename := imageNameFromRef(ref)
6869
appname = appNameFromRef(ref)
6970
tempDir, err := ioutil.TempDir("", "dockerapp")
7071
if err != nil {
7172
return nil, errors.Wrap(err, "failed to create temporary directory")
7273
}
74+
// Attempt loading image based on default name permutation
7375
path, err := Pull(imagename, tempDir)
7476
if err != nil {
75-
os.RemoveAll(tempDir)
76-
return nil, err
77+
if literalImageName == imagename {
78+
os.RemoveAll(tempDir)
79+
return nil, err
80+
}
81+
// Attempt loading image based on the literal name
82+
path, err = Pull(literalImageName, tempDir)
83+
if err != nil {
84+
os.RemoveAll(tempDir)
85+
return nil, err
86+
}
7787
}
7888
ops = append(ops, types.WithName(appname), types.WithCleanup(func() { os.RemoveAll(tempDir) }))
7989
return loader.LoadFromDirectory(path, ops...)

internal/packager/registry.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func Pull(repotag string, outputDir string) (string, error) {
6666
}
6767

6868
// Push pushes an app to a registry. Returns the image digest.
69-
func Push(app *types.App, namespace, tag string) (string, error) {
69+
func Push(app *types.App, namespace, tag, repo string) (string, error) {
7070
payload := make(map[string]string)
7171
payload[internal.MetadataFileName] = string(app.MetadataRaw())
7272
payload[internal.ComposeFileName] = string(app.Composes()[0])
@@ -80,9 +80,12 @@ func Push(app *types.App, namespace, tag string) (string, error) {
8080
tag = metadata.Version
8181
}
8282
}
83+
if repo == "" {
84+
repo = internal.AppNameFromDir(app.Name) + internal.AppExtension
85+
}
8386
if namespace != "" && namespace[len(namespace)-1] != '/' {
8487
namespace += "/"
8588
}
86-
imageName := namespace + internal.AppNameFromDir(app.Name) + internal.AppExtension + ":" + tag
89+
imageName := namespace + repo + ":" + tag
8790
return resto.PushConfigMulti(context.Background(), payload, imageName, resto.RegistryOptions{}, nil)
8891
}

0 commit comments

Comments
 (0)