fix: allow renaming old applications to new format
0.22.0 changed allowed values for app names, making it more difficult for users to fix their app names - you need to either downgrade+rename or recreate the app. The `apps:rename` command can now rename these old applications to the new standard. Also drop some app name verification from internal commands. Duplicate verification doesn't help much, and though it isn't excessively slow, it does prevent us from running commands against old apps that exist. Refs #4267
This commit is contained in:
1 parent
3d77de20cc
commit
d7b23b84f0
9 files changed
+77
-44
No files matched your search
@@ -83,6 +83,17 @@ func destroyApp(appName string) error {
|
|||||||
|
|
||||||
forceCleanup := true
|
forceCleanup := true
|
||||||
common.DockerCleanup(appName, forceCleanup)
|
common.DockerCleanup(appName, forceCleanup)
|
||||||
|
|
||||||
|
// remove contents for apps that are symlinks to other folders
|
||||||
|
if err := os.RemoveAll(fmt.Sprintf("%v/", common.AppRoot(appName))); err != nil {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// then remove the folder and/or the symlink
|
||||||
|
if err := os.RemoveAll(common.AppRoot(appName)); err != nil {
|
||||||
|
common.LogWarn(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func CommandClone(oldAppName string, newAppName string, skipDeploy bool, ignoreE
|
|||||||
return errors.New("Please specify an new app name")
|
return errors.New("Please specify an new app name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.IsValidAppName(oldAppName); err != nil {
|
if err := common.VerifyAppName(oldAppName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +26,6 @@ func CommandClone(oldAppName string, newAppName string, skipDeploy bool, ignoreE
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := appExists(oldAppName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := appExists(newAppName); err == nil {
|
if err := appExists(newAppName); err == nil {
|
||||||
if ignoreExisting {
|
if ignoreExisting {
|
||||||
common.LogWarn("Name is already taken")
|
common.LogWarn("Name is already taken")
|
||||||
@@ -61,8 +57,8 @@ func CommandClone(oldAppName string, newAppName string, skipDeploy bool, ignoreE
|
|||||||
|
|
||||||
// CommandCreate creates app via command line
|
// CommandCreate creates app via command line
|
||||||
func CommandCreate(appName string) error {
|
func CommandCreate(appName string) error {
|
||||||
if appName == "" {
|
if err := common.IsValidAppName(appName); err != nil {
|
||||||
return errors.New("Please specify an app to run the command on")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return createApp(appName)
|
return createApp(appName)
|
||||||
@@ -70,8 +66,8 @@ func CommandCreate(appName string) error {
|
|||||||
|
|
||||||
// CommandDestroy destroys an app
|
// CommandDestroy destroys an app
|
||||||
func CommandDestroy(appName string, force bool) error {
|
func CommandDestroy(appName string, force bool) error {
|
||||||
if appName == "" {
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
return errors.New("Please specify an app to run the command on")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if force {
|
if force {
|
||||||
@@ -153,7 +149,7 @@ func CommandRename(oldAppName string, newAppName string, skipDeploy bool) error
|
|||||||
return errors.New("Please specify an new app name")
|
return errors.New("Please specify an new app name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.IsValidAppName(oldAppName); err != nil {
|
if err := common.VerifyAppName(oldAppName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,10 +157,6 @@ func CommandRename(oldAppName string, newAppName string, skipDeploy bool) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := appExists(oldAppName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := appExists(newAppName); err == nil {
|
if err := appExists(newAppName); err == nil {
|
||||||
return errors.New("Name is already taken")
|
return errors.New("Name is already taken")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package apps
|
package apps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/dokku/dokku/plugins/common"
|
"github.com/dokku/dokku/plugins/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,16 +28,6 @@ func TriggerAppMaybeCreate(appName string) error {
|
|||||||
func TriggerPostDelete(appName string) error {
|
func TriggerPostDelete(appName string) error {
|
||||||
imageRepo := common.GetAppImageRepo(appName)
|
imageRepo := common.GetAppImageRepo(appName)
|
||||||
|
|
||||||
// remove contents for apps that are symlinks to other folders
|
|
||||||
if err := os.RemoveAll(fmt.Sprintf("%v/", common.AppRoot(appName))); err != nil {
|
|
||||||
common.LogWarn(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// then remove the folder and/or the symlink
|
|
||||||
if err := os.RemoveAll(common.AppRoot(appName)); err != nil {
|
|
||||||
common.LogWarn(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
imagesByAppLabel, err := listImagesByAppLabel(appName)
|
imagesByAppLabel, err := listImagesByAppLabel(appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogWarn(err.Error())
|
common.LogWarn(err.Error())
|
||||||
|
|||||||
@@ -416,10 +416,10 @@ func UcFirst(str string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValidAppName verifies app name format
|
// IsValidAppName verifies that the app name matches naming restrictions
|
||||||
func IsValidAppName(appName string) error {
|
func IsValidAppName(appName string) error {
|
||||||
if appName == "" {
|
if appName == "" {
|
||||||
return fmt.Errorf("APP must not be null")
|
return errors.New("Please specify an app to run the command on")
|
||||||
}
|
}
|
||||||
|
|
||||||
r, _ := regexp.Compile("^[a-z0-9][^/:_A-Z]*$")
|
r, _ := regexp.Compile("^[a-z0-9][^/:_A-Z]*$")
|
||||||
@@ -430,10 +430,27 @@ func IsValidAppName(appName string) error {
|
|||||||
return errors.New("App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores")
|
return errors.New("App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores")
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyAppName verifies app name format and app existence"
|
// isValidAppNameOld verifies that the app name matches the old naming restrictions
|
||||||
|
func isValidAppNameOld(appName string) error {
|
||||||
|
if appName == "" {
|
||||||
|
return errors.New("Please specify an app to run the command on")
|
||||||
|
}
|
||||||
|
|
||||||
|
r, _ := regexp.Compile("^[a-z0-9][^/:A-Z]*$")
|
||||||
|
if r.MatchString(appName) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, or colons")
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifyAppName checks if an app conforming to either the old or new
|
||||||
|
// naming conventions exists
|
||||||
func VerifyAppName(appName string) error {
|
func VerifyAppName(appName string) error {
|
||||||
if err := IsValidAppName(appName); err != nil {
|
newErr := IsValidAppName(appName)
|
||||||
return err
|
oldErr := isValidAppNameOld(appName)
|
||||||
|
if newErr != nil && oldErr != nil {
|
||||||
|
return newErr
|
||||||
}
|
}
|
||||||
|
|
||||||
appRoot := AppRoot(appName)
|
appRoot := AppRoot(appName)
|
||||||
|
|||||||
@@ -181,9 +181,9 @@ dokku_container_log_verbose_quiet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
is_valid_app_name() {
|
is_valid_app_name() {
|
||||||
declare desc="verify app name format"
|
declare desc="verify that the app name matches naming restrictions"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
[[ -z "$APP" ]] && dokku_log_fail "APP must not be null"
|
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||||
if [[ "$APP" =~ ^[a-z].* ]] || [[ "$APP" =~ ^[0-9].* ]]; then
|
if [[ "$APP" =~ ^[a-z].* ]] || [[ "$APP" =~ ^[0-9].* ]]; then
|
||||||
if [[ ! $APP =~ [A-Z] ]] && [[ ! $APP =~ [:] ]] && [[ ! $APP =~ [_] ]]; then
|
if [[ ! $APP =~ [A-Z] ]] && [[ ! $APP =~ [:] ]] && [[ ! $APP =~ [_] ]]; then
|
||||||
return 0
|
return 0
|
||||||
@@ -193,10 +193,31 @@ is_valid_app_name() {
|
|||||||
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores"
|
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_valid_app_name_old() {
|
||||||
|
declare desc="verify that the app name matches the old naming restrictions"
|
||||||
|
local APP="$1"
|
||||||
|
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||||
|
if [[ "$APP" =~ ^[a-z].* ]] || [[ "$APP" =~ ^[0-9].* ]]; then
|
||||||
|
if [[ ! $APP =~ [A-Z] ]] && [[ ! $APP =~ [:] ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, or colons"
|
||||||
|
}
|
||||||
|
|
||||||
verify_app_name() {
|
verify_app_name() {
|
||||||
declare desc="verify app name format and app existence"
|
declare desc="verify app name format and app existence"
|
||||||
local APP="$1"
|
declare APP="$1"
|
||||||
is_valid_app_name "$APP"
|
local VALID_NEW=false
|
||||||
|
local VALID_OLD=false
|
||||||
|
is_valid_app_name "$APP" 2>/dev/null && VALID_NEW=true
|
||||||
|
is_valid_app_name_old "$APP" 2>/dev/null && VALID_OLD=true
|
||||||
|
|
||||||
|
if [[ "$VALID_NEW" == "false" ]] && [[ "$VALID_OLD" == "false" ]]; then
|
||||||
|
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores"
|
||||||
|
fi
|
||||||
|
|
||||||
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist"
|
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@@ -216,7 +237,6 @@ get_app_image_repo() {
|
|||||||
declare desc="central definition of image repo pattern"
|
declare desc="central definition of image repo pattern"
|
||||||
local APP="$1"
|
local APP="$1"
|
||||||
local IMAGE_REPO="dokku/$APP"
|
local IMAGE_REPO="dokku/$APP"
|
||||||
is_valid_app_name "$APP"
|
|
||||||
echo "$IMAGE_REPO"
|
echo "$IMAGE_REPO"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +245,6 @@ get_deploying_app_image_name() {
|
|||||||
local APP="$1"
|
local APP="$1"
|
||||||
local IMAGE_TAG="$2"
|
local IMAGE_TAG="$2"
|
||||||
IMAGE_REPO="$3"
|
IMAGE_REPO="$3"
|
||||||
is_valid_app_name "$APP"
|
|
||||||
|
|
||||||
local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP")
|
local IMAGE_REMOTE_REPOSITORY=$(plugn trigger deployed-app-repository "$APP")
|
||||||
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
|
local NEW_IMAGE_TAG=$(plugn trigger deployed-app-image-tag "$APP")
|
||||||
@@ -246,7 +265,6 @@ get_app_image_name() {
|
|||||||
local APP="$1"
|
local APP="$1"
|
||||||
local IMAGE_TAG="$2"
|
local IMAGE_TAG="$2"
|
||||||
IMAGE_REPO="$3"
|
IMAGE_REPO="$3"
|
||||||
is_valid_app_name "$APP"
|
|
||||||
|
|
||||||
if [[ -z "$IMAGE_REPO" ]]; then
|
if [[ -z "$IMAGE_REPO" ]]; then
|
||||||
IMAGE_REPO=$(get_app_image_repo "$APP")
|
IMAGE_REPO=$(get_app_image_repo "$APP")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -145,9 +144,14 @@ func getEnvironment(appName string, merged bool) (env *Env) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAppNameOrGlobal(appName string, global bool) (string, error) {
|
func getAppNameOrGlobal(appName string, global bool) (string, error) {
|
||||||
if appName == "" && !global {
|
if global {
|
||||||
return appName, errors.New("Please specify an app to run the command on or --global")
|
return appName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := common.VerifyAppName(appName); err != nil {
|
||||||
|
return appName, err
|
||||||
|
}
|
||||||
|
|
||||||
return appName, nil
|
return appName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ func newEnvFromString(rep string) (env *Env, err error) {
|
|||||||
|
|
||||||
//LoadAppEnv loads an environment for the given app
|
//LoadAppEnv loads an environment for the given app
|
||||||
func LoadAppEnv(appName string) (env *Env, err error) {
|
func LoadAppEnv(appName string) (env *Env, err error) {
|
||||||
|
err = common.VerifyAppName(appName)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
appfile, err := getAppFile(appName)
|
appfile, err := getAppFile(appName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
|
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27
|
||||||
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
||||||
github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000
|
github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000
|
||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/dokku/dokku/plugins/common => ../common
|
replace github.com/dokku/dokku/plugins/common => ../common
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ teardown() {
|
|||||||
echo "status: $status"
|
echo "status: $status"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
run /bin/bash -c "dokku --trace apps:rename $TEST_APP great-test-name"
|
run /bin/bash -c "dokku apps:rename $TEST_APP great-test-name"
|
||||||
echo "output: $output"
|
echo "output: $output"
|
||||||
echo "status: $status"
|
echo "status: $status"
|
||||||
assert_success
|
assert_success
|
||||||
|
|||||||
Reference in new issue
Block a user