From dc04ab912d86db9d05e6d1668b014e83fff1c3c8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 2 Aug 2021 00:42:54 -0400 Subject: [PATCH] feat: tag image --- plugins/registry/functions.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/registry/functions.go b/plugins/registry/functions.go index fe94f1d58..9cf36e696 100644 --- a/plugins/registry/functions.go +++ b/plugins/registry/functions.go @@ -1,10 +1,12 @@ package registry import ( + "errors" "fmt" "strconv" "strings" + "github.com/codeskyblue/go-sh" "github.com/dokku/dokku/plugins/common" ) @@ -56,8 +58,15 @@ func pushToRegistry(appName string, tag string) error { imageID, _ := common.DockerInspect(image, "{{ .Id }}") common.LogVerboseQuiet(fmt.Sprintf("Tagging $IMAGE_REPO:%s in registry format", tag)) - // docker tag "$IMAGE_ID" "${DOKKU_REGISTRY_SERVER}${IMAGE_REPO}:${TAG}" - // docker tag "$IMAGE_ID" "${IMAGE_REPO}:${TAG}" + if !dockerTag(imageID, fmt.Sprintf("%s%s:%s", registryServer, imageRepo, tag)) { + // TODO: better error + return errors.New("Unable to tag image") + } + + if !dockerTag(imageID, fmt.Sprintf("%s:%s", imageRepo, tag)) { + // TODO: better error + return errors.New("Unable to tag image") + } // fn-registry-create-repository "$APP" "$DOKKU_REGISTRY_SERVER" "$IMAGE_REPO" @@ -70,3 +79,14 @@ func pushToRegistry(appName string, tag string) error { common.LogVerboseQuiet("Image $IMAGE_REPO:$TAG pushed") return nil } + +func dockerTag(imageID string, imageTag string) bool { + cmd := sh.Command(common.DockerBin(), "image", "tag", imageID, imageTag) + cmd.Stdout = nil + cmd.Stderr = nil + if err := cmd.Run(); err != nil { + return false + } + + return true +}