2021-03-04 20:44:49 -05:00
|
|
|
package registry
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
2021-08-05 01:13:36 -04:00
|
|
|
"strings"
|
2021-03-04 20:44:49 -05:00
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-19 16:50:32 -04:00
|
|
|
// TriggerDeployedAppImageRepo outputs the associated image repo to stdout
|
|
|
|
|
func TriggerDeployedAppImageRepo(appName string) error {
|
2024-01-19 06:20:43 -05:00
|
|
|
imageRepo := strings.TrimSpace(reportImageRepo(appName))
|
|
|
|
|
if imageRepo == "" {
|
|
|
|
|
var err error
|
|
|
|
|
imageRepo, err = getImageRepoFromTemplate(appName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("Unable to determine image repo from template: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 16:50:32 -04:00
|
|
|
if imageRepo == "" {
|
|
|
|
|
imageRepo = common.GetAppImageRepo(appName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(imageRepo)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerDeployedAppImageTag outputs the associated image tag to stdout
|
|
|
|
|
func TriggerDeployedAppImageTag(appName string) error {
|
2021-08-05 01:12:30 -04:00
|
|
|
if !isPushEnabled(appName) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 16:50:32 -04:00
|
|
|
tagVersion := common.PropertyGet("registry", appName, "tag-version")
|
2023-06-02 19:35:23 -04:00
|
|
|
tagVersion = strings.TrimSpace(tagVersion)
|
2021-03-19 16:50:32 -04:00
|
|
|
if tagVersion == "" {
|
|
|
|
|
tagVersion = "1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println(tagVersion)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 22:16:51 -05:00
|
|
|
// TriggerDeployedAppRepository outputs the associated registry repository to stdout
|
|
|
|
|
func TriggerDeployedAppRepository(appName string) error {
|
2021-03-19 16:50:32 -04:00
|
|
|
fmt.Println(getRegistryServerForApp(appName))
|
2021-03-19 16:31:13 -04:00
|
|
|
return nil
|
2021-03-04 22:16:51 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 20:44:49 -05:00
|
|
|
// TriggerInstall runs the install step for the registry plugin
|
|
|
|
|
func TriggerInstall() error {
|
|
|
|
|
if err := common.PropertySetup("registry"); err != nil {
|
|
|
|
|
return fmt.Errorf("Unable to install the registry plugin: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 23:49:46 -04:00
|
|
|
// TriggerPostAppCloneSetup creates new registry files
|
|
|
|
|
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
|
|
|
|
err := common.PropertyClone("registry", oldAppName, newAppName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TriggerPostAppRenameSetup renames registry files
|
|
|
|
|
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
|
|
|
|
if err := common.PropertyClone("registry", oldAppName, newAppName); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := common.PropertyDestroy("registry", oldAppName); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 20:44:49 -05:00
|
|
|
// TriggerPostDelete destroys the registry property for a given app container
|
|
|
|
|
func TriggerPostDelete(appName string) error {
|
|
|
|
|
return common.PropertyDestroy("registry", appName)
|
|
|
|
|
}
|
2021-03-04 22:16:51 -05:00
|
|
|
|
|
|
|
|
// TriggerPostReleaseBuilder pushes the image to the remote registry
|
2021-08-05 01:13:36 -04:00
|
|
|
func TriggerPostReleaseBuilder(appName string, image string) error {
|
2021-08-14 01:23:30 -04:00
|
|
|
parts := strings.Split(image, ":")
|
2021-08-13 01:42:11 -04:00
|
|
|
imageTag := parts[len(parts)-1]
|
2024-04-04 02:34:29 -04:00
|
|
|
if common.PlugnTriggerExists("pre-deploy") {
|
|
|
|
|
common.LogWarn("Deprecated: please upgrade plugin to use 'pre-release-builder' plugin trigger instead of pre-deploy")
|
|
|
|
|
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
|
|
|
|
Trigger: "pre-deploy",
|
|
|
|
|
Args: []string{appName, imageTag},
|
|
|
|
|
StreamStdio: true,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2021-08-13 01:42:11 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-14 01:23:30 -04:00
|
|
|
imageID, _ := common.DockerInspect(image, "{{ .Id }}")
|
|
|
|
|
imageRepo := common.GetAppImageRepo(appName)
|
|
|
|
|
computedImageRepo := reportComputedImageRepo(appName)
|
|
|
|
|
newImage := strings.Replace(image, imageRepo+":", computedImageRepo+":", 1)
|
|
|
|
|
|
2021-08-05 01:13:36 -04:00
|
|
|
if computedImageRepo != imageRepo {
|
2025-06-25 17:47:39 +05:30
|
|
|
if err := dockerTag(imageID, newImage); err != nil {
|
|
|
|
|
return fmt.Errorf("unable to tag image %s as %s: %w", imageID, newImage, err)
|
2021-08-05 01:13:36 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 22:16:51 -05:00
|
|
|
if !isPushEnabled(appName) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
common.LogInfo1("Pushing image to registry")
|
2021-08-13 01:42:11 -04:00
|
|
|
newTag, err := incrementTagVersion(appName)
|
2021-03-04 22:16:51 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 01:42:11 -04:00
|
|
|
return pushToRegistry(appName, newTag, imageID, computedImageRepo)
|
2021-03-04 22:16:51 -05:00
|
|
|
}
|