feat: implement :clone and :rename
This commit is contained in:
@@ -96,6 +96,16 @@ func getAppName(args []string) (appName string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func getNewAppName(args []string) (appName string, err error) {
|
||||
if len(args) >= 2 {
|
||||
appName = args[1]
|
||||
} else {
|
||||
err = errors.New("Please specify an new app name")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func listImagesByAppLabel(appName string) ([]string, error) {
|
||||
command := []string{
|
||||
common.DockerBin(),
|
||||
|
||||
@@ -19,8 +19,10 @@ func main() {
|
||||
switch subcommand {
|
||||
case "clone":
|
||||
args := flag.NewFlagSet("apps:clone", flag.ExitOnError)
|
||||
skipDeploy := args.Bool("skip-deploy", false, "--skip-deploy: skip deploy of the new app")
|
||||
ignoreExisting := args.Bool("ignore-existing", false, "--ignore-existing: exit 0 if new app already exists")
|
||||
args.Parse(os.Args[2:])
|
||||
err = apps.CommandClone(args.Args())
|
||||
err = apps.CommandClone(args.Args(), *skipDeploy, *ignoreExisting)
|
||||
case "create":
|
||||
args := flag.NewFlagSet("apps:create", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
@@ -47,8 +49,9 @@ func main() {
|
||||
err = apps.CommandLocked(args.Args())
|
||||
case "rename":
|
||||
args := flag.NewFlagSet("apps:rename", flag.ExitOnError)
|
||||
skipDeploy := args.Bool("skip-deploy", false, "--skip-deploy: skip deploy of the new app")
|
||||
args.Parse(os.Args[2:])
|
||||
err = apps.CommandRename(args.Args())
|
||||
err = apps.CommandRename(args.Args(), *skipDeploy)
|
||||
case "report":
|
||||
args := flag.NewFlagSet("apps:report", flag.ExitOnError)
|
||||
args.Parse(os.Args[2:])
|
||||
|
||||
@@ -10,13 +10,55 @@ import (
|
||||
)
|
||||
|
||||
// CommandClone clones an app
|
||||
func CommandClone(args []string) error {
|
||||
appName, err := getAppName(args)
|
||||
func CommandClone(args []string, skipDeploy bool, ignoreExisting bool) error {
|
||||
oldAppName, err := getAppName(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(appName)
|
||||
newAppName, err := getNewAppName(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = common.IsValidAppName(oldAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = common.IsValidAppName(newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = appExists(oldAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = appExists(newAppName); err == nil {
|
||||
if ignoreExisting {
|
||||
common.LogWarn("Name is already taken")
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("Name is already taken")
|
||||
}
|
||||
|
||||
common.LogInfo1Quiet(fmt.Sprintf("Cloning %s to %s", oldAppName, newAppName))
|
||||
if err = createApp(newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = PlugnTrigger("post-app-clone-setup", []string{oldAppName, newAppName}...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if skipDeploy {
|
||||
os.Setenv("SKIP_REBUILD", "true")
|
||||
}
|
||||
|
||||
if err = PlugnTrigger("post-app-clone", []string{oldAppName, newAppName}...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -116,13 +158,55 @@ func CommandLocked(args []string) error {
|
||||
}
|
||||
|
||||
// CommandRename renames an app
|
||||
func CommandRename(args []string) error {
|
||||
func CommandRename(args []string, skipDeploy bool) error {
|
||||
appName, err := getAppName(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(appName)
|
||||
newAppName, err := getNewAppName(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = common.IsValidAppName(oldAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = common.IsValidAppName(newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = appExists(oldAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = appExists(newAppName); err == nil {
|
||||
return errors.New("Name is already taken")
|
||||
}
|
||||
|
||||
common.LogInfo1Quiet(fmt.Sprintf("Renaming %s to %s", oldAppName, newAppName))
|
||||
if err = createApp(newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = PlugnTrigger("post-app-rename-setup", []string{oldAppName, newAppName}...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
os.Setenv("DOKKU_APPS_FORCE_DELETE", "1")
|
||||
if err = destroyApp(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if skipDeploy {
|
||||
os.Setenv("SKIP_REBUILD", "true")
|
||||
}
|
||||
|
||||
if err = PlugnTrigger("post-app-rename", []string{oldAppName, newAppName}...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user