Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit be49d0b

Browse files
authored
Improve acorn copy and move all code to CLI (#2116)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent ab51559 commit be49d0b

File tree

21 files changed

+278
-766
lines changed

21 files changed

+278
-766
lines changed

docs/docs/100-reference/01-command-line/acorn_copy.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ Copy Acorn images between registries
88
```
99
acorn copy [flags] SOURCE DESTINATION
1010
11-
This command can copy local images to remote registries, and can copy images between remote registries.
12-
It cannot copy images from remote registries to the local registry (use acorn pull instead).
13-
14-
The --all-tags option only works with remote registries.
11+
This command copies Acorn images between remote image registries.
12+
It does not interact with images stored in the Acorn internal registry, or with the Acorn API in any way.
1513
```
1614

1715
### Examples
1816

1917
```
20-
# Copy the local image tagged "myimage:v1" to Docker Hub:
21-
acorn copy myimage:v1 docker.io/<username>/myimage:v1
22-
2318
# Copy an image from Docker Hub to GHCR:
2419
acorn copy docker.io/<username>/myimage:v1 ghcr.io/<username>/myimage:v1
2520
21+
# Copy the 'main' tag on an image to the 'prod' tag on the same image, and overwrite if it already exists:
22+
acorn copy docker.io/<username>/myimage:main prod --force
23+
2624
# Copy all tags on a particular image repo in Docker Hub to GHCR:
2725
acorn copy --all-tags docker.io/<username>/myimage ghcr.io/<username>/myimage
2826
```

docs/docs/100-reference/01-command-line/acorn_image_copy.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,19 @@ Copy Acorn images between registries
88
```
99
acorn image copy [flags] SOURCE DESTINATION
1010
11-
This command can copy local images to remote registries, and can copy images between remote registries.
12-
It cannot copy images from remote registries to the local registry (use acorn pull instead).
13-
14-
The --all-tags option only works with remote registries.
11+
This command copies Acorn images between remote image registries.
12+
It does not interact with images stored in the Acorn internal registry, or with the Acorn API in any way.
1513
```
1614

1715
### Examples
1816

1917
```
20-
# Copy the local image tagged "myimage:v1" to Docker Hub:
21-
acorn copy myimage:v1 docker.io/<username>/myimage:v1
22-
2318
# Copy an image from Docker Hub to GHCR:
2419
acorn copy docker.io/<username>/myimage:v1 ghcr.io/<username>/myimage:v1
2520
21+
# Copy the 'main' tag on an image to the 'prod' tag on the same image, and overwrite if it already exists:
22+
acorn copy docker.io/<username>/myimage:main prod --force
23+
2624
# Copy all tags on a particular image repo in Docker Hub to GHCR:
2725
acorn copy --all-tags docker.io/<username>/myimage ghcr.io/<username>/myimage
2826
```

integration/client/images/images_test.go

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/acorn-io/runtime/integration/helper"
1010
"github.com/acorn-io/runtime/pkg/client"
1111
kclient "github.com/acorn-io/runtime/pkg/k8sclient"
12-
"github.com/google/go-containerregistry/pkg/name"
13-
"github.com/google/go-containerregistry/pkg/v1/remote"
1412
"github.com/stretchr/testify/assert"
1513
apierrors "k8s.io/apimachinery/pkg/api/errors"
1614
)
@@ -418,110 +416,3 @@ func TestImageBadTag(t *testing.T) {
418416
err = c.ImageTag(ctx, image.Name, "foo@@:badtag")
419417
assert.Equal(t, "could not parse reference: foo@@:badtag", err.Error())
420418
}
421-
422-
func TestImageCopy(t *testing.T) {
423-
helper.StartController(t)
424-
helper.StartAPI(t)
425-
registry, closeRegistry := helper.StartRegistry(t)
426-
t.Cleanup(closeRegistry)
427-
428-
ctx := helper.GetCTX(t)
429-
c, _ := helper.ClientAndProject(t)
430-
431-
// Step 1: build an image and copy it to the registry
432-
image, err := c.AcornImageBuild(ctx, "../testdata/nginx/Acornfile", &client.AcornImageBuildOptions{
433-
Cwd: "../testdata/nginx",
434-
})
435-
if err != nil {
436-
t.Fatal(err)
437-
}
438-
439-
remoteTagName := registry + "/test:ci"
440-
441-
progress, err := c.ImageCopy(ctx, image.ID, remoteTagName, nil)
442-
if err != nil {
443-
t.Fatal(err)
444-
}
445-
446-
for update := range progress {
447-
if update.Error != "" {
448-
t.Fatal(update.Error)
449-
}
450-
}
451-
452-
// Step 2: build a second image and attempt to copy it to the registry - should fail because "force" is not set
453-
image2, err := c.AcornImageBuild(ctx, "../testdata/sidecar/Acornfile", &client.AcornImageBuildOptions{
454-
Cwd: "../testdata/sidecar",
455-
})
456-
if err != nil {
457-
t.Fatal(err)
458-
}
459-
460-
progress, err = c.ImageCopy(ctx, image2.ID, remoteTagName, nil)
461-
if err != nil {
462-
t.Fatal(err)
463-
}
464-
465-
var errorFound bool
466-
for update := range progress {
467-
if update.Error != "" {
468-
errorFound = true
469-
assert.Contains(t, update.Error, "not copying image")
470-
assert.Contains(t, update.Error, "since it already exists")
471-
}
472-
}
473-
assert.True(t, errorFound)
474-
475-
// Now that it failed, force copy it to make sure that works
476-
progress, err = c.ImageCopy(ctx, image2.ID, remoteTagName, &client.ImageCopyOptions{Force: true})
477-
if err != nil {
478-
t.Fatal(err)
479-
}
480-
481-
for update := range progress {
482-
if update.Error != "" {
483-
t.Fatal(update.Error)
484-
}
485-
}
486-
487-
// Step 4: copy the first image again, this time under a different tag
488-
progress, err = c.ImageCopy(ctx, image.ID, remoteTagName+"-2", nil)
489-
if err != nil {
490-
t.Fatal(err)
491-
}
492-
493-
for update := range progress {
494-
if update.Error != "" {
495-
t.Fatal(update.Error)
496-
}
497-
}
498-
499-
// Step 5: copy all tags from the first image in the registry to a new image in the registry
500-
oldRemoteRepo := registry + "/test"
501-
newRemoteRepo := registry + "/test2"
502-
progress, err = c.ImageCopy(ctx, oldRemoteRepo, newRemoteRepo, &client.ImageCopyOptions{AllTags: true})
503-
if err != nil {
504-
t.Fatal(err)
505-
}
506-
507-
for update := range progress {
508-
if update.Error != "" {
509-
t.Fatal(update.Error)
510-
}
511-
}
512-
513-
// Step 6: verify that both tags exist in the registry
514-
repo, err := name.NewRepository(newRemoteRepo)
515-
if err != nil {
516-
t.Fatal(err)
517-
}
518-
519-
tags, err := remote.List(repo, remote.WithContext(ctx))
520-
if err != nil {
521-
t.Fatal(err)
522-
}
523-
524-
assert.Len(t, tags, 2)
525-
assert.Contains(t, tags, "ci")
526-
assert.Contains(t, tags, "ci-2")
527-
}

pkg/apis/api.acorn.io/v1/scheme.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func AddToSchemeWithGV(scheme *runtime.Scheme, schemeGroupVersion schema.GroupVe
3838
&ImageTag{},
3939
&ImagePush{},
4040
&ImagePull{},
41-
&ImageCopy{},
4241
&ImageSignature{},
4342
&Info{},
4443
&InfoList{},

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,6 @@ type ImagePull struct {
185185
Auth *RegistryAuth `json:"auth,omitempty"`
186186
}
187187

188-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
189-
190-
type ImageCopy struct {
191-
metav1.TypeMeta `json:",inline"`
192-
Source string `json:"source,omitempty"`
193-
Dest string `json:"dest,omitempty"`
194-
SourceAuth *RegistryAuth `json:"sourceAuth,omitempty"`
195-
DestAuth *RegistryAuth `json:"destAuth,omitempty"`
196-
AllTags bool `json:"allTags,omitempty"`
197-
Force bool `json:"force,omitempty"`
198-
}
199-
200188
type LogMessage struct {
201189
Line string `json:"line,omitempty"`
202190
AppName string `json:"appName,omitempty"`

pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)