fix: ensure we push and cleanup the correct images
This commit is contained in:
1 parent
39af6359be
commit
d727dd76ce
3 files changed
+30
-15
No files matched your search
@@ -49,17 +49,16 @@ func incrementTagVersion(appName string) (int, error) {
|
|||||||
return version, nil
|
return version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pushToRegistry(appName string, tag int) error {
|
func pushToRegistry(appName string, tag int, imageID string, imageRepo string) error {
|
||||||
common.LogVerboseQuiet("Retrieving image info for app")
|
common.LogVerboseQuiet("Retrieving image info for app")
|
||||||
|
|
||||||
registryServer := getRegistryServerForApp(appName)
|
registryServer := getRegistryServerForApp(appName)
|
||||||
imageRepo := reportComputedImageRepo(appName)
|
|
||||||
imageTag, _ := common.GetRunningImageTag(appName)
|
imageTag, _ := common.GetRunningImageTag(appName)
|
||||||
image := common.GetAppImageName(appName, imageTag, "")
|
|
||||||
imageID, _ := common.DockerInspect(image, "{{ .Id }}")
|
|
||||||
|
|
||||||
common.LogVerboseQuiet(fmt.Sprintf("Tagging $IMAGE_REPO:%d in registry format", tag))
|
fullImage := fmt.Sprintf("%s%s:%d", registryServer, imageRepo, tag)
|
||||||
if !dockerTag(imageID, fmt.Sprintf("%s%s:%d", registryServer, imageRepo, tag)) {
|
|
||||||
|
common.LogVerboseQuiet(fmt.Sprintf("Tagging %s:%d in registry format", imageRepo, tag))
|
||||||
|
if !dockerTag(imageID, fullImage) {
|
||||||
// TODO: better error
|
// TODO: better error
|
||||||
return errors.New("Unable to tag image")
|
return errors.New("Unable to tag image")
|
||||||
}
|
}
|
||||||
@@ -73,16 +72,17 @@ func pushToRegistry(appName string, tag int) error {
|
|||||||
// This is only really important for registries that do not support creation on push
|
// This is only really important for registries that do not support creation on push
|
||||||
// Examples include AWS and Quay.io
|
// Examples include AWS and Quay.io
|
||||||
|
|
||||||
common.LogVerboseQuiet("Pushing $IMAGE_REPO:$TAG")
|
common.LogVerboseQuiet(fmt.Sprintf("Pushing %s", fullImage))
|
||||||
if !dockerPush(fmt.Sprintf("%s%s:%d", registryServer, imageRepo, tag)) {
|
if !dockerPush(fullImage) {
|
||||||
// TODO: better error
|
// TODO: better error
|
||||||
return errors.New("Unable to push image")
|
return errors.New("Unable to push image")
|
||||||
}
|
}
|
||||||
|
|
||||||
common.LogVerboseQuiet("Cleaning up")
|
common.LogVerboseQuiet("Cleaning up")
|
||||||
imageCleanup(appName, registryServer, imageRepo, imageTag, tag)
|
imageCleanup(appName, fmt.Sprintf("%s%s", registryServer, imageRepo), imageTag, tag)
|
||||||
|
imageCleanup(appName, imageRepo, imageTag, tag)
|
||||||
|
|
||||||
common.LogVerboseQuiet("Image $IMAGE_REPO:$TAG pushed")
|
common.LogVerboseQuiet(fmt.Sprintf("Image %s pushed", fullImage))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,14 +108,14 @@ func dockerPush(imageTag string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func imageCleanup(appName string, registryServer string, imageRepo string, imageTag string, tag int) {
|
func imageCleanup(appName string, imageRepo string, imageTag string, tag int) {
|
||||||
// # keep last two images in place
|
// # keep last two images in place
|
||||||
oldTag := tag - 1
|
oldTag := tag - 1
|
||||||
tenImagesAgoTag := tag - 12
|
tenImagesAgoTag := tag - 12
|
||||||
|
|
||||||
imagesToRemove := []string{}
|
imagesToRemove := []string{}
|
||||||
for oldTag > 0 {
|
for oldTag > 0 {
|
||||||
imagesToRemove = append(imagesToRemove, fmt.Sprintf("%s%s:%d", registryServer, imageRepo, oldTag))
|
common.LogInfo1(fmt.Sprintf("Removing image: %s:%d", imageRepo, oldTag))
|
||||||
imagesToRemove = append(imagesToRemove, fmt.Sprintf("%s:%d", imageRepo, oldTag))
|
imagesToRemove = append(imagesToRemove, fmt.Sprintf("%s:%d", imageRepo, oldTag))
|
||||||
oldTag = oldTag - 1
|
oldTag = oldTag - 1
|
||||||
if tenImagesAgoTag == oldTag {
|
if tenImagesAgoTag == oldTag {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ func main() {
|
|||||||
err = registry.TriggerPostDelete(appName)
|
err = registry.TriggerPostDelete(appName)
|
||||||
case "post-release-builder":
|
case "post-release-builder":
|
||||||
appName := flag.Arg(1)
|
appName := flag.Arg(1)
|
||||||
err = registry.TriggerPostReleaseBuilder(appName)
|
image := flag.Arg(2)
|
||||||
|
err = registry.TriggerPostReleaseBuilder(appName, image)
|
||||||
case "report":
|
case "report":
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
err = registry.ReportSingleApp(appName, "", "")
|
err = registry.ReportSingleApp(appName, "", "")
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package registry
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
@@ -53,7 +55,19 @@ func TriggerPostDelete(appName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TriggerPostReleaseBuilder pushes the image to the remote registry
|
// TriggerPostReleaseBuilder pushes the image to the remote registry
|
||||||
func TriggerPostReleaseBuilder(appName string) error {
|
func TriggerPostReleaseBuilder(appName string, image string) error {
|
||||||
|
imageID, _ := common.DockerInspect(image, "{{ .Id }}")
|
||||||
|
imageRepo := common.GetAppImageRepo(appName)
|
||||||
|
computedImageRepo := reportComputedImageRepo(appName)
|
||||||
|
newImage := strings.Replace(image, imageRepo+":", computedImageRepo+":", 1)
|
||||||
|
|
||||||
|
if computedImageRepo != imageRepo {
|
||||||
|
if !dockerTag(imageID, newImage) {
|
||||||
|
// TODO: better error
|
||||||
|
return errors.New("Unable to tag image")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !isPushEnabled(appName) {
|
if !isPushEnabled(appName) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -64,5 +78,5 @@ func TriggerPostReleaseBuilder(appName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return pushToRegistry(appName, imageTag)
|
return pushToRegistry(appName, imageTag, imageID, computedImageRepo)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user