From 894cae8a75697854290c7d9282a5c9f1a3a7aed1 Mon Sep 17 00:00:00 2001 From: luktom Date: Mon, 6 Aug 2018 10:24:59 +0200 Subject: [PATCH 1/3] Rename arguments --- main.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index a861104d..aece8987 100644 --- a/main.go +++ b/main.go @@ -46,7 +46,7 @@ func moveLayerUsingFile(srcHub *registry.Registry, destHub *registry.Registry, s imageReadStream, err := os.Open(file.Name()) if err != nil { - return fmt.Errorf("Failed to open the temporary image layer for uploading. %v", err) + return fmt.Errorf("Failed to open temporary image layer for uploading. %v", err) } err = destHub.UploadLayer(destRepo, layerDigest, imageReadStream) imageReadStream.Close() @@ -58,19 +58,19 @@ func moveLayerUsingFile(srcHub *registry.Registry, destHub *registry.Registry, s } func migrateLayer(srcHub *registry.Registry, destHub *registry.Registry, srcRepo string, destRepo string, layer schema1.FSLayer) error { - fmt.Println("Checking if manifest layer exists in destiation registery") + fmt.Println("Checking if manifest layer exists in destination registery") layerDigest := layer.BlobSum hasLayer, err := destHub.HasLayer(destRepo, layerDigest) if err != nil { - return fmt.Errorf("Failure while checking if the destiation registry contained an image layer. %v", err) + return fmt.Errorf("Failure while checking if the destination registry contained an image layer. %v", err) } if !hasLayer { - fmt.Println("Need to upload layer", layerDigest, "to the destiation") + fmt.Println("Need to upload layer", layerDigest, "to the destination") tempFile, err := ioutil.TempFile("", "docker-image") if err != nil { - return fmt.Errorf("Failure while a creating temporary file for an image layer download. %v", err) + return fmt.Errorf("Failure while creating temporary file for an image layer download. %v", err) } err = moveLayerUsingFile(srcHub, destHub, srcRepo, destRepo, layer, tempFile) @@ -94,15 +94,15 @@ type RepositoryArguments struct { } func buildRegistryArguments(argPrefix string, argDescription string) RepositoryArguments { - registryURLName := fmt.Sprintf("%sURL", argPrefix) + registryURLName := fmt.Sprintf("%s-url", argPrefix) registryURLDescription := fmt.Sprintf("URL of %s registry", argDescription) registryURLArg := kingpin.Flag(registryURLName, registryURLDescription).String() - repositoryName := fmt.Sprintf("%sRepo", argPrefix) + repositoryName := fmt.Sprintf("%s-repo", argPrefix) repositoryDescription := fmt.Sprintf("Name of the %s repository", argDescription) repositoryArg := kingpin.Flag(repositoryName, repositoryDescription).String() - tagName := fmt.Sprintf("%sTag", argPrefix) + tagName := fmt.Sprintf("%s-tag", argPrefix) tagDescription := fmt.Sprintf("Name of the %s tag", argDescription) tagArg := kingpin.Flag(tagName, tagDescription).String() @@ -157,7 +157,7 @@ func connectToRegistry(args RepositoryArguments) (*registry.Registry, error) { err = registry.Ping() if err != nil { - return nil, fmt.Errorf("Failed to to ping registry %s as a connection test. %v", origUrl, err) + return nil, fmt.Errorf("Failed to ping registry %s as a connection test. %v", origUrl, err) } return registry, nil @@ -170,9 +170,9 @@ func main() { }() srcArgs := buildRegistryArguments("src", "source") - destArgs := buildRegistryArguments("dest", "destiation") - repoArg := kingpin.Flag("repo", "The repository in the source and the destiation. Values provided by --srcRepo or --destTag will override this value").String() - tagArg := kingpin.Flag("tag", "The tag name in the source and the destiation. Values provided by --srcTag or --destTag will override this value").Default("latest").String() + destArgs := buildRegistryArguments("dest", "destination") + repoArg := kingpin.Flag("repo", "The repository in the source and the destination. Values provided by --src-repo or --dest-tag will override this value").String() + tagArg := kingpin.Flag("tag", "The tag name in the source and the destination. Values provided by --src-tag or --dest-tag will override this value").Default("latest").String() kingpin.Parse() if *srcArgs.Repository == "" { @@ -190,13 +190,13 @@ func main() { } if *srcArgs.Repository == "" { - fmt.Printf("A source repository name is required either with --srcRepo or --repo") + fmt.Printf("A source repository name is required either with --src-repo or --repo") exitCode = -1 return } if *destArgs.Repository == "" { - fmt.Printf("A destiation repository name is required either with --destRepo or --repo") + fmt.Printf("A destination repository name is required either with --dest-repo or --repo") exitCode = -1 return } From 387ba0caebda12122d924c9aaf65f435c60093fa Mon Sep 17 00:00:00 2001 From: luktom Date: Wed, 8 Aug 2018 13:25:20 +0200 Subject: [PATCH 2/3] Update README to match new flag format --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index adbc6140..cb89faa8 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ ## Overview -When doing automated deployments, especially when using AWS ECR in multiple accounts, you might want to copy images from one registry to another without the need for a full docker installation. At LifeOmic we wanted to orchestrate the copying of images while executing inside a container without exposing a full Docker socker just for image manipulation. +When doing automated deployments, especially when using AWS ECR in multiple accounts, you might want to copy images from one registry to another without the need for a full docker installation. At LifeOmic we wanted to orchestrate the copying of images while executing inside a container without exposing a full Docker socket just for image manipulation. To copy an image between two anonymous repositories, you can use a command line like: ``` -$ copy-docker-image --srcRepo http://registry1/ --destRepo http://registry2 --repo project +$ copy-docker-image --src-repo http://registry1/ --dest-repo http://registry2 --repo project ``` To specify an image tag, just add a --tag argument like: ``` -$ copy-docker-image --srcRepo http://registry1/ --destRepo http://registry2 --repo project --tag v1 +$ copy-docker-image --src-repo http://registry1/ --dest-repo http://registry2 --repo project --tag v1 ``` ## Integration with AWS ECR @@ -22,7 +22,7 @@ $ copy-docker-image --srcRepo http://registry1/ --destRepo http://registry2 --re Because copy to AWS ECR was common a special URL format was added to automatically look up the right HTTPS URL and authorization token. Assuming a AWS CLI profile has been created for your account you can use a command like: ``` -$ copy-docker-image --srcRepo http://registry1/ --destRepo ecr: --repo project +$ copy-docker-image --src-repo http://registry1/ --dest-repo ecr: --repo project ``` ## Installation From 58f02b5b12f0b288ca0f784befe0adc264c92295 Mon Sep 17 00:00:00 2001 From: luktom Date: Wed, 8 Aug 2018 13:27:02 +0200 Subject: [PATCH 3/3] Fix typos in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cb89faa8..f235891b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# move-docker-image - Copy docker images without a full docker installation +# copy-docker-image - Copy docker images without a full docker installation [![Build Status](https://travis-ci.org/mdlavin/copy-docker-image.svg?branch=master)](https://travis-ci.org/mdlavin/copy-docker-image) ## Overview