hoangweb
4/16/2016 - 1:21 PM

dokku- plugin

dokku- plugin

[plugin]
description = "dokku hello plugin"
version = "0.1.0"
[plugin.config]
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"       #load core functions

case "$1" in
  hello)    # --> dokku hello
    [[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
    APP="$2"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
    verify_app_name "$APP"

    echo "Hello $APP"
    ;;

  hello:world)
    echo "Hello world"
    ;;

  help)     # --> dokku help
    cat<<EOF
    hello <app>, Says "Hello <app>"
    hello:world, Says "Hello world"
EOF
    ;;

  *)
    exit $DOKKU_NOT_IMPLEMENTED_EXIT
    ;;

esac
#-------------------variables-------------------------------------------------------
$DOKKU_TRACE: 0|1
$DOKKU_ROOT: /home/dokku
$APP_NAME : app container ID, $(cat /home/dokku/app1/CONTAINER)
$APP_PORT: app port
$APP_PERSISTENT_NAMES: e.g: cache_data_php1
$IMAGE: app image, ie: dokku/php1:latest
$APP: app name, ie: php1
$APP_DIR: eg: /home/dokku/php1
"$@": dokku commands text, eg: apps:status app1

$IMAGE_GENERIC: dokku/php1

#-------------------------functions---------------------------
verify_app_name "$2"
verify_max_args 2 "$@"

deploy_app "$APP"
stop_and_remove_app_containers
stop_and_remove_container $APP_PERSISTENT_NAMES
remove_image "$IMAGE"


#-------------learning--------------
# volume
docker run -v "$CACHE_DIR:/cache" "$IMAGE"

# delete app: remove app cache (dokku-alt\plugins\apps/pre-delete)
docker run -v "$CACHE_DIR:/cache" "$IMAGE" find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} \;

# delete app: remove app dir & image
docker rmi \
    "$IMAGE_GENERIC:build" \
	"$IMAGE_GENERIC:release" \
	"$IMAGE_GENERIC:deployed" \
	"$IMAGE_GENERIC:latest" \
	1>/dev/null 2>/dev/null || true

# git hooks
pluginhook git-pre-pull $APP
git-upload-pack "$DOKKU_ROOT/$APP"
pluginhook pre-delete $APP      # execute file dokku-alt\plugins\apps/pre-delete ?
pluginhook post-delete $APP
pluginhook git-post-pull $APP
pluginhook pre-build "$APP" "$REV" "buildstep"
pluginhook post-build "$APP" "$REV" "buildstep"

/home/dokku/app1/hooks


TEMP_DIR=$(mktemp -d)
APP="$2";
IMAGE_TAG=$(get_running_image_tag $APP);
IMAGE=$(get_app_image_name $APP $IMAGE_TAG)