Merge pull request #3861 from dokku/3821-fix-clone-rename

Fix app clone and rename calls
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2020-02-18 00:42:25 -05:00
commit 9f32747c98
33 files changed
+570 -133

No files matched your search

+7 -1
View File
@@ -134,6 +134,12 @@ Renaming node-js-app to io-js-app... done
This will copy all of your app's contents into a new app directory with the name of your choice, delete your old app, then rebuild the new version of the app and deploy it. All of your config variables, including database urls, will be preserved. This will copy all of your app's contents into a new app directory with the name of your choice, delete your old app, then rebuild the new version of the app and deploy it. All of your config variables, including database urls, will be preserved.
By default, Dokku will deploy the renamed app, though you can skip the deploy by using the `--skip-deploy` flag:
```shell
dokku apps:rename --skip-deploy node-js-app io-js-app
```
### Cloning an existing app ### Cloning an existing app
> New as of 0.11.5 > New as of 0.11.5
@@ -157,7 +163,7 @@ This will copy all of your app's contents into a new app directory with the name
> Warning: If you have exposed specific ports via `docker-options` plugin, or performed anything that cannot be done against multiple applications, `apps:clone` may result in errors. > Warning: If you have exposed specific ports via `docker-options` plugin, or performed anything that cannot be done against multiple applications, `apps:clone` may result in errors.
By default, Dokku will deploy this new application, though you can skip the deploy by using the `--skip-deploy` flag: By default, Dokku will deploy this new app, though you can skip the deploy by using the `--skip-deploy` flag:
```shell ```shell
dokku apps:clone --skip-deploy node-js-app io-js-app dokku apps:clone --skip-deploy node-js-app io-js-app
+1 -1
View File
@@ -527,7 +527,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
### `network-clear-config` ### `network-clear-config`
- Description: Clears network configuration - Description: Clears network configuration
- Invoked by: `internally triggered by proxy-clear-config within proxy implementations` - Invoked by: `internally triggered within proxy implementations`
- Arguments: `$APP` - Arguments: `$APP`
- Example: - Example:
+1
View File
@@ -0,0 +1 @@
hook
+2 -18
View File
@@ -21,8 +21,6 @@ cmd-apps-clone() {
OLD_APP="$1" NEW_APP="$2" OLD_APP="$1" NEW_APP="$2"
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on" [[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
is_valid_app_name "$OLD_APP" is_valid_app_name "$OLD_APP"
is_valid_app_name "$NEW_APP" is_valid_app_name "$NEW_APP"
apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist" apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist"
@@ -35,24 +33,10 @@ cmd-apps-clone() {
dokku_log_fail "Name is already taken" dokku_log_fail "Name is already taken"
fi fi
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache" dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP"
local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache"
apps_create "$NEW_APP" apps_create "$NEW_APP"
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null
plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP" plugn trigger post-app-clone-setup "$OLD_APP" "$NEW_APP"
SKIP_REBUILD=$SKIP_REBUILD plugn trigger post-app-clone "$OLD_APP" "$NEW_APP"
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi
rm -rf "$NEW_CACHE_DIR"
[[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]] && sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
[[ "$SKIP_REBUILD" == "true" ]] || ps_rebuild "$NEW_APP"
plugn trigger post-app-clone "$OLD_APP" "$NEW_APP"
dokku_log_info1_quiet "Cloning $OLD_APP to $NEW_APP... done"
} }
cmd-apps-clone "$@" cmd-apps-clone "$@"
+16 -16
View File
@@ -10,29 +10,29 @@ cmd-apps-rename() {
declare cmd="apps:rename" declare cmd="apps:rename"
[[ "$1" == "$cmd" ]] && shift 1 [[ "$1" == "$cmd" ]] && shift 1
declare OLD_APP="$1" NEW_APP="$2" declare OLD_APP="$1" NEW_APP="$2"
local SKIP_REBUILD=false
for arg in "$@"; do
[[ "$arg" == "--skip-deploy" ]] && shift 1 && SKIP_REBUILD=true
[[ "$arg" =~ ^--.* ]] || break
done
OLD_APP="$1" NEW_APP="$2"
[[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on" [[ -z "$OLD_APP" ]] && dokku_log_fail "Please specify an app to run the command on"
[[ -d "$DOKKU_ROOT/$NEW_APP" ]] && dokku_log_fail "Name is already taken"
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$OLD_APP" is_valid_app_name "$OLD_APP"
is_valid_app_name "$NEW_APP"
apps_exists "$OLD_APP" >/dev/null 2>&1 || dokku_log_fail "App does not exist"
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then if apps_exists "$NEW_APP" >/dev/null 2>&1; then
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache dokku_log_fail "Name is already taken"
fi fi
rm -rf "$OLD_CACHE_DIR"
dokku_log_info1_quiet "Renaming $OLD_APP to $NEW_APP"
apps_create "$NEW_APP" apps_create "$NEW_APP"
cp -a "$DOKKU_ROOT/$OLD_APP/." "$DOKKU_ROOT/$NEW_APP" plugn trigger post-app-rename-setup "$OLD_APP" "$NEW_APP"
plugn trigger proxy-clear-config "$NEW_APP"
DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP" DOKKU_APPS_FORCE_DELETE=1 apps_destroy "$OLD_APP"
[[ -f "$DOKKU_ROOT/$NEW_APP/URLS" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS" SKIP_REBUILD=$SKIP_REBUILD plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
[[ -f "$DOKKU_ROOT/$NEW_APP/VHOST" ]] && sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
[[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]] && sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
ps_rebuild "$NEW_APP"
plugn trigger post-app-rename "$OLD_APP" "$NEW_APP"
docker_cleanup "$OLD_APP" "true"
echo "Renaming $OLD_APP to $NEW_APP... done"
} }
cmd-apps-rename "$@" cmd-apps-rename "$@"
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-builder-herokuish-post-app-clone-setup() {
declare desc="builder-herokuish post-app-clone-setup plugin trigger"
declare trigger="post-app-clone-setup"
declare OLD_APP="$1" NEW_APP="$2"
local NEW_CACHE_DIR="$DOKKU_ROOT/$NEW_APP/cache"
local NEW_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$NEW_APP/cache"
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null
if [[ -d "$NEW_CACHE_DIR" ]] && ! rmdir "$NEW_CACHE_DIR"; then
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$NEW_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi
rm -rf "$NEW_CACHE_DIR"
}
trigger-builder-herokuish-post-app-clone-setup "$@"
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-builder-herokuish-post-app-clone-setup() {
declare desc="builder-herokuish post-app-clone-setup plugin trigger"
declare trigger="post-app-clone-setup"
declare OLD_APP="$1" NEW_APP="$2"
local OLD_CACHE_DIR="$DOKKU_ROOT/$OLD_APP/cache"
local OLD_CACHE_HOST_DIR="$DOKKU_HOST_ROOT/$OLD_APP/cache"
if [[ -d "$OLD_CACHE_DIR" ]] && ! rmdir "$OLD_CACHE_DIR" >/dev/null 2>&1; then
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$NEW_APP"
"$DOCKER_BIN" container run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS --rm --volume "$OLD_CACHE_HOST_DIR:/cache" "dokku/$OLD_APP" chmod 777 -R /cache
fi
rm -rf "$OLD_CACHE_DIR"
pushd "$DOKKU_ROOT/$OLD_APP/." >/dev/null
find ./* \( -name ".cache" -o -name "cache" \) -prune -o -print | cpio -pdmu --quiet "$DOKKU_ROOT/$NEW_APP"
popd >/dev/null 2>&1 || pushd "/tmp" >/dev/null
}
trigger-builder-herokuish-post-app-clone-setup "$@"
+1 -2
View File
@@ -3,6 +3,5 @@
/triggers/* /triggers/*
/triggers /triggers
/install /install
/post-delete /post-*
/post-extract
/report /report
+1 -1
View File
@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set SUBCOMMANDS = subcommands/add subcommands/clear subcommands/list subcommands/remove subcommands/report subcommands/set
TRIGGERS = triggers/install triggers/post-delete triggers/post-extract triggers/report TRIGGERS = triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/post-extract triggers/report
BUILD = commands subcommands triggers BUILD = commands subcommands triggers
PLUGIN_NAME = buildpacks PLUGIN_NAME = buildpacks
@@ -16,9 +16,18 @@ func main() {
trigger := parts[len(parts)-1] trigger := parts[len(parts)-1]
flag.Parse() flag.Parse()
var err error
switch trigger { switch trigger {
case "install": case "install":
buildpacks.TriggerInstall() buildpacks.TriggerInstall()
case "post-app-clone-setup":
oldAppName := flag.Arg(0)
newAppName := flag.Arg(1)
err = buildpacks.TriggerPostAppCloneSetup(oldAppName, newAppName)
case "post-app-rename-setup":
oldAppName := flag.Arg(0)
newAppName := flag.Arg(1)
err = buildpacks.TriggerPostAppRenameSetup(oldAppName, newAppName)
case "post-delete": case "post-delete":
appName := flag.Arg(0) appName := flag.Arg(0)
buildpacks.TriggerPostDelete(appName) buildpacks.TriggerPostDelete(appName)
@@ -32,4 +41,8 @@ func main() {
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
} }
if err != nil {
common.LogFail(err.Error())
}
} }
+23
View File
@@ -16,6 +16,29 @@ func TriggerInstall() {
} }
} }
// TriggerPostAppCloneSetup creates new buildpacks files
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
err := common.PropertyClone("buildpacks", oldAppName, newAppName)
if err != nil {
return err
}
return nil
}
// TriggerPostAppRenameSetup renames buildpacks files
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
if err := common.PropertyClone("buildpacks", oldAppName, newAppName); err != nil {
return err
}
if err := common.PropertyDestroy("buildpacks", oldAppName); err != nil {
return err
}
return nil
}
// TriggerPostDelete destroys the buildpacks property for a given app container // TriggerPostDelete destroys the buildpacks property for a given app container
func TriggerPostDelete(appName string) { func TriggerPostDelete(appName string) {
err := common.PropertyDestroy("buildpacks", appName) err := common.PropertyDestroy("buildpacks", appName)
+16
View File
@@ -44,6 +44,22 @@ func CommandPropertySet(pluginName, appName, property, value string, properties
} }
} }
// PropertyClone clones a set of properties from one app to another
func PropertyClone(pluginName string, oldAppName string, newAppName string) error {
properties, err := PropertyGetAll(pluginName, oldAppName)
if err != nil {
return nil
}
for property, value := range properties {
if err := PropertyWrite(pluginName, newAppName, property, value); err != nil {
return err
}
}
return nil
}
// PropertyDelete deletes a property from the plugin properties for an app // PropertyDelete deletes a property from the plugin properties for an app
func PropertyDelete(pluginName string, appName string, property string) error { func PropertyDelete(pluginName string, appName string, property string) error {
propertyPath := getPropertyPath(pluginName, appName, property) propertyPath := getPropertyPath(pluginName, appName, property)
+7 -1
View File
@@ -9,10 +9,16 @@ fn-plugin-property-get() {
fn-plugin-property-get-default "$PLUGIN" "$APP" "$KEY" "$DEFAULT" fn-plugin-property-get-default "$PLUGIN" "$APP" "$KEY" "$DEFAULT"
} }
fn-plugin-property-clone() {
declare desc="destroy the properties for an app"
declare PLUGIN="$1" OLD_APP="$2" NEW_APP="$3"
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "clone" "$PLUGIN" "$OLD_APP" "$NEW_APP"
}
fn-plugin-property-destroy() { fn-plugin-property-destroy() {
declare desc="destroy the properties for an app" declare desc="destroy the properties for an app"
declare PLUGIN="$1" APP="$2" declare PLUGIN="$1" APP="$2"
"$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "destroy" "$PLUGIN" "$APP" "$KEY" "$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "destroy" "$PLUGIN" "$APP"
} }
fn-plugin-property-delete() { fn-plugin-property-delete() {
+79 -72
View File
@@ -33,12 +33,78 @@ func main() {
pluginName := flag.Arg(1) pluginName := flag.Arg(1)
switch cmd { switch cmd {
case "rpush": case "clone":
oldAppName := flag.Arg(2)
newAppName := flag.Arg(3)
err := common.PropertyClone(pluginName, oldAppName, newAppName)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "del":
appName := flag.Arg(2)
property := flag.Arg(3)
err := common.PropertyDelete(pluginName, appName, property)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "destroy":
appName := flag.Arg(2)
err := common.PropertyDestroy(pluginName, appName)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "exists":
appName := flag.Arg(2)
property := flag.Arg(3)
exists := common.PropertyExists(pluginName, appName, property)
if !exists {
os.Exit(1)
}
case "get":
appName := flag.Arg(2)
property := flag.Arg(3)
value := common.PropertyGet(pluginName, appName, property)
if value != "" {
fmt.Printf("%v\n", value)
}
case "get-all":
appName := flag.Arg(2)
values, err := common.PropertyGetAll(pluginName, appName)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
for key, value := range values {
fmt.Fprintln(os.Stdout, key, strings.TrimSuffix(value, "\n"))
}
case "get-with-default":
appName := flag.Arg(2)
property := flag.Arg(3)
defaultValue := flag.Arg(4)
value := common.PropertyGetDefault(pluginName, appName, property, defaultValue)
if value != "" {
fmt.Printf("%v\n", value)
}
case "lindex":
appName := flag.Arg(2)
property := flag.Arg(3)
index := strToInt(flag.Arg(4), 0, false)
propertyValue, err := common.PropertyListGetByIndex(pluginName, appName, property, index)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
fmt.Printf("%v\n", propertyValue)
case "lismember":
appName := flag.Arg(2) appName := flag.Arg(2)
property := flag.Arg(3) property := flag.Arg(3)
value := flag.Arg(4) value := flag.Arg(4)
index := strToInt(flag.Arg(5), 0, true) _, err := common.PropertyListGetByValue(pluginName, appName, property, value)
err := common.PropertyListAdd(pluginName, appName, property, value, index)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
@@ -65,26 +131,6 @@ func main() {
for _, line := range lines { for _, line := range lines {
fmt.Printf("%v\n", line) fmt.Printf("%v\n", line)
} }
case "lindex":
appName := flag.Arg(2)
property := flag.Arg(3)
index := strToInt(flag.Arg(4), 0, false)
propertyValue, err := common.PropertyListGetByIndex(pluginName, appName, property, index)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
fmt.Printf("%v\n", propertyValue)
case "lismember":
appName := flag.Arg(2)
property := flag.Arg(3)
value := flag.Arg(4)
_, err := common.PropertyListGetByValue(pluginName, appName, property, value)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "lrem": case "lrem":
appName := flag.Arg(2) appName := flag.Arg(2)
property := flag.Arg(3) property := flag.Arg(3)
@@ -113,6 +159,16 @@ func main() {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
} }
case "rpush":
appName := flag.Arg(2)
property := flag.Arg(3)
value := flag.Arg(4)
index := strToInt(flag.Arg(5), 0, true)
err := common.PropertyListAdd(pluginName, appName, property, value, index)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "set": case "set":
appName := flag.Arg(2) appName := flag.Arg(2)
property := flag.Arg(3) property := flag.Arg(3)
@@ -122,60 +178,11 @@ func main() {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
} }
case "get":
appName := flag.Arg(2)
property := flag.Arg(3)
value := common.PropertyGet(pluginName, appName, property)
if value != "" {
fmt.Printf("%v\n", value)
}
case "get-with-default":
appName := flag.Arg(2)
property := flag.Arg(3)
defaultValue := flag.Arg(4)
value := common.PropertyGetDefault(pluginName, appName, property, defaultValue)
if value != "" {
fmt.Printf("%v\n", value)
}
case "get-all":
appName := flag.Arg(2)
values, err := common.PropertyGetAll(pluginName, appName)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
for key, value := range values {
fmt.Fprintln(os.Stdout, key, strings.TrimSuffix(value, "\n"))
}
case "exists":
appName := flag.Arg(2)
property := flag.Arg(3)
exists := common.PropertyExists(pluginName, appName, property)
if !exists {
os.Exit(1)
}
case "del":
appName := flag.Arg(2)
property := flag.Arg(3)
err := common.PropertyDelete(pluginName, appName, property)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
case "setup": case "setup":
err := common.PropertySetup(pluginName) err := common.PropertySetup(pluginName)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err.Error()) fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1) os.Exit(1)
} }
case "destroy":
appName := flag.Arg(2)
err := common.PropertyDestroy(pluginName, appName)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
} }
} }
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
trigger-domains-post-app-rename-setup() {
declare desc="updates VHOST and URLS files during rename"
declare trigger="post-app-rename-setup"
declare OLD_APP="$1" NEW_APP="$2"
if [[ -f "$DOKKU_ROOT/$NEW_APP/URLS" ]]; then
sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/URLS"
fi
if [[ -f "$DOKKU_ROOT/$NEW_APP/VHOST" ]]; then
sed -i -e "s/$OLD_APP/$NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/VHOST"
fi
}
trigger-domains-post-app-rename-setup "$@"
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-git-post-app-clone-setup() {
declare desc="modifies git-hook"
declare trigger="post-app-clone-setup"
declare OLD_APP="$1" NEW_APP="$2"
if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then
sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
fi
fn-plugin-property-clone "git" "$OLD_APP" "$NEW_APP"
}
trigger-git-post-app-clone-setup "$@"
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-git-post-app-rename-setup() {
declare desc="modifies git-hook"
declare trigger="post-app-rename-setup"
declare OLD_APP="$1" NEW_APP="$2"
if [[ -f "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive" ]]; then
sed -i -e "s/git-hook $OLD_APP/git-hook $NEW_APP/g" "$DOKKU_ROOT/$NEW_APP/hooks/pre-receive"
fi
fn-plugin-property-clone "git" "$OLD_APP" "$NEW_APP"
fn-plugin-property-destroy "git" "$OLD_APP"
}
trigger-git-post-app-rename-setup "$@"
+1 -1
View File
@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/create subcommands/destroy subcommands/exists subcommands/info subcommands/list subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set SUBCOMMANDS = subcommands/create subcommands/destroy subcommands/exists subcommands/info subcommands/list subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set
TRIGGERS = triggers/core-post-deploy triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report TRIGGERS = triggers/core-post-deploy triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report
BUILD = commands subcommands triggers BUILD = commands subcommands triggers
PLUGIN_NAME = network PLUGIN_NAME = network
+2 -2
View File
@@ -188,8 +188,8 @@ func HasNetworkConfig(appName string) bool {
return common.FileExists(ipfile) && common.FileExists(portfile) return common.FileExists(ipfile) && common.FileExists(portfile)
} }
// PostAppCloneSetup removes old IP and PORT files for a newly cloned app // ClearNetworkConfig removes old IP and PORT files for a newly cloned app
func PostAppCloneSetup(appName string) bool { func ClearNetworkConfig(appName string) bool {
dokkuRoot := common.MustGetEnv("DOKKU_ROOT") dokkuRoot := common.MustGetEnv("DOKKU_ROOT")
appRoot := strings.Join([]string{dokkuRoot, appName}, "/") appRoot := strings.Join([]string{dokkuRoot, appName}, "/")
success := true success := true
+12 -2
View File
@@ -16,6 +16,7 @@ func main() {
trigger := parts[len(parts)-1] trigger := parts[len(parts)-1]
flag.Parse() flag.Parse()
var err error
switch trigger { switch trigger {
case "install": case "install":
network.TriggerInstall() network.TriggerInstall()
@@ -61,8 +62,13 @@ func main() {
port := flag.Arg(3) port := flag.Arg(3)
network.TriggerNetworkWritePort(appName, processType, containerIndex, port) network.TriggerNetworkWritePort(appName, processType, containerIndex, port)
case "post-app-clone-setup": case "post-app-clone-setup":
appName := flag.Arg(1) oldAppName := flag.Arg(0)
network.TriggerPostAppCloneSetup(appName) newAppName := flag.Arg(1)
err = network.TriggerPostAppCloneSetup(oldAppName, newAppName)
case "post-app-rename-setup":
oldAppName := flag.Arg(0)
newAppName := flag.Arg(1)
err = network.TriggerPostAppRenameSetup(oldAppName, newAppName)
case "post-container-create": case "post-container-create":
containerType := flag.Arg(0) containerType := flag.Arg(0)
containerID := flag.Arg(1) containerID := flag.Arg(1)
@@ -85,4 +91,8 @@ func main() {
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger))
} }
if err != nil {
common.LogFail(err.Error())
}
} }
+28 -3
View File
@@ -153,12 +153,37 @@ func TriggerNetworkWritePort(appName string, processType string, containerIndex
} }
} }
// TriggerPostAppCloneSetup cleans up network files for a new app clone // TriggerPostAppCloneSetup creates new network files
func TriggerPostAppCloneSetup(appName string) { func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
success := PostAppCloneSetup(appName) success := ClearNetworkConfig(newAppName)
if !success { if !success {
os.Exit(1) os.Exit(1)
} }
err := common.PropertyClone("network", oldAppName, newAppName)
if err != nil {
return err
}
return nil
}
// TriggerPostAppRenameSetup renames network files
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
success := ClearNetworkConfig(newAppName)
if !success {
os.Exit(1)
}
if err := common.PropertyClone("network", oldAppName, newAppName); err != nil {
return err
}
if err := common.PropertyDestroy("network", oldAppName); err != nil {
return err
}
return nil
} }
// TriggerPostContainerCreate associates the container with a specified network // TriggerPostContainerCreate associates the container with a specified network
@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-nginx-vhosts-post-app-clone-setup() { trigger-nginx-vhosts-post-app-clone-setup() {
declare desc="removes nginx files when setting up a clone" declare desc="removes nginx files when setting up a clone"
@@ -8,6 +9,7 @@ trigger-nginx-vhosts-post-app-clone-setup() {
declare OLD_APP="$1" NEW_APP="$2" declare OLD_APP="$1" NEW_APP="$2"
local APP_DIR="$DOKKU_ROOT/$NEW_APP" local APP_DIR="$DOKKU_ROOT/$NEW_APP"
fn-plugin-property-clone "nginx" "$OLD_APP" "$NEW_APP"
rm -rf "$APP_DIR/nginx.conf" rm -rf "$APP_DIR/nginx.conf"
} }
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/internal-functions"
source "$PLUGIN_AVAILABLE_PATH/proxy/functions"
trigger-nginx-vhosts-post-app-rename-setup() {
declare desc="calls proxy-clear-config"
declare trigger="post-app-rename-setup"
declare OLD_APP="$1" NEW_APP="$2"
fn-plugin-property-clone "nginx" "$OLD_APP" "$NEW_APP"
fn-plugin-property-destroy "nginx" "$OLD_APP"
plugn trigger proxy-clear-config "$NEW_APP"
}
trigger-nginx-vhosts-post-app-rename-setup "$@"
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
trigger-ps-post-app-clone() {
declare desc="ps post-app-clone plugin trigger"
declare trigger="post-app-clone"
declare OLD_APP="$1" NEW_APP="$2"
if [[ "$SKIP_REBUILD" != "true" ]]; then
ps_rebuild "$NEW_APP"
fi
}
trigger-ps-post-app-clone "$@"
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
trigger-ps-post-app-rename() {
declare desc="ps post-app-rename plugin trigger"
declare trigger="post-app-rename"
declare OLD_APP="$1" NEW_APP="$2"
if [[ "$SKIP_REBUILD" != "true" ]]; then
ps_rebuild "$NEW_APP"
fi
}
trigger-ps-post-app-rename "$@"
+1 -1
View File
@@ -3,7 +3,7 @@
/triggers/* /triggers/*
/triggers /triggers
/install /install
/post-delete /post-*
/report /report
/docker-args-process-deploy /docker-args-process-deploy
/docker-args-process-run /docker-args-process-run
+1 -1
View File
@@ -1,5 +1,5 @@
SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/report subcommands/reserve subcommands/reserve-clear SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/report subcommands/reserve subcommands/reserve-clear
TRIGGERS = triggers/docker-args-process-deploy triggers/install triggers/post-delete triggers/report triggers/resource-get-property TRIGGERS = triggers/docker-args-process-deploy triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report triggers/resource-get-property
BUILD = commands subcommands triggers BUILD = commands subcommands triggers
PLUGIN_NAME = resource PLUGIN_NAME = resource
@@ -24,6 +24,14 @@ func main() {
err = resource.TriggerDockerArgsProcessDeploy(appName, processType) err = resource.TriggerDockerArgsProcessDeploy(appName, processType)
case "install": case "install":
err = resource.TriggerInstall() err = resource.TriggerInstall()
case "post-app-clone-setup":
oldAppName := flag.Arg(0)
newAppName := flag.Arg(1)
err = resource.TriggerPostAppCloneSetup(oldAppName, newAppName)
case "post-app-rename-setup":
oldAppName := flag.Arg(0)
newAppName := flag.Arg(1)
err = resource.TriggerPostAppRenameSetup(oldAppName, newAppName)
case "post-delete": case "post-delete":
appName := flag.Arg(0) appName := flag.Arg(0)
err = resource.TriggerPostDelete(appName) err = resource.TriggerPostDelete(appName)
+23
View File
@@ -92,6 +92,29 @@ func TriggerInstall() error {
return nil return nil
} }
// TriggerPostAppCloneSetup creates new resource files
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
err := common.PropertyClone("resource", oldAppName, newAppName)
if err != nil {
return err
}
return nil
}
// TriggerPostAppRenameSetup renames resource files
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
if err := common.PropertyClone("resource", oldAppName, newAppName); err != nil {
return err
}
if err := common.PropertyDestroy("resource", oldAppName); err != nil {
return err
}
return nil
}
// TriggerPostDelete destroys the resource property for a given app container // TriggerPostDelete destroys the resource property for a given app container
func TriggerPostDelete(appName string) error { func TriggerPostDelete(appName string) error {
return common.PropertyDestroy("resource", appName) return common.PropertyDestroy("resource", appName)
@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-scheduler-docker-local-post-app-clone-setup() { trigger-scheduler-docker-local-post-app-clone-setup() {
declare desc="removes docker-local files when setting up a clone" declare desc="removes docker-local files when setting up a clone"
@@ -8,6 +9,7 @@ trigger-scheduler-docker-local-post-app-clone-setup() {
declare OLD_APP="$1" NEW_APP="$2" declare OLD_APP="$1" NEW_APP="$2"
local APP_DIR="$DOKKU_ROOT/$NEW_APP" local APP_DIR="$DOKKU_ROOT/$NEW_APP"
fn-plugin-property-clone "scheduler-docker-local" "$OLD_APP" "$NEW_APP"
find "$APP_DIR" -type f -name 'CONTAINER.*' -exec rm {} \; find "$APP_DIR" -type f -name 'CONTAINER.*' -exec rm {} \;
} }
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
trigger-scheduler-docker-local-post-app-rename-setup() {
declare desc="updates settings when renaming an app"
declare trigger="post-app-rename-setup"
declare OLD_APP="$1" NEW_APP="$2"
local APP_DIR="$DOKKU_ROOT/$NEW_APP"
fn-plugin-property-clone "scheduler-docker-local" "$OLD_APP" "$NEW_APP"
fn-plugin-property-destroy "scheduler-docker-local" "$OLD_APP"
}
trigger-scheduler-docker-local-post-app-rename-setup "$@"
+135 -1
View File
@@ -117,10 +117,67 @@ teardown() {
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku apps:rename $TEST_APP great-test-name"
run /bin/bash -c "dokku buildpacks:add $TEST_APP https://github.com/heroku/heroku-buildpack-ruby.git"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku git:set $TEST_APP deploy-branch SOME_BRANCH_NAME"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku network:set $TEST_APP attach-post-create test-network"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:set $TEST_APP bind-address-ipv4 127.0.0.1"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku resource:limit --memory 100 $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku scheduler-docker-local:set $TEST_APP disable-chown true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku --trace apps:rename $TEST_APP great-test-name"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku buildpacks:report great-test-name --buildpacks-list"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "https://github.com/heroku/heroku-buildpack-ruby.git"
run /bin/bash -c "dokku git:report great-test-name --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "SOME_BRANCH_NAME"
run /bin/bash -c "dokku network:report great-test-name --network-attach-post-create"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "test-network"
run /bin/bash -c "dokku nginx:report great-test-name --nginx-bind-address-ipv4"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "127.0.0.1"
run /bin/bash -c "dokku resource:report great-test-name --resource-_default_.limit.memory"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "100"
run /bin/bash -c "dokku scheduler-docker-local:report great-test-name --scheduler-docker-local-disable-chown"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "true"
run /bin/bash -c "dokku --force apps:destroy great-test-name" run /bin/bash -c "dokku --force apps:destroy great-test-name"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
@@ -160,6 +217,83 @@ teardown() {
assert_success assert_success
} }
@test "(apps) apps:clone (no app)" {
run /bin/bash -c "dokku apps:create $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku buildpacks:add $TEST_APP https://github.com/heroku/heroku-buildpack-ruby.git"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku git:set $TEST_APP deploy-branch SOME_BRANCH_NAME"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku network:set $TEST_APP attach-post-create test-network"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku nginx:set $TEST_APP bind-address-ipv4 127.0.0.1"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku resource:limit --memory 100 $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku scheduler-docker-local:set $TEST_APP disable-chown true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku apps:clone $TEST_APP great-test-name"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku apps:list | grep $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku buildpacks:report great-test-name --buildpacks-list"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "https://github.com/heroku/heroku-buildpack-ruby.git"
run /bin/bash -c "dokku git:report great-test-name --git-deploy-branch"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "SOME_BRANCH_NAME"
run /bin/bash -c "dokku network:report great-test-name --network-attach-post-create"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "test-network"
run /bin/bash -c "dokku nginx:report great-test-name --nginx-bind-address-ipv4"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "127.0.0.1"
run /bin/bash -c "dokku resource:report great-test-name --resource-_default_.limit.memory"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "100"
run /bin/bash -c "dokku scheduler-docker-local:report great-test-name --scheduler-docker-local-disable-chown"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "true"
run /bin/bash -c "dokku --force apps:destroy great-test-name"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(apps) apps:clone ssl-app" { @test "(apps) apps:clone ssl-app" {
run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_PROXY_PORT_MAP=https:443:5000 DOKKU_PROXY_SSL_PORT=443" run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_PROXY_PORT_MAP=https:443:5000 DOKKU_PROXY_SSL_PORT=443"
deploy_app deploy_app
+10 -10
View File
@@ -85,32 +85,32 @@ teardown() {
} }
@test "(network) network management" { @test "(network) network management" {
run /bin/bash -c "dokku network:list | grep test-network" run /bin/bash -c "dokku network:list | grep $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku network:exists test-network" run /bin/bash -c "dokku network:exists $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku network:create test-network" run /bin/bash -c "dokku network:create $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku network:list | grep test-network" run /bin/bash -c "dokku network:list | grep $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku network:create test-network" run /bin/bash -c "dokku network:create $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku network:exists test-network" run /bin/bash -c "dokku network:exists $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
@@ -125,22 +125,22 @@ teardown() {
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku --force network:destroy test-network" run /bin/bash -c "dokku --force network:destroy $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_success assert_success
run /bin/bash -c "dokku --force network:destroy test-network" run /bin/bash -c "dokku --force network:destroy $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku network:exists test-network" run /bin/bash -c "dokku network:exists $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure
run /bin/bash -c "dokku network:list | grep test-network" run /bin/bash -c "dokku network:list | grep $TEST_NETWORK"
echo "output: $output" echo "output: $output"
echo "status: $status" echo "status: $status"
assert_failure assert_failure